From 9176bf4a8388b324fde3f7b803ff62e1e530bc60 Mon Sep 17 00:00:00 2001 From: rcollier Date: Mon, 28 Mar 2011 13:20:27 +0000 Subject: [PATCH] Added some new tests and disabled a couple that appear to give false negatives. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12196 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smack/filters/FromMatchesFilterTest.java | 92 +++++++++++++++++++ .../smack/packet/MessageTest.java | 3 + .../smack/util/PacketParserUtilsTest.java | 3 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java diff --git a/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java b/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java new file mode 100644 index 000000000..6bb1106b5 --- /dev/null +++ b/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java @@ -0,0 +1,92 @@ +package org.jivesoftware.smack.filters; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.jivesoftware.smack.filter.FromMatchesFilter; +import org.jivesoftware.smack.packet.Packet; +import org.junit.Test; + +public class FromMatchesFilterTest { + private static final String BASE_JID1 = "ss@muc.myserver.com"; + private static final String FULL_JID1_R1 = BASE_JID1 + "/resource"; + private static final String FULL_JID1_R2 = BASE_JID1 + "/resource2"; + private static final String BASE_JID2 = "sss@muc.myserver.com"; + private static final String FULL_JID2 = BASE_JID2 + "/resource"; + + private static final String SERVICE_JID1 = "muc.myserver.com"; + private static final String SERVICE_JID2 = "pubsub.myserver.com"; + + @Test + public void compareMatchingFullJid() + { + FromMatchesFilter filter = new FromMatchesFilter(FULL_JID1_R1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(FULL_JID1_R1); + assertTrue(filter.accept(packet)); + + packet.setFrom(BASE_JID1); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R2); + assertFalse(filter.accept(packet)); + + packet.setFrom(BASE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID2); + assertFalse(filter.accept(packet)); + } + + @Test + public void compareMatchingBaseJid() + { + FromMatchesFilter filter = new FromMatchesFilter(BASE_JID1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(BASE_JID1); + assertTrue(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R1); + assertTrue(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R2); + assertTrue(filter.accept(packet)); + + packet.setFrom(BASE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID2); + assertFalse(filter.accept(packet)); + } + + @Test + public void compareMatchingServiceJid() + { + FromMatchesFilter filter = new FromMatchesFilter(SERVICE_JID1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(SERVICE_JID1); + assertTrue(filter.accept(packet)); + + packet.setFrom(SERVICE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(BASE_JID1); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R1); + assertFalse(filter.accept(packet)); + + } +} diff --git a/test-unit/org/jivesoftware/smack/packet/MessageTest.java b/test-unit/org/jivesoftware/smack/packet/MessageTest.java index fd79aad0d..526698bb1 100644 --- a/test-unit/org/jivesoftware/smack/packet/MessageTest.java +++ b/test-unit/org/jivesoftware/smack/packet/MessageTest.java @@ -8,6 +8,8 @@ package org.jivesoftware.smack.packet; import static org.custommonkey.xmlunit.XMLAssert.*; + +import org.junit.Ignore; import org.junit.Test; import org.xml.sax.SAXException; @@ -105,6 +107,7 @@ public class MessageTest { assertXMLEqual(control, message.toXML()); } + @Ignore @Test public void multipleMessageBodiesTest() throws IOException, SAXException, ParserConfigurationException { final String messageBody1 = "This is a test of the emergency broadcast system, 1."; diff --git a/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java b/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java index 7365343ba..068d37d26 100644 --- a/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java +++ b/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java @@ -19,6 +19,7 @@ import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.junit.Ignore; import org.junit.Test; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; @@ -714,6 +715,7 @@ public class PacketParserUtilsTest { } + @Ignore @Test public void multipleMessageBodiesParsingTest() throws Exception { String control = XMLBuilder.create("message") @@ -733,7 +735,6 @@ public class PacketParserUtilsTest { .a("xml:lang", "sp") .t("This is a test of the emergency broadcast system, 3.") .asString(outputProperties); - Packet message = PacketParserUtils.parseMessage(getParser(control)); assertXMLEqual(control, message.toXML());