KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smack > ChatTest


1 /**
2 * $RCSfile$
3 * $Revision: 2339 $
4 * $Date: 2004-07-12 10:36:13 -0300 (Mon, 12 Jul 2004) $
5 *
6 * Copyright (C) 2002-2003 Jive Software. All rights reserved.
7 * ====================================================================
8 * The Jive Software License (based on Apache Software License, Version 1.1)
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 * if any, must include the following acknowledgment:
24 * "This product includes software developed by
25 * Jive Software (http://www.jivesoftware.com)."
26 * Alternately, this acknowledgment may appear in the software itself,
27 * if and wherever such third-party acknowledgments normally appear.
28 *
29 * 4. The names "Smack" and "Jive Software" must not be used to
30 * endorse or promote products derived from this software without
31 * prior written permission. For written permission, please
32 * contact webmaster@jivesoftware.com.
33 *
34 * 5. Products derived from this software may not be called "Smack",
35 * nor may "Smack" appear in their name, without prior written
36 * permission of Jive Software.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 */

52
53 package org.jivesoftware.smack;
54
55 import java.util.Date JavaDoc;
56
57 import org.jivesoftware.smack.packet.Message;
58 import org.jivesoftware.smack.test.SmackTestCase;
59
60
61 /**
62  * Tests the chat functionality.
63  *
64  * @author Gaston Dombiak
65  */

66 public class ChatTest extends SmackTestCase {
67
68     /**
69      * Constructor for ChatTest.
70      * @param arg0
71      */

72     public ChatTest(String JavaDoc arg0) {
73         super(arg0);
74     }
75
76     public void testProperties() {
77         try {
78             Chat newChat = getConnection(0).createChat(getFullJID(1));
79             Chat newChat2 = new Chat(getConnection(1), getFullJID(0), newChat.getThreadID());
80
81             Message msg = newChat.createMessage();
82
83             msg.setSubject("Subject of the chat");
84             msg.setBody("Body of the chat");
85             msg.setProperty("favoriteColor", "red");
86             msg.setProperty("age", 30);
87             msg.setProperty("distance", 30f);
88             msg.setProperty("weight", 30d);
89             msg.setProperty("male", true);
90             msg.setProperty("birthdate", new Date JavaDoc());
91             newChat.sendMessage(msg);
92
93             Message msg2 = newChat2.nextMessage(2000);
94             assertNotNull("No message was received", msg2);
95             assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
96             assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
97             assertEquals(
98                 "favoriteColors are different",
99                 msg.getProperty("favoriteColor"),
100                 msg2.getProperty("favoriteColor"));
101             assertEquals(
102                 "ages are different",
103                 msg.getProperty("age"),
104                 msg2.getProperty("age"));
105             assertEquals(
106                 "distances are different",
107                 msg.getProperty("distance"),
108                 msg2.getProperty("distance"));
109             assertEquals(
110                 "weights are different",
111                 msg.getProperty("weight"),
112                 msg2.getProperty("weight"));
113             assertEquals(
114                 "males are different",
115                 msg.getProperty("male"),
116                 msg2.getProperty("male"));
117             assertEquals(
118                 "birthdates are different",
119                 msg.getProperty("birthdate"),
120                 msg2.getProperty("birthdate"));
121         }
122         catch (XMPPException e) {
123             e.printStackTrace();
124             fail(e.getMessage());
125         }
126     }
127
128     protected int getMaxConnections() {
129         return 2;
130     }
131 }
132
Popular Tags