From 08f3b3dcba08117f763c32de5f463498f98f9bcf Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Tue, 15 Mar 2005 16:29:30 +0000 Subject: [PATCH] Modified priority testing to include more cases. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2465 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smack/PresencePriorityTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/org/jivesoftware/smack/PresencePriorityTest.java b/test/org/jivesoftware/smack/PresencePriorityTest.java index 3a0428a00..88ccd721d 100644 --- a/test/org/jivesoftware/smack/PresencePriorityTest.java +++ b/test/org/jivesoftware/smack/PresencePriorityTest.java @@ -62,6 +62,7 @@ public class PresencePriorityTest extends SmackTestCase { conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, Presence.Mode.AVAILABLE)); + Thread.sleep(150); // Test delivery of message to the presence with highest priority chat0.sendMessage("Hello"); assertNotNull("Resource with highest priority didn't receive the message", @@ -69,6 +70,48 @@ public class PresencePriorityTest extends SmackTestCase { assertNull("Resource with lowest priority received the message", chat2.nextMessage(1000)); + // User_1 closes his connection + chat2 = null; + conn.close(); + Thread.sleep(150); + + // Test delivery of message to the unique presence of the user_1 + chat0.sendMessage("Hello"); + assertNotNull("Resource with highest priority didn't receive the message", + chat1.nextMessage(2000)); + + getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, + Presence.Mode.AVAILABLE)); + + // User_1 will log in again using another resource + conn = new XMPPConnection(getHost(), getPort()); + conn.login(getUsername(1), getUsername(1), "OtherPlace"); + conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, + Presence.Mode.AVAILABLE)); + chat2 = new Chat(conn, getBareJID(0)); + + Thread.sleep(150); + // Test delivery of message to the presence with highest priority + chat0.sendMessage("Hello"); + assertNotNull("Resource with highest priority didn't receive the message", + chat1.nextMessage(2000)); + assertNull("Resource with lowest priority received the message", + chat2.nextMessage(1000)); + + // Invert the presence priorities of User_1 + getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, + Presence.Mode.AVAILABLE)); + conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, + Presence.Mode.AVAILABLE)); + + Thread.sleep(150); + // Test delivery of message to the presence with highest priority + chat0.sendMessage("Hello"); + assertNotNull("Resource with highest priority didn't receive the message", + chat2.nextMessage(2000)); + assertNull("Resource with lowest priority received the message", + chat1.nextMessage(1000)); + } catch (Exception e) { e.printStackTrace(); @@ -86,4 +129,9 @@ public class PresencePriorityTest extends SmackTestCase { protected int getMaxConnections() { return 2; } + + protected void setUp() throws Exception { + XMPPConnection.DEBUG_ENABLED = false; + super.setUp(); + } }