1 11 12 package org.jivesoftware.smack; 13 14 import org.jivesoftware.smack.test.SmackTestCase; 15 import org.jivesoftware.smack.packet.Presence; 16 17 23 public class PresencePriorityTest extends SmackTestCase { 24 25 public PresencePriorityTest(String arg0) { 26 super(arg0); 27 } 28 29 33 public void testMessageToHighestPriority() { 34 boolean wasFiltering = Chat.isFilteredOnThreadID(); 35 Chat.setFilteredOnThreadID(false); 36 XMPPConnection conn = null; 37 try { 38 conn = new XMPPConnection(getHost(), getPort()); 40 conn.login(getUsername(1), getUsername(1), "OtherPlace"); 41 getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, 43 Presence.Mode.AVAILABLE)); 44 conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, 45 Presence.Mode.AVAILABLE)); 46 Thread.sleep(150); 47 Chat chat0 = new Chat(getConnection(0), getBareJID(1)); 49 Chat chat1 = new Chat(getConnection(1), getBareJID(0)); 50 Chat chat2 = new Chat(conn, getBareJID(0)); 51 52 chat0.sendMessage("Hello"); 54 assertNotNull("Resource with highest priority didn't receive the message", 55 chat2.nextMessage(2000)); 56 assertNull("Resource with lowest priority received the message", 57 chat1.nextMessage(1000)); 58 59 getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, 61 Presence.Mode.AVAILABLE)); 62 conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, 63 Presence.Mode.AVAILABLE)); 64 65 Thread.sleep(150); 66 chat0.sendMessage("Hello"); 68 assertNotNull("Resource with highest priority didn't receive the message", 69 chat1.nextMessage(2000)); 70 assertNull("Resource with lowest priority received the message", 71 chat2.nextMessage(1000)); 72 73 chat2 = null; 75 conn.close(); 76 Thread.sleep(150); 77 78 chat0.sendMessage("Hello"); 80 assertNotNull("Resource with highest priority didn't receive the message", 81 chat1.nextMessage(2000)); 82 83 getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, 84 Presence.Mode.AVAILABLE)); 85 86 conn = new XMPPConnection(getHost(), getPort()); 88 conn.login(getUsername(1), getUsername(1), "OtherPlace"); 89 conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, 90 Presence.Mode.AVAILABLE)); 91 chat2 = new Chat(conn, getBareJID(0)); 92 93 Thread.sleep(150); 94 chat0.sendMessage("Hello"); 96 assertNotNull("Resource with highest priority didn't receive the message", 97 chat1.nextMessage(2000)); 98 assertNull("Resource with lowest priority received the message", 99 chat2.nextMessage(1000)); 100 101 getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1, 103 Presence.Mode.AVAILABLE)); 104 conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2, 105 Presence.Mode.AVAILABLE)); 106 107 Thread.sleep(150); 108 chat0.sendMessage("Hello"); 110 assertNotNull("Resource with highest priority didn't receive the message", 111 chat2.nextMessage(2000)); 112 assertNull("Resource with lowest priority received the message", 113 chat1.nextMessage(1000)); 114 115 } 116 catch (Exception e) { 117 e.printStackTrace(); 118 fail(e.getMessage()); 119 } 120 finally { 121 Chat.setFilteredOnThreadID(wasFiltering); 123 if (conn != null) { 124 conn.close(); 125 } 126 } 127 } 128 129 protected int getMaxConnections() { 130 return 2; 131 } 132 133 protected void setUp() throws Exception { 134 XMPPConnection.DEBUG_ENABLED = false; 135 super.setUp(); 136 } 137 } 138 | Popular Tags |