public void testMessageFlood() { try { Chat chat11 = getConnection(0).getChatManager().createChat(getBareJID(1), null); PacketCollector chat12 = getConnection(1).createPacketCollector( new ThreadFilter(chat11.getThreadID())); Chat chat21 = getConnection(0).getChatManager().createChat(getBareJID(2), null); PacketCollector chat22 = getConnection(2).createPacketCollector( new ThreadFilter(chat21.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); chat21.sendMessage("Hello_2" + i); chat31.sendMessage("Hello_3" + i); } for (int i=0; i<500; i++) { 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) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void abstractListFilterToStringTest() { AndFilter andFilter = new AndFilter(); andFilter.addFilter(new StanzaIdFilter("foo")); andFilter.addFilter(new ThreadFilter("42")); andFilter.addFilter(MessageWithBodiesFilter.INSTANCE); final String res =andFilter.toString(); assertEquals("AndFilter: (StanzaIdFilter: id=foo, ThreadFilter: thread=42, MessageWithBodiesFilter)", res); }
public void testProperties() { try { Chat newChat = getConnection(0).getChatManager().createChat(getFullJID(1), null); PacketCollector collector = getConnection(1) .createPacketCollector(new ThreadFilter(newChat.getThreadID())); Message msg = new Message(); msg.setSubject("Subject of the chat"); msg.setBody("Body of the chat"); msg.setProperty("favoriteColor", "red"); msg.setProperty("age", 30); msg.setProperty("distance", 30f); msg.setProperty("weight", 30d); msg.setProperty("male", true); msg.setProperty("birthdate", new Date()); newChat.sendMessage(msg); 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")); assertEquals( "ages are different", msg.getProperty("age"), msg2.getProperty("age")); assertEquals( "distances are different", msg.getProperty("distance"), msg2.getProperty("distance")); assertEquals( "weights are different", msg.getProperty("weight"), msg2.getProperty("weight")); assertEquals( "males are different", msg.getProperty("male"), msg2.getProperty("male")); assertEquals( "birthdates are different", msg.getProperty("birthdate"), msg2.getProperty("birthdate")); } catch (XMPPException e) { e.printStackTrace(); fail(e.getMessage()); } }
PacketCollector createPacketCollector(Chat chat) { return connection().createPacketCollector(new AndFilter(new ThreadFilter(chat.getThreadID()), FromMatchesFilter.create(chat.getParticipant()))); }
PacketCollector createPacketCollector(Chat chat) { return connection.createPacketCollector(new AndFilter(new ThreadFilter(chat.getThreadID()), new FromContainsFilter(chat.getParticipant()))); }
PacketCollector createPacketCollector(Chat chat) { return connection.createPacketCollector(new AndFilter(new ThreadFilter( chat.getThreadID()), new FromContainsFilter(chat .getParticipant()))); }