mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-13 11:09:39 +02:00
Created new chat manager which handles the creation of Chats.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6213 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
18a35e4e8f
commit
ae6065d7cc
36 changed files with 3964 additions and 714 deletions
|
@ -1,54 +1,54 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
|
@ -56,29 +56,27 @@ import java.util.Date;
|
|||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the chat functionality.
|
||||
*
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class ChatTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for ChatTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public ChatTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testProperties() {
|
||||
try {
|
||||
Chat newChat = getConnection(0).createChat(getFullJID(1));
|
||||
Chat newChat2 = new Chat(getConnection(1), getFullJID(0), newChat.getThreadID());
|
||||
Chat newChat = getConnection(0).getChatManager().createChat(getFullJID(1), null);
|
||||
PacketCollector collector = getConnection(1)
|
||||
.createPacketCollector(new ThreadFilter(newChat.getThreadID()));
|
||||
|
||||
Message msg = newChat.createMessage();
|
||||
Message msg = new Message();
|
||||
|
||||
msg.setSubject("Subject of the chat");
|
||||
msg.setBody("Body of the chat");
|
||||
|
@ -90,34 +88,35 @@ public class ChatTest extends SmackTestCase {
|
|||
msg.setProperty("birthdate", new Date());
|
||||
newChat.sendMessage(msg);
|
||||
|
||||
Message msg2 = newChat2.nextMessage(2000);
|
||||
Message msg2 = (Message) collector.nextResult(2000);
|
||||
|
||||
assertNotNull("No message was received", msg2);
|
||||
assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
|
||||
assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
|
||||
assertEquals(
|
||||
"favoriteColors are different",
|
||||
msg.getProperty("favoriteColor"),
|
||||
msg2.getProperty("favoriteColor"));
|
||||
"favoriteColors are different",
|
||||
msg.getProperty("favoriteColor"),
|
||||
msg2.getProperty("favoriteColor"));
|
||||
assertEquals(
|
||||
"ages are different",
|
||||
msg.getProperty("age"),
|
||||
msg2.getProperty("age"));
|
||||
"ages are different",
|
||||
msg.getProperty("age"),
|
||||
msg2.getProperty("age"));
|
||||
assertEquals(
|
||||
"distances are different",
|
||||
msg.getProperty("distance"),
|
||||
msg2.getProperty("distance"));
|
||||
"distances are different",
|
||||
msg.getProperty("distance"),
|
||||
msg2.getProperty("distance"));
|
||||
assertEquals(
|
||||
"weights are different",
|
||||
msg.getProperty("weight"),
|
||||
msg2.getProperty("weight"));
|
||||
"weights are different",
|
||||
msg.getProperty("weight"),
|
||||
msg2.getProperty("weight"));
|
||||
assertEquals(
|
||||
"males are different",
|
||||
msg.getProperty("male"),
|
||||
msg2.getProperty("male"));
|
||||
"males are different",
|
||||
msg.getProperty("male"),
|
||||
msg2.getProperty("male"));
|
||||
assertEquals(
|
||||
"birthdates are different",
|
||||
msg.getProperty("birthdate"),
|
||||
msg2.getProperty("birthdate"));
|
||||
"birthdates are different",
|
||||
msg.getProperty("birthdate"),
|
||||
msg2.getProperty("birthdate"));
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
|
||||
/**
|
||||
* Simple test to measure server performance.
|
||||
|
@ -35,14 +36,17 @@ public class FloodTest extends SmackTestCase {
|
|||
|
||||
public void testMessageFlood() {
|
||||
try {
|
||||
Chat chat11 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat12 = new Chat(getConnection(1), getBareJID(0), chat11.getThreadID());
|
||||
Chat chat11 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
PacketCollector chat12 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat11.getThreadID()));
|
||||
|
||||
Chat chat21 = getConnection(0).createChat(getBareJID(2));
|
||||
Chat chat22 = new Chat(getConnection(2), getBareJID(0), chat21.getThreadID());
|
||||
Chat chat21 = getConnection(0).getChatManager().createChat(getBareJID(2), null);
|
||||
PacketCollector chat22 = getConnection(2).createPacketCollector(
|
||||
new ThreadFilter(chat21.getThreadID()));
|
||||
|
||||
Chat chat31 = getConnection(0).createChat(getBareJID(3));
|
||||
Chat chat32 = new Chat(getConnection(3), getBareJID(0), chat31.getThreadID());
|
||||
Chat chat31 = getConnection(0).getChatManager().createChat(getBareJID(3), null);
|
||||
PacketCollector chat32 = getConnection(3).createPacketCollector(
|
||||
new ThreadFilter(chat31.getThreadID()));
|
||||
|
||||
for (int i=0; i<500; i++) {
|
||||
chat11.sendMessage("Hello_1" + i);
|
||||
|
@ -50,9 +54,9 @@ public class FloodTest extends SmackTestCase {
|
|||
chat31.sendMessage("Hello_3" + i);
|
||||
}
|
||||
for (int i=0; i<500; i++) {
|
||||
assertNotNull("Some message was lost (" + i + ")", chat12.nextMessage(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat22.nextMessage(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat32.nextMessage(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat12.nextResult(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat22.nextResult(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat32.nextResult(1000));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -48,14 +48,16 @@ public class MessageTest extends SmackTestCase {
|
|||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.chat));
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
|
||||
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.available));
|
||||
|
||||
// Check that offline messages are retrieved by user2 which is now available
|
||||
|
@ -66,7 +68,8 @@ public class MessageTest extends SmackTestCase {
|
|||
message = (Message) collector.nextResult(1000);
|
||||
assertNull(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
@ -84,14 +87,16 @@ public class MessageTest extends SmackTestCase {
|
|||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.chat));
|
||||
chat.sendMessage("Test \f 1");
|
||||
chat.sendMessage("Test \r 1");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
|
||||
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.available));
|
||||
|
||||
// Check that offline messages are retrieved by user2 which is now available
|
||||
|
@ -102,7 +107,8 @@ public class MessageTest extends SmackTestCase {
|
|||
message = (Message) collector.nextResult(1000);
|
||||
assertNull(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
@ -114,12 +120,13 @@ public class MessageTest extends SmackTestCase {
|
|||
*/
|
||||
public void testHugeMessage() {
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.chat));
|
||||
|
||||
// Create message with a body of 4K characters
|
||||
Message msg = new Message(getFullJID(1), Message.Type.CHAT);
|
||||
Message msg = new Message(getFullJID(1), Message.Type.chat);
|
||||
StringBuilder sb = new StringBuilder(5000);
|
||||
for (int i=0; i<=4000; i++) {
|
||||
for (int i = 0; i <= 4000; i++) {
|
||||
sb.append("X");
|
||||
}
|
||||
msg.setBody(sb.toString());
|
||||
|
|
|
@ -63,7 +63,7 @@ public class AndFilterTest extends TestCase {
|
|||
public void testNullArgs() {
|
||||
PacketFilter filter = null;
|
||||
try {
|
||||
AndFilter and = new AndFilter(filter, filter);
|
||||
new AndFilter(filter, filter);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -54,6 +54,8 @@ package org.jivesoftware.smackx;
|
|||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
|
@ -64,10 +66,6 @@ import org.jivesoftware.smack.test.SmackTestCase;
|
|||
*/
|
||||
public class FormTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for FormTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public FormTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
@ -113,10 +111,13 @@ public class FormTest extends SmackTestCase {
|
|||
formToSend.addField(field);
|
||||
|
||||
// Create the chats between the two participants
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat.getThreadID());
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
PacketCollector collector = getConnection(0).createPacketCollector(
|
||||
new ThreadFilter(chat.getThreadID()));
|
||||
PacketCollector collector2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat.getThreadID()));
|
||||
|
||||
Message msg = chat.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setBody("To enter a case please fill out this form and send it back to me");
|
||||
msg.addExtension(formToSend.getDataFormToSend());
|
||||
|
||||
|
@ -125,7 +126,7 @@ public class FormTest extends SmackTestCase {
|
|||
chat.sendMessage(msg);
|
||||
|
||||
// Get the message with the form to fill out
|
||||
Message msg2 = chat2.nextMessage(2000);
|
||||
Message msg2 = (Message)collector2.nextResult(2000);
|
||||
// Retrieve the form to fill out
|
||||
Form formToRespond = Form.getFormFrom(msg2);
|
||||
assertNotNull(formToRespond);
|
||||
|
@ -148,15 +149,18 @@ public class FormTest extends SmackTestCase {
|
|||
completedForm.setAnswer("time", true);
|
||||
completedForm.setAnswer("age", 20);
|
||||
// Create a new message to send with the completed form
|
||||
msg2 = chat2.createMessage();
|
||||
msg2 = new Message();
|
||||
msg2.setTo(msg.getFrom());
|
||||
msg2.setThread(msg.getThread());
|
||||
msg2.setType(Message.Type.chat);
|
||||
msg2.setBody("To enter a case please fill out this form and send it back to me");
|
||||
// Add the completed form to the message
|
||||
msg2.addExtension(completedForm.getDataFormToSend());
|
||||
// Send the message with the completed form
|
||||
chat2.sendMessage(msg2);
|
||||
getConnection(1).sendPacket(msg2);
|
||||
|
||||
// Get the message with the completed form
|
||||
Message msg3 = chat.nextMessage(2000);
|
||||
Message msg3 = (Message) collector.nextResult(2000);
|
||||
// Retrieve the completed form
|
||||
completedForm = Form.getFormFrom(msg3);
|
||||
assertNotNull(completedForm);
|
||||
|
@ -173,6 +177,10 @@ public class FormTest extends SmackTestCase {
|
|||
catch (XMPPException ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
finally {
|
||||
collector.cancel();
|
||||
collector2.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
|
|
|
@ -66,10 +66,6 @@ import org.jivesoftware.smack.test.SmackTestCase;
|
|||
*/
|
||||
public class MessageEventManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for MessageEventManagerTest.
|
||||
* @param name
|
||||
*/
|
||||
public MessageEventManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
@ -83,10 +79,10 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequest() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
|
@ -112,7 +108,7 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
MessageEventManager messageEventManager = new MessageEventManager(getConnection(0));
|
||||
messageEventManager
|
||||
|
@ -139,7 +135,7 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
});
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
|
@ -166,8 +162,8 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
* 5. User_2 will simulate that he/she has cancelled the reply
|
||||
*/
|
||||
public void testRequestsAndNotifications() {
|
||||
final ArrayList results = new ArrayList();
|
||||
ArrayList resultsExpected = new ArrayList();
|
||||
final ArrayList<String> results = new ArrayList<String>();
|
||||
ArrayList<String> resultsExpected = new ArrayList<String>();
|
||||
resultsExpected.add("deliveredNotificationRequested");
|
||||
resultsExpected.add("composingNotificationRequested");
|
||||
resultsExpected.add("displayedNotificationRequested");
|
||||
|
@ -178,7 +174,7 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
resultsExpected.add("cancelledNotification");
|
||||
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
MessageEventManager messageEventManager1 = new MessageEventManager(getConnection(0));
|
||||
messageEventManager1
|
||||
|
@ -241,7 +237,7 @@ public class MessageEventManagerTest extends SmackTestCase {
|
|||
});
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
|
|
|
@ -49,11 +49,11 @@ public class MultipleRecipientManagerTest extends SmackTestCase {
|
|||
public void testSending() throws XMPPException {
|
||||
|
||||
PacketCollector collector1 =
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector2 =
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector3 =
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
|
||||
Message message = new Message();
|
||||
message.setBody("Hola");
|
||||
|
@ -114,13 +114,13 @@ public class MultipleRecipientManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testReplying() throws XMPPException {
|
||||
PacketCollector collector0 =
|
||||
getConnection(0).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(0).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector1 =
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector2 =
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector3 =
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
|
||||
// Send the intial message with multiple recipients
|
||||
Message message = new Message();
|
||||
|
@ -196,11 +196,11 @@ public class MultipleRecipientManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testNoReply() throws XMPPException {
|
||||
PacketCollector collector1 =
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector2 =
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
PacketCollector collector3 =
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.NORMAL));
|
||||
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
|
||||
|
||||
// Send the intial message with multiple recipients
|
||||
Message message = new Message();
|
||||
|
|
|
@ -64,7 +64,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
// Check the message headers
|
||||
Iterator headers = offlineManager.getHeaders();
|
||||
assertTrue("No message header was found", headers.hasNext());
|
||||
List stamps = new ArrayList();
|
||||
List<String> stamps = new ArrayList<String>();
|
||||
while (headers.hasNext()) {
|
||||
OfflineMessageHeader header = (OfflineMessageHeader) headers.next();
|
||||
assertEquals("Incorrect sender", getFullJID(0), header.getJid());
|
||||
|
@ -87,7 +87,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
// Get the offline messages
|
||||
Iterator messages = offlineManager.getMessages(stamps);
|
||||
assertTrue("No message was found", messages.hasNext());
|
||||
stamps = new ArrayList();
|
||||
stamps = new ArrayList<String>();
|
||||
while (messages.hasNext()) {
|
||||
Message message = (Message) messages.next();
|
||||
OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
|
||||
|
@ -102,7 +102,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.CHAT));
|
||||
new MessageTypeFilter(Message.Type.chat));
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.available));
|
||||
|
||||
// Check that no offline messages was sent to the user
|
||||
|
@ -133,7 +133,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
|
@ -145,7 +145,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
// Get all offline messages
|
||||
Iterator messages = offlineManager.getMessages();
|
||||
assertTrue("No message was found", messages.hasNext());
|
||||
List stamps = new ArrayList();
|
||||
List<String> stamps = new ArrayList<String>();
|
||||
while (messages.hasNext()) {
|
||||
Message message = (Message) messages.next();
|
||||
OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
|
||||
|
@ -160,7 +160,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
|
|||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.CHAT));
|
||||
new MessageTypeFilter(Message.Type.chat));
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.available));
|
||||
|
||||
// Check that no offline messages was sent to the user
|
||||
|
|
|
@ -66,10 +66,6 @@ import org.jivesoftware.smackx.packet.DiscoverInfo;
|
|||
*/
|
||||
public class ServiceDiscoveryManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for ServiceDiscoveryManagerTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public ServiceDiscoveryManagerTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ package org.jivesoftware.smackx;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
|
@ -83,10 +84,10 @@ public class XHTMLManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendSimpleXHTMLMessage() {
|
||||
// User1 creates a chat with user2
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
|
||||
|
@ -123,39 +124,12 @@ public class XHTMLManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a listener for the chat that will check if the received message includes
|
||||
// an XHTML extension. Answer an ACK if everything is ok
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
chat2.addMessageListener(packetListener);
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
|
||||
|
@ -179,8 +153,24 @@ public class XHTMLManagerTest extends SmackTestCase {
|
|||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait for 1 second for a reply
|
||||
msg = chat1.nextMessage(1000);
|
||||
|
||||
Packet packet = chat2.nextResult(2000);
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
assertNotNull("No reply received", msg);
|
||||
}
|
||||
|
||||
|
@ -194,37 +184,12 @@ public class XHTMLManagerTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a listener for the chat that will check if the received message includes
|
||||
// an XHTML extension. Answer an ACK if everything is ok
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
received++;
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
bodiesReceived = received;
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
chat2.addMessageListener(packetListener);
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody(
|
||||
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||
|
@ -266,11 +231,31 @@ public class XHTMLManagerTest extends SmackTestCase {
|
|||
bodiesSent = 2;
|
||||
bodiesReceived = 0;
|
||||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(300);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
|
||||
Packet packet = chat2.nextResult(2000);
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
received++;
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
bodiesReceived = received;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers" +
|
||||
"is misconfigured");
|
||||
}
|
||||
assertEquals(
|
||||
"Number of sent and received XHTMP bodies does not match",
|
||||
bodiesSent,
|
||||
|
|
|
@ -53,9 +53,6 @@
|
|||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.Form;
|
||||
|
@ -78,10 +75,6 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
|
||||
private MultiUserChat muc;
|
||||
|
||||
/**
|
||||
* Constructor for MultiUserChatTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public MultiUserChatTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
@ -440,8 +433,8 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
assertFalse("No room was found", rooms.isEmpty());
|
||||
// Check that we have discovered the room used by this test
|
||||
boolean found = false;
|
||||
for (Iterator it = rooms.iterator(); it.hasNext();) {
|
||||
HostedRoom hostedRoom = (HostedRoom) it.next();
|
||||
for (Object room1 : rooms) {
|
||||
HostedRoom hostedRoom = (HostedRoom) room1;
|
||||
if (room.equals(hostedRoom.getJid())) {
|
||||
found = true;
|
||||
break;
|
||||
|
@ -461,14 +454,12 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
|
||||
muc2.join("testbot2");
|
||||
|
||||
getConnection(0).addPacketListener(new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
Chat chat2 = new Chat(getConnection(0), message.getFrom(), message.getThread());
|
||||
getConnection(0).getChatManager().addChatListener(new ChatListener() {
|
||||
public void chatCreated(Chat chat2, boolean createdLocally) {
|
||||
assertEquals(
|
||||
"Sender of chat is incorrect",
|
||||
room + "/testbot2",
|
||||
message.getFrom());
|
||||
chat2.getParticipant());
|
||||
try {
|
||||
chat2.sendMessage("ACK");
|
||||
}
|
||||
|
@ -476,16 +467,15 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
},
|
||||
new AndFilter(
|
||||
new MessageTypeFilter(Message.Type.CHAT),
|
||||
new PacketTypeFilter(Message.class)));
|
||||
});
|
||||
|
||||
// Start a private chat with another participant
|
||||
Chat chat = muc2.createPrivateChat(room + "/testbot");
|
||||
Chat chat = muc2.createPrivateChat(room + "/testbot", null);
|
||||
PacketCollector collector = chat.createCollector();
|
||||
chat.sendMessage("Hello there");
|
||||
|
||||
Message response = chat.nextMessage(2000);
|
||||
Message response = (Message) collector.nextResult(2000);
|
||||
assertNotNull("No response", response);
|
||||
assertEquals("Sender of response is incorrect", room + "/testbot", response.getFrom());
|
||||
assertEquals("Body of response is incorrect", "ACK", response.getBody());
|
||||
|
||||
|
@ -1561,8 +1551,8 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
// Check that the owner list is correct
|
||||
Collection affiliates = muc.getOwners();
|
||||
assertEquals("Room does not have 2 owners", 2, affiliates.size());
|
||||
for (Iterator it =affiliates.iterator(); it.hasNext();) {
|
||||
Affiliate affiliate = (Affiliate)it.next();
|
||||
for (Object affiliate1 : affiliates) {
|
||||
Affiliate affiliate = (Affiliate) affiliate1;
|
||||
if (getBareJID(0).equals(affiliate.getJid())) {
|
||||
assertEquals("Wrong affiliation", "owner", affiliate.getAffiliation());
|
||||
assertEquals("Wrong role", "moderator", affiliate.getRole());
|
||||
|
@ -1600,8 +1590,8 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
// Check that the moderator list is correct
|
||||
Collection occupants = muc.getModerators();
|
||||
assertEquals("Room does not have 2 moderators", 2, occupants.size());
|
||||
for (Iterator it =occupants.iterator(); it.hasNext();) {
|
||||
Occupant occupant = (Occupant)it.next();
|
||||
for (Object occupant1 : occupants) {
|
||||
Occupant occupant = (Occupant) occupant1;
|
||||
if (getFullJID(0).equals(occupant.getJid())) {
|
||||
assertEquals("Wrong affiliation", "owner", occupant.getAffiliation());
|
||||
assertEquals("Wrong role", "moderator", occupant.getRole());
|
||||
|
@ -1854,7 +1844,7 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
answerForm.setAnswer("muc#roomconfig_moderatedroom", true);
|
||||
// Keep the room owner
|
||||
try {
|
||||
List owners = new ArrayList();
|
||||
List<String> owners = new ArrayList<String>();
|
||||
owners.add(getBareJID(0));
|
||||
answerForm.setAnswer("muc#roomconfig_roomowners", owners);
|
||||
}
|
||||
|
@ -1884,6 +1874,7 @@ public class MultiUserChatTest extends SmackTestCase {
|
|||
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,10 +65,6 @@ import org.jivesoftware.smack.test.SmackTestCase;
|
|||
*/
|
||||
public class MessageEventTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for MessageEventTest.
|
||||
* @param name
|
||||
*/
|
||||
public MessageEventTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
@ -82,10 +78,10 @@ public class MessageEventTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequest() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Create a MessageEvent Package and add it to the message
|
||||
|
@ -118,7 +114,7 @@ public class MessageEventTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
|
@ -143,7 +139,7 @@ public class MessageEventTest extends SmackTestCase {
|
|||
getConnection(0).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Create a MessageEvent Package and add it to the message
|
||||
|
|
|
@ -20,10 +20,6 @@ import org.jivesoftware.smackx.*;
|
|||
*/
|
||||
public class RosterExchangeTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for RosterExchangeTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public RosterExchangeTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
@ -35,10 +31,10 @@ public class RosterExchangeTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
|
@ -62,40 +58,12 @@ public class RosterExchangeTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendAndReceiveRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:roster");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
RosterExchange rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
|
@ -110,8 +78,20 @@ public class RosterExchangeTest extends SmackTestCase {
|
|||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
// Wait for 2 seconds for a reply
|
||||
msg = chat1.nextMessage(2000);
|
||||
assertNotNull("No reply received", msg);
|
||||
Packet packet = chat2.nextResult(2000);
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,47 +102,12 @@ public class RosterExchangeTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendAndAcceptRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2, save the roster entries and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:roster");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
RosterExchange rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
// Add the roster entries to user2's roster
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
getConnection(1).getRoster().createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
|
@ -177,12 +122,32 @@ public class RosterExchangeTest extends SmackTestCase {
|
|||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
// Wait for 10 seconds for a reply
|
||||
msg = chat1.nextMessage(5000);
|
||||
assertNotNull("No reply received", msg);
|
||||
Packet packet = chat2.nextResult(5000);
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
// Add the roster entries to user2's roster
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
getConnection(1).getRoster().createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
|
||||
assertTrue("Roster2 has no entries", getConnection(1).getRoster().getEntryCount() > 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,10 +69,6 @@ public class XHTMLExtensionTest extends SmackTestCase {
|
|||
private int bodiesSent;
|
||||
private int bodiesReceived;
|
||||
|
||||
/**
|
||||
* Constructor for XHTMLExtensionTest.
|
||||
* @param name
|
||||
*/
|
||||
public XHTMLExtensionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
@ -84,16 +80,16 @@ public class XHTMLExtensionTest extends SmackTestCase {
|
|||
*/
|
||||
public void testSendSimpleXHTMLMessage() {
|
||||
// User1 creates a chat with user2
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
// Create a XHTMLExtension Package and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
|
@ -107,62 +103,27 @@ public class XHTMLExtensionTest extends SmackTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
* Low level API test.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter =
|
||||
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
XHTMLExtension xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
// Create a XHTMLExtension Package and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
|
@ -172,67 +133,65 @@ public class XHTMLExtensionTest extends SmackTestCase {
|
|||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait for 2 seconds for a reply
|
||||
msg = chat1.nextMessage(1000);
|
||||
assertNotNull("No reply received", msg);
|
||||
Packet packet = chat2.nextResult(2000);
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
|
||||
final PacketCollector chat2 = getConnection(1).createPacketCollector(
|
||||
new ThreadFilter(chat1.getThreadID()));
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter =
|
||||
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
|
||||
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
XHTMLExtension xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
received++;
|
||||
System.out.println((String) it.next());
|
||||
}
|
||||
bodiesReceived = received;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
Message msg = new Message();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody(
|
||||
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||
// Create an XHTMLExtension and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridícula es el espantajo de mentes pequeñas.</p></blockquote></body>");
|
||||
"<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridícula es el espantajo de mentes pequeñas.</p></blockquote></body>");
|
||||
xhtmlExtension.addBody(
|
||||
"<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
|
||||
"<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
|
@ -240,16 +199,38 @@ public class XHTMLExtensionTest extends SmackTestCase {
|
|||
bodiesSent = xhtmlExtension.getBodiesCount();
|
||||
bodiesReceived = 0;
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(300);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
Packet packet = chat2.nextResult(2000);
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
received++;
|
||||
System.out.println((String) it.next());
|
||||
}
|
||||
bodiesReceived = received;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is " +
|
||||
"misconfigured");
|
||||
}
|
||||
// Wait half second so that the complete test can run
|
||||
assertEquals(
|
||||
"Number of sent and received XHTMP bodies does not match",
|
||||
bodiesSent,
|
||||
bodiesReceived);
|
||||
"Number of sent and received XHTMP bodies does not match",
|
||||
bodiesSent,
|
||||
bodiesReceived);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue