From 7d9189e490b3d2b58855e48b5fef98b08d93840b Mon Sep 17 00:00:00 2001 From: Alex Wenckus Date: Wed, 27 Dec 2006 20:02:59 +0000 Subject: [PATCH] test of sending message after sending a directed presence. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6481 b35dd754-fafc-0310-a699-88a17e54d16e --- test/org/jivesoftware/smack/MessageTest.java | 35 +++++++++++++++++++ .../smack/test/SmackTestCase.java | 10 ++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/test/org/jivesoftware/smack/MessageTest.java b/test/org/jivesoftware/smack/MessageTest.java index 1619c5867..5eb4e06ef 100644 --- a/test/org/jivesoftware/smack/MessageTest.java +++ b/test/org/jivesoftware/smack/MessageTest.java @@ -36,11 +36,38 @@ public class MessageTest extends SmackTestCase { super(arg0); } + /** + * Will a user recieve a message from another after only sending the user a directed presence, + * or will Wildfire intercept for offline storage? + */ + public void testDirectPresence() { + getConnection(1).sendPacket(new Presence(Presence.Type.available)); + + Presence presence = new Presence(Presence.Type.available); + presence.setTo(getFullJID(1)); + getConnection(0).sendPacket(presence); + + PacketCollector collector = getConnection(0) + .createPacketCollector(new MessageTypeFilter(Message.Type.chat)); + try { + getConnection(1).getChatManager().createChat(getBareJID(0), null).sendMessage("Test 1"); + } + catch (XMPPException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + Message message = (Message) collector.nextResult(2500); + assertNotNull("Message not recieved from remote user", message); + } + /** * Check that when a client becomes unavailable all messages sent to the client are stored offline. So that when * the client becomes available again the offline messages are received. */ public void testOfflineMessage() { + getConnection(0).sendPacket(new Presence(Presence.Type.available)); + getConnection(1).sendPacket(new Presence(Presence.Type.available)); // Make user2 unavailable getConnection(1).sendPacket(new Presence(Presence.Type.unavailable)); @@ -122,6 +149,8 @@ public class MessageTest extends SmackTestCase { * connections are not being closed. */ public void testHugeMessage() { + getConnection(0).sendPacket(new Presence(Presence.Type.available)); + getConnection(1).sendPacket(new Presence(Presence.Type.available)); // User2 becomes available again PacketCollector collector = getConnection(1).createPacketCollector( new MessageTypeFilter(Message.Type.chat)); @@ -154,4 +183,10 @@ public class MessageTest extends SmackTestCase { protected int getMaxConnections() { return 2; } + + + @Override + protected boolean sendInitialPresence() { + return false; + } } diff --git a/test/org/jivesoftware/smack/test/SmackTestCase.java b/test/org/jivesoftware/smack/test/SmackTestCase.java index 22040b22b..bbfb9b002 100644 --- a/test/org/jivesoftware/smack/test/SmackTestCase.java +++ b/test/org/jivesoftware/smack/test/SmackTestCase.java @@ -60,7 +60,7 @@ public abstract class SmackTestCase extends TestCase { /** * Constructor for SmackTestCase. - * @param arg0 + * @param arg0 arg for SmackTestCase */ public SmackTestCase(String arg0) { super(arg0); @@ -216,7 +216,7 @@ public abstract class SmackTestCase extends TestCase { } } // Login with the new test account - getConnection(i).login("user" + i, "user" + i); + getConnection(i).login("user" + i, "user" + i, "smack", sendInitialPresence()); } // Let the server process the available presences Thread.sleep(150); @@ -240,6 +240,10 @@ public abstract class SmackTestCase extends TestCase { } } + protected boolean sendInitialPresence() { + return true; + } + /** * Initializes the context of the test case. We will first try to load the configuration from * a file whose name is conformed by the test case class name plus an .xml extension @@ -269,6 +273,7 @@ public abstract class SmackTestCase extends TestCase { } } catch (Exception e) { + /* Do Nothing */ } } @@ -320,6 +325,7 @@ public abstract class SmackTestCase extends TestCase { systemStream.close(); } catch (Exception e) { + /* Do Nothing */ } } return parsedOK;