summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/RosterItemExchangeParserTest.java60
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/RosterParserTest.java117
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/RosterItemExchangeSerializerTest.java58
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/RosterSerializerTest.java105
4 files changed, 340 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/RosterItemExchangeParserTest.java b/test/com/isode/stroke/parser/payloadparsers/RosterItemExchangeParserTest.java
new file mode 100644
index 0000000..8bf2d52
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/RosterItemExchangeParserTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.RosterItemExchangePayload;
+import com.isode.stroke.parser.payloadparsers.RosterItemExchangeParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+import java.util.Vector;
+
+public class RosterItemExchangeParserTest {
+
+ public RosterItemExchangeParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<x xmlns=\"http://jabber.org/protocol/rosterx\">" +
+ "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" +
+ "<group>Group 1</group>" +
+ "<group>Group 2</group>" +
+ "</item>" +
+ "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" +
+ "</x>"));
+
+ RosterItemExchangePayload payload = (RosterItemExchangePayload)parser.getPayload();
+ Vector<RosterItemExchangePayload.Item> items = payload.getItems();
+
+ assertEquals(2, items.size());
+
+ assertEquals(new JID("foo@bar.com"), items.get(0).getJID());
+ assertEquals("Foo @ Bar", items.get(0).getName());
+ assertEquals(RosterItemExchangePayload.Item.Action.Add, items.get(0).getAction());
+ assertEquals(2, items.get(0).getGroups().size());
+ assertEquals("Group 1", items.get(0).getGroups().get(0));
+ assertEquals("Group 2", items.get(0).getGroups().get(1));
+
+ assertEquals(new JID("baz@blo.com"), items.get(1).getJID());
+ assertEquals("Baz", items.get(1).getName());
+ assertEquals(RosterItemExchangePayload.Item.Action.Modify, items.get(1).getAction());
+ assertEquals(0, items.get(1).getGroups().size());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/RosterParserTest.java b/test/com/isode/stroke/parser/payloadparsers/RosterParserTest.java
new file mode 100644
index 0000000..45f1735
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/RosterParserTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2010 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import com.isode.stroke.elements.RosterPayload;
+import com.isode.stroke.elements.RosterItemPayload;
+import com.isode.stroke.parser.payloadparsers.RosterParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+import java.util.ArrayList;
+import java.util.List;
+
+public class RosterParserTest {
+
+ public RosterParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<query xmlns='jabber:iq:roster'>" +
+ " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" +
+ " <group>Group 1</group>" +
+ " <group>Group 2</group>" +
+ " </item>" +
+ " <item jid='baz@blo.com' name='Baz'/>" +
+ "</query>"));
+
+ RosterPayload payload = (RosterPayload)(parser.getPayload());
+
+ assertNull(payload.getVersion());
+ List<RosterItemPayload> items = payload.getItems();
+
+ assertEquals(2, items.size());
+
+ assertEquals(new JID("foo@bar.com"), items.get(0).getJID());
+ assertEquals("Foo @ Bar", items.get(0).getName());
+ assertEquals(RosterItemPayload.Subscription.From, items.get(0).getSubscription());
+ assertTrue(items.get(0).getSubscriptionRequested());
+ assertEquals(2, items.get(0).getGroups().size());
+ assertEquals("Group 1", items.get(0).getGroups().toArray()[0]);
+ assertEquals("Group 2", items.get(0).getGroups().toArray()[1]);
+
+ assertEquals(new JID("baz@blo.com"), items.get(1).getJID());
+ assertEquals("Baz", items.get(1).getName());
+ assertEquals(RosterItemPayload.Subscription.None, items.get(1).getSubscription());
+ assertFalse(items.get(1).getSubscriptionRequested());
+ assertEquals(0, items.get(1).getGroups().size());
+ }
+
+ @Test
+ public void testParse_ItemWithUnknownContent() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<query xmlns='jabber:iq:roster'>" +
+ " <item jid='foo@bar.com' name='Foo @ Bar' subscription='from' ask='subscribe'>" +
+ " <group>Group 1</group>" +
+ " <foo xmlns=\"http://example.com\"><bar>Baz</bar></foo>" +
+ " <group>Group 2</group>" +
+ " <baz><fum>foo</fum></baz>" +
+ " </item>" +
+ "</query>"));
+
+ RosterPayload payload = (RosterPayload)(parser.getPayload());
+ List<RosterItemPayload> items = payload.getItems();
+
+ assertEquals(1, items.size());
+ assertEquals("Group 1", items.get(0).getGroups().toArray()[0]);
+ assertEquals("Group 2", items.get(0).getGroups().toArray()[1]);
+ assertEquals(
+ "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" +
+ "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>"
+ , items.get(0).getUnknownContent());
+ }
+
+ @Test
+ public void testParse_WithVersion() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<query xmlns='jabber:iq:roster' ver='ver10'/>"));
+
+ RosterPayload payload = (RosterPayload)(parser.getPayload());
+ assertNotNull(payload.getVersion());
+ assertEquals("ver10", payload.getVersion());
+ }
+
+ @Test
+ public void testParse_WithEmptyVersion() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<query xmlns='jabber:iq:roster' ver=''/>"));
+
+ RosterPayload payload = (RosterPayload)(parser.getPayload());
+ assertNotNull(payload.getVersion());
+ assertEquals("", payload.getVersion());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/RosterItemExchangeSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/RosterItemExchangeSerializerTest.java
new file mode 100644
index 0000000..c732d94
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/RosterItemExchangeSerializerTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.RosterItemExchangeSerializer;
+import com.isode.stroke.elements.RosterItemExchangePayload;
+import com.isode.stroke.jid.JID;
+
+public class RosterItemExchangeSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public RosterItemExchangeSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ RosterItemExchangeSerializer testling = new RosterItemExchangeSerializer();
+ RosterItemExchangePayload roster = new RosterItemExchangePayload();
+ RosterItemExchangePayload.Item item1 = new RosterItemExchangePayload.Item();
+ item1.setJID(new JID("foo@bar.com"));
+ item1.setName("Foo @ Bar");
+ item1.setAction(RosterItemExchangePayload.Item.Action.Add);
+ item1.addGroup("Group 1");
+ item1.addGroup("Group 2");
+ roster.addItem(item1);
+
+ RosterItemExchangePayload.Item item2 = new RosterItemExchangePayload.Item();
+ item2.setJID(new JID("baz@blo.com"));
+ item2.setName("Baz");
+ item2.setAction(RosterItemExchangePayload.Item.Action.Modify);
+ roster.addItem(item2);
+
+ String expectedResult =
+ "<x xmlns=\"http://jabber.org/protocol/rosterx\">" +
+ "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" +
+ "<group>Group 1</group>" +
+ "<group>Group 2</group>" +
+ "</item>" +
+ "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" +
+ "</x>";
+
+ assertEquals(expectedResult, testling.serialize(roster));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/RosterSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/RosterSerializerTest.java
new file mode 100644
index 0000000..ec74efe
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/RosterSerializerTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.RosterSerializer;
+import com.isode.stroke.elements.RosterPayload;
+import com.isode.stroke.elements.RosterItemPayload;
+import com.isode.stroke.jid.JID;
+
+public class RosterSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public RosterSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ RosterSerializer testling = new RosterSerializer();
+ RosterPayload roster = new RosterPayload();
+
+ RosterItemPayload item1 = new RosterItemPayload();
+ item1.setJID(new JID("foo@bar.com"));
+ item1.setName("Foo @ Bar");
+ item1.setSubscription(RosterItemPayload.Subscription.From);
+ item1.addGroup("Group 1");
+ item1.addGroup("Group 2");
+ item1.setSubscriptionRequested();
+ roster.addItem(item1);
+
+ RosterItemPayload item2 = new RosterItemPayload();
+ item2.setJID(new JID("baz@blo.com"));
+ item2.setName("Baz");
+ roster.addItem(item2);
+
+ String expectedResult =
+ "<query xmlns=\"jabber:iq:roster\">" +
+ "<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">" +
+ "<group>Group 1</group>" +
+ "<group>Group 2</group>" +
+ "</item>" +
+ "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>" +
+ "</query>";
+
+ assertEquals(expectedResult, testling.serialize(roster));
+ }
+
+ @Test
+ public void testSerialize_ItemWithUnknownContent() {
+ RosterSerializer testling = new RosterSerializer();
+ RosterPayload roster = new RosterPayload();
+
+ RosterItemPayload item = new RosterItemPayload();
+ item.setJID(new JID("baz@blo.com"));
+ item.setName("Baz");
+ item.addGroup("Group 1");
+ item.addGroup("Group 2");
+ item.addUnknownContent(
+ "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" +
+ "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>");
+ roster.addItem(item);
+
+ String expectedResult =
+ "<query xmlns=\"jabber:iq:roster\">" +
+ "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\">" +
+ "<group>Group 1</group>" +
+ "<group>Group 2</group>" +
+ "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" +
+ "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" +
+ "</item>" +
+ "</query>";
+
+ assertEquals(expectedResult, testling.serialize(roster));
+ }
+
+ @Test
+ public void testSerialize_WithVersion() {
+ RosterSerializer testling = new RosterSerializer();
+ RosterPayload roster = new RosterPayload();
+ roster.setVersion("ver20");
+
+ String expectedResult = "<query ver=\"ver20\" xmlns=\"jabber:iq:roster\"/>";
+
+ assertEquals(expectedResult, testling.serialize(roster));
+ }
+
+ @Test
+ public void testSerialize_WithEmptyVersion() {
+ RosterSerializer testling = new RosterSerializer();
+ RosterPayload roster = new RosterPayload();
+ roster.setVersion("");
+
+ String expectedResult = "<query ver=\"\" xmlns=\"jabber:iq:roster\"/>";
+
+ assertEquals(expectedResult, testling.serialize(roster));
+ }
+} \ No newline at end of file