summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-22 20:29:55 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-07-07 07:09:25 (GMT)
commitae1f4d65b253fa1a263556be7419836a37683dd2 (patch)
tree7628bd7b894e0dee72e61f7aba197ffb7bf28716 /test/com/isode
parentac54c7b41a869d5c8762ce57fb8e918f1ba557f0 (diff)
downloadstroke-ae1f4d65b253fa1a263556be7419836a37683dd2.zip
stroke-ae1f4d65b253fa1a263556be7419836a37683dd2.tar.bz2
Adds tests for Parser and Serializers.
Adds PubSubEvent Element. Adds StreamFeaturesSerializer. Adds ParserTester, ElementParserTester, StanzaParserTester, PayloadParserTester, PayloadsSerializer and EnumParser. Updates Error Payload, JingleFIleTransferHash Elements/ Updates StreamFeaturesParser, ParserElement. Updates Delay Serializer, Error Serializer. Updates AuthChallenge and AuthRequest Element. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Test are added for: AuthChallenge Serializer, AuthRequest Serializer, AuthResponse Serializer, AuthSuccess Serializer. GenericPayloadTreeParserTest. IQ Parser. Message Parser. Presence Parser. StanzaAck Parser. Stanza Parser. StreamFeatures Parser and Serializer. StreamManagementEnabled Parser. Private Storage Parser and Serializer. RawXMLPayload Parser. Storage Parser and Serializer. Error Serializer. Jingle Serializer. PubSubItem Serializer and PubSubItems Serializer. Serializing Parser. All tests passes. Change-Id: I79e00dc5b5c4f85e659bf88b1547dd7c17825805
Diffstat (limited to 'test/com/isode')
-rw-r--r--test/com/isode/stroke/parser/AttributeMapTest.java91
-rw-r--r--test/com/isode/stroke/parser/ElementParserTester.java47
-rw-r--r--test/com/isode/stroke/parser/EnumParserTest.java51
-rw-r--r--test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java66
-rw-r--r--test/com/isode/stroke/parser/IQParserTest.java79
-rw-r--r--test/com/isode/stroke/parser/MessageParserTest.java89
-rw-r--r--test/com/isode/stroke/parser/ParserTester.java47
-rw-r--r--test/com/isode/stroke/parser/PresenceParserTest.java118
-rw-r--r--test/com/isode/stroke/parser/SerializingParserTest.java74
-rw-r--r--test/com/isode/stroke/parser/StanzaAckParserTest.java60
-rw-r--r--test/com/isode/stroke/parser/StanzaParserTest.java227
-rw-r--r--test/com/isode/stroke/parser/StanzaParserTester.java47
-rw-r--r--test/com/isode/stroke/parser/StreamFeaturesParserTest.java118
-rw-r--r--test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java42
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java39
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java47
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java106
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java45
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java97
-rw-r--r--test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java61
-rw-r--r--test/com/isode/stroke/serializer/AuthRequestSerializerTest.java62
-rw-r--r--test/com/isode/stroke/serializer/AuthResponseSerializerTest.java62
-rw-r--r--test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java62
-rw-r--r--test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java59
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java55
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java287
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java32
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java55
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java65
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java86
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java76
31 files changed, 2452 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/AttributeMapTest.java b/test/com/isode/stroke/parser/AttributeMapTest.java
new file mode 100644
index 0000000..45f5a4c
--- /dev/null
+++ b/test/com/isode/stroke/parser/AttributeMapTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+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.parser.AttributeMap;
+
+public class AttributeMapTest {
+
+ public AttributeMapTest() {
+
+ }
+
+ @Test
+ public void testGetAttribute_Namespaced() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("lang", "", "nl");
+ testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en");
+ testling.addAttribute("lang", "", "fr");
+
+ assertEquals("en", testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"));
+ }
+
+ @Test
+ public void testGetBoolAttribute_True() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("foo", "", "true");
+
+ assertTrue(testling.getBoolAttribute("foo"));
+ }
+
+ @Test
+ public void testGetBoolAttribute_1() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("foo", "", "1");
+
+ assertTrue(testling.getBoolAttribute("foo"));
+ }
+
+ @Test
+ public void testGetBoolAttribute_False() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("foo", "", "false");
+
+ assertFalse(testling.getBoolAttribute("foo", true));
+ }
+
+ @Test
+ public void testGetBoolAttribute_0() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("foo", "", "0");
+
+ assertFalse(testling.getBoolAttribute("foo", true));
+ }
+
+ @Test
+ public void testGetBoolAttribute_Invalid() {
+ AttributeMap testling = new AttributeMap();
+ testling.addAttribute("foo", "", "bla");
+
+ assertFalse(testling.getBoolAttribute("foo", true));
+ }
+
+ @Test
+ public void testGetBoolAttribute_UnknownWithDefaultTrue() {
+ AttributeMap testling = new AttributeMap();
+
+ assertTrue(testling.getBoolAttribute("foo", true));
+ }
+
+ @Test
+ public void testGetBoolAttribute_UnknownWithDefaultFalse() {
+ AttributeMap testling = new AttributeMap();
+
+ assertFalse(testling.getBoolAttribute("foo", false));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/ElementParserTester.java b/test/com/isode/stroke/parser/ElementParserTester.java
new file mode 100644
index 0000000..d8a0252
--- /dev/null
+++ b/test/com/isode/stroke/parser/ElementParserTester.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import com.isode.stroke.parser.XMLParser;
+import com.isode.stroke.eventloop.EventLoop;
+import com.isode.stroke.parser.XMLParserClient;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.ElementParser;
+import com.isode.stroke.parser.PlatformXMLParserFactory;
+
+public class ElementParserTester<ParserType extends ElementParser> implements XMLParserClient {
+
+ private XMLParser xmlParser_;
+ private ParserType parser_;
+
+ public ElementParserTester(ParserType parser) {
+ this.parser_ = parser;
+ xmlParser_ = PlatformXMLParserFactory.createXMLParser(this);
+ }
+
+ public boolean parse(String data) {
+ return xmlParser_.parse(data);
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ parser_.handleStartElement(element, ns, attributes);
+ }
+
+ public void handleEndElement(String element, String ns) {
+ parser_.handleEndElement(element, ns);
+ }
+
+ public void handleCharacterData(String data) {
+ parser_.handleCharacterData(data);
+ }
+}
+
diff --git a/test/com/isode/stroke/parser/EnumParserTest.java b/test/com/isode/stroke/parser/EnumParserTest.java
new file mode 100644
index 0000000..aa20873
--- /dev/null
+++ b/test/com/isode/stroke/parser/EnumParserTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 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;
+
+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.parser.EnumParser;
+
+public class EnumParserTest {
+
+ public EnumParserTest() {
+
+ }
+
+ public enum MyEnum {
+ MyValue1,
+ MyValue2,
+ MyValue3
+ };
+
+ @Test
+ public void testParse() {
+ EnumParser parser = new EnumParser<MyEnum>();
+ parser.addValue(MyEnum.MyValue1, "my-value-1");
+ parser.addValue(MyEnum.MyValue2, "my-value-2");
+ parser.addValue(MyEnum.MyValue3, "my-value-3");
+ assertEquals(MyEnum.MyValue2, parser.parse("my-value-2"));
+ }
+
+ @Test
+ public void testParse_NoValue() {
+ EnumParser parser = new EnumParser<MyEnum>();
+ parser.addValue(MyEnum.MyValue1, "my-value-1");
+ parser.addValue(MyEnum.MyValue2, "my-value-2");
+ parser.addValue(MyEnum.MyValue3, "my-value-3");
+ assertNull(parser.parse("my-value-4"));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java b/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java
new file mode 100644
index 0000000..1021eae
--- /dev/null
+++ b/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011 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;
+
+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.parser.GenericPayloadTreeParser;
+import com.isode.stroke.elements.RawXMLPayload;
+import com.isode.stroke.parser.tree.ParserElement;
+import com.isode.stroke.parser.tree.NullParserElement;
+import com.isode.stroke.parser.payloadparsers.PayloadParserTester;
+
+public class GenericPayloadTreeParserTest {
+
+ public GenericPayloadTreeParserTest() {
+
+ }
+
+ private class MyParser extends GenericPayloadTreeParser<RawXMLPayload> {
+
+ public MyParser() {
+ super(new RawXMLPayload());
+ }
+
+ public void handleTree(ParserElement root) {
+ tree = root;
+ }
+
+ public ParserElement tree;
+ }
+
+ @Test
+ public void testTree() {
+ MyParser testling = new MyParser();
+
+ String data = "<topLevel xmlns='urn:test:top'><firstLevelInheritedEmpty/><firstLevelInherited><secondLevelMultiChildren num='1'/><secondLevelMultiChildren num='2'/></firstLevelInherited><firstLevelNS xmlns='urn:test:first'/></topLevel>";
+
+ PayloadParserTester tester = new PayloadParserTester(testling);
+ tester.parse(data);
+
+ ParserElement tree = testling.tree;
+
+ assertEquals("topLevel", tree.getName());
+ assertEquals("urn:test:top", tree.getNamespace());
+ assertNotNull(tree.getChild("firstLevelInheritedEmpty", "urn:test:top"));
+ assertTrue(tree.getChild("firstLevelInheritedEmpty", "") instanceof NullParserElement);
+ assertNotNull(tree.getChild("firstLevelInherited", "urn:test:top"));
+ assertEquals(2, tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").size());
+ assertEquals("1", tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").get(0).getAttributes().getAttribute("num"));
+ assertEquals("2", tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").get(1).getAttributes().getAttribute("num"));
+ assertNotNull(tree.getChild("firstLevelNS", "urn:test:first"));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/IQParserTest.java b/test/com/isode/stroke/parser/IQParserTest.java
new file mode 100644
index 0000000..603caec
--- /dev/null
+++ b/test/com/isode/stroke/parser/IQParserTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+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 org.junit.Before;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.StanzaParserTester;
+import com.isode.stroke.parser.IQParser;
+import com.isode.stroke.elements.IQ;
+
+public class IQParserTest {
+
+ private PayloadParserFactoryCollection factoryCollection_;
+
+ public IQParserTest() {
+
+ }
+
+ @Before
+ public void setUp() {
+ factoryCollection_ = new PayloadParserFactoryCollection();
+ }
+
+ @Test
+ public void testParse_Set() {
+ IQParser testling = new IQParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<iq type=\"set\"/>"));
+
+ assertEquals(IQ.Type.Set, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Get() {
+ IQParser testling = new IQParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<iq type=\"get\"/>"));
+
+ assertEquals(IQ.Type.Get, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Result() {
+ IQParser testling = new IQParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<iq type=\"result\"/>"));
+
+ assertEquals(IQ.Type.Result, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Error() {
+ IQParser testling = new IQParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<iq type=\"error\"/>"));
+
+ assertEquals(IQ.Type.Error, testling.getStanzaGeneric().getType());
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/MessageParserTest.java b/test/com/isode/stroke/parser/MessageParserTest.java
new file mode 100644
index 0000000..5b5e08a
--- /dev/null
+++ b/test/com/isode/stroke/parser/MessageParserTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+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 org.junit.Before;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.StanzaParserTester;
+import com.isode.stroke.parser.MessageParser;
+import com.isode.stroke.elements.Message;
+
+public class MessageParserTest {
+
+ private PayloadParserFactoryCollection factoryCollection_;
+
+ public MessageParserTest() {
+
+ }
+
+ @Before
+ public void setUp() {
+ factoryCollection_ = new PayloadParserFactoryCollection();
+ }
+
+ @Test
+ public void testParse_Chat() {
+ MessageParser testling = new MessageParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<message type=\"chat\"/>"));
+
+ assertEquals(Message.Type.Chat, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Groupchat() {
+ MessageParser testling = new MessageParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<message type=\"groupchat\"/>"));
+
+ assertEquals(Message.Type.Groupchat, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Error() {
+ MessageParser testling = new MessageParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<message type=\"error\"/>"));
+
+ assertEquals(Message.Type.Error, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Headline() {
+ MessageParser testling = new MessageParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<message type=\"headline\"/>"));
+
+ assertEquals(Message.Type.Headline, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Normal() {
+ MessageParser testling = new MessageParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<message/>"));
+
+ assertEquals(Message.Type.Normal, testling.getStanzaGeneric().getType());
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/ParserTester.java b/test/com/isode/stroke/parser/ParserTester.java
new file mode 100644
index 0000000..90c9586
--- /dev/null
+++ b/test/com/isode/stroke/parser/ParserTester.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import com.isode.stroke.parser.XMLParser;
+import com.isode.stroke.eventloop.EventLoop;
+import com.isode.stroke.parser.XMLParserClient;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.ElementParser;
+import com.isode.stroke.parser.PlatformXMLParserFactory;
+
+public class ParserTester<ParserType extends XMLParserClient> implements XMLParserClient {
+
+ private XMLParser xmlParser_;
+ private ParserType parser_;
+
+ public ParserTester(ParserType parser) {
+ this.parser_ = parser;
+ xmlParser_ = PlatformXMLParserFactory.createXMLParser(this);
+ }
+
+ public boolean parse(String data) {
+ return xmlParser_.parse(data);
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ parser_.handleStartElement(element, ns, attributes);
+ }
+
+ public void handleEndElement(String element, String ns) {
+ parser_.handleEndElement(element, ns);
+ }
+
+ public void handleCharacterData(String data) {
+ parser_.handleCharacterData(data);
+ }
+}
+
diff --git a/test/com/isode/stroke/parser/PresenceParserTest.java b/test/com/isode/stroke/parser/PresenceParserTest.java
new file mode 100644
index 0000000..bcd617a
--- /dev/null
+++ b/test/com/isode/stroke/parser/PresenceParserTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+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 org.junit.Before;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.StanzaParserTester;
+import com.isode.stroke.parser.PresenceParser;
+import com.isode.stroke.elements.Presence;
+
+public class PresenceParserTest {
+
+ private PayloadParserFactoryCollection factoryCollection_;
+
+ public PresenceParserTest() {
+
+ }
+
+ @Before
+ public void setUp() {
+ factoryCollection_ = new PayloadParserFactoryCollection();
+ }
+
+ @Test
+ public void testParse_Available() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence/>"));
+
+ assertEquals(Presence.Type.Available, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Unavailable() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"unavailable\"/>"));
+
+ assertEquals(Presence.Type.Unavailable, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Probe() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"probe\"/>"));
+
+ assertEquals(Presence.Type.Probe, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Subscribe() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"subscribe\"/>"));
+
+ assertEquals(Presence.Type.Subscribe, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Subscribed() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"subscribed\"/>"));
+
+ assertEquals(Presence.Type.Subscribed, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Unsubscribe() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"unsubscribe\"/>"));
+
+ assertEquals(Presence.Type.Unsubscribe, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Unsubscribed() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"unsubscribed\"/>"));
+
+ assertEquals(Presence.Type.Unsubscribed, testling.getStanzaGeneric().getType());
+ }
+
+ @Test
+ public void testParse_Error() {
+ PresenceParser testling = new PresenceParser(factoryCollection_);
+ StanzaParserTester parser = new StanzaParserTester(testling);
+
+ assertTrue(parser.parse("<presence type=\"error\"/>"));
+
+ assertEquals(Presence.Type.Error, testling.getStanzaGeneric().getType());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/SerializingParserTest.java b/test/com/isode/stroke/parser/SerializingParserTest.java
new file mode 100644
index 0000000..eff8d6a
--- /dev/null
+++ b/test/com/isode/stroke/parser/SerializingParserTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+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.parser.SerializingParser;
+import com.isode.stroke.parser.XMLParserClient;
+import com.isode.stroke.parser.ParserTester;
+import com.isode.stroke.parser.AttributeMap;
+
+public class SerializingParserTest {
+
+ private class ToTestSerializingParser extends SerializingParser implements XMLParserClient {
+
+ }
+
+ public SerializingParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ ToTestSerializingParser testling = new ToTestSerializingParser();
+ ParserTester parser = new ParserTester(testling);
+
+ assertTrue(parser.parse(
+ "<message type=\"chat\" to=\"me@foo.com\">"
+ + "<body>Hello&lt;&amp;World</body>"
+ + "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
+ + "foo<b>bar</b>baz"
+ + "</html>"
+ + "</message>"));
+
+ assertEquals(
+ "<message to=\"me@foo.com\" type=\"chat\">"
+ + "<body>Hello&lt;&amp;World</body>"
+ + "<html xmlns=\"http://www.w3.org/1999/xhtml\">foo<b xmlns=\"http://www.w3.org/1999/xhtml\">bar</b>baz</html>"
+ + "</message>", testling.getResult());
+ }
+
+ @Test
+ public void testParse_Empty() {
+ ToTestSerializingParser testling = new ToTestSerializingParser();
+
+ assertEquals("", testling.getResult());
+ }
+
+ @Test
+ public void testParse_ToplevelCharacterData() {
+ ToTestSerializingParser testling = new ToTestSerializingParser();
+
+ AttributeMap attributes = new AttributeMap();
+ testling.handleCharacterData("foo");
+ testling.handleStartElement("message", "", attributes);
+ testling.handleEndElement("message", "");
+ testling.handleCharacterData("bar");
+
+ assertEquals("<message/>", testling.getResult());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/StanzaAckParserTest.java b/test/com/isode/stroke/parser/StanzaAckParserTest.java
new file mode 100644
index 0000000..ad6b951
--- /dev/null
+++ b/test/com/isode/stroke/parser/StanzaAckParserTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+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.parser.StanzaAckParser;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.ElementParserTester;
+
+public class StanzaAckParserTest {
+
+ public StanzaAckParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ StanzaAckParser testling = new StanzaAckParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse("<a h=\"12\" xmlns=\"urn:xmpp:sm:2\"/>"));
+
+ assertTrue(testling.getElementGeneric().isValid());
+ assertEquals(12, testling.getElementGeneric().getHandledStanzasCount());
+ }
+
+ @Test
+ public void testParse_Invalid() {
+ StanzaAckParser testling = new StanzaAckParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse("<a h=\"invalid\" xmlns=\"urn:xmpp:sm:2\"/>"));
+
+ assertFalse(testling.getElementGeneric().isValid());
+ }
+
+ @Test
+ public void testParse_Empty() {
+ StanzaAckParser testling = new StanzaAckParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse("<a xmlns=\"urn:xmpp:sm:2\"/>"));
+
+ assertFalse(testling.getElementGeneric().isValid());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/StanzaParserTest.java b/test/com/isode/stroke/parser/StanzaParserTest.java
new file mode 100644
index 0000000..de10d44
--- /dev/null
+++ b/test/com/isode/stroke/parser/StanzaParserTest.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 2010-2014 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;
+
+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 org.junit.Before;
+import com.isode.stroke.parser.StanzaParser;
+import com.isode.stroke.parser.PayloadParserFactory;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.elements.Stanza;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.Element;
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.jid.JID;
+
+public class StanzaParserTest {
+
+ public StanzaParserTest() {
+
+ }
+
+ private class MyPayload1 extends Payload {
+
+ public MyPayload1() {
+ this.hasChild = false;
+ }
+
+ public boolean hasChild;
+ }
+
+ private class MyPayload1Parser extends GenericPayloadParser<MyPayload1> {
+
+ public MyPayload1Parser() {
+ super(new MyPayload1());
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ if (!element.equals("mypayload1")) {
+ getPayloadInternal().hasChild = true;
+ }
+ }
+
+ public void handleEndElement(String element, String ns) {}
+ public void handleCharacterData(String data) {}
+ }
+
+ private class MyPayload1ParserFactory implements PayloadParserFactory {
+
+ public MyPayload1ParserFactory() {
+
+ }
+
+ public PayloadParser createPayloadParser() {
+ return new MyPayload1Parser();
+ }
+
+ public boolean canParse(String element, String ns, AttributeMap attributes) {
+ return element.equals("mypayload1");
+ }
+ }
+
+ private class MyPayload2 extends Payload {
+
+ public MyPayload2() {
+
+ }
+ }
+
+ private class MyPayload2Parser extends GenericPayloadParser<MyPayload2> {
+
+ public MyPayload2Parser() {
+ super(new MyPayload2());
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {}
+ public void handleEndElement(String element, String ns) {}
+ public void handleCharacterData(String data) {}
+ }
+
+ private class MyPayload2ParserFactory implements PayloadParserFactory {
+
+ public MyPayload2ParserFactory() {
+
+ }
+
+ public PayloadParser createPayloadParser() {
+ return new MyPayload2Parser();
+ }
+
+ public boolean canParse(String element, String ns, AttributeMap attributes) {
+ return element.equals("mypayload2");
+ }
+ }
+
+
+ private class MyStanza extends Stanza {
+
+ public MyStanza() {}
+ }
+
+ private class MyStanzaParser extends StanzaParser {
+
+ public MyStanzaParser(PayloadParserFactoryCollection collection) {
+ super(collection);
+ stanza_ = new MyStanza();
+ }
+
+ public Element getElement() {
+ return stanza_;
+ }
+
+ private MyStanza stanza_;
+ }
+
+ private MyPayload1ParserFactory factory1_ = new MyPayload1ParserFactory();
+ private MyPayload2ParserFactory factory2_ = new MyPayload2ParserFactory();
+ private PayloadParserFactoryCollection factoryCollection_;
+
+ @Before
+ public void setUp() {
+ factoryCollection_ = new PayloadParserFactoryCollection();
+ factoryCollection_.addFactory(factory1_);
+ factoryCollection_.addFactory(factory2_);
+ }
+
+ @Test
+ public void testHandleEndElement_OnePayload() {
+ MyStanzaParser testling = new MyStanzaParser(factoryCollection_);
+
+ AttributeMap attributes = new AttributeMap();
+ attributes.addAttribute("foo", "", "fum");
+ attributes.addAttribute("bar", "", "baz");
+ testling.handleStartElement("mystanza", "", attributes);
+ testling.handleStartElement("mypayload1", "", attributes);
+ testling.handleStartElement("child", "", attributes);
+ testling.handleEndElement("child", "");
+ testling.handleEndElement("mypayload1", "");
+ testling.handleEndElement("mystanza", "");
+
+ assertNotNull(testling.getStanza().getPayload(new MyPayload1()));
+ assertTrue(testling.getStanza().getPayload(new MyPayload1()).hasChild);
+ }
+
+ @Test
+ public void testHandleEndElement_MultiplePayloads() {
+ MyStanzaParser testling = new MyStanzaParser(factoryCollection_);
+
+ AttributeMap attributes = new AttributeMap();
+ testling.handleStartElement("mystanza", "", attributes);
+ testling.handleStartElement("mypayload1", "", attributes);
+ testling.handleEndElement("mypayload1", "");
+ testling.handleStartElement("mypayload2", "", attributes);
+ testling.handleEndElement("mypayload2", "");
+ testling.handleEndElement("mystanza", "");
+
+ assertNotNull(testling.getStanza().getPayload(new MyPayload1()));
+ assertNotNull(testling.getStanza().getPayload(new MyPayload2()));
+ }
+
+ @Test
+ public void testHandleEndElement_StrayCharacterData() {
+ MyStanzaParser testling = new MyStanzaParser(factoryCollection_);
+
+ AttributeMap attributes = new AttributeMap();
+ testling.handleStartElement("mystanza", "", attributes);
+ testling.handleStartElement("mypayload1", "", attributes);
+ testling.handleEndElement("mypayload1", "");
+ testling.handleCharacterData("bla");
+ testling.handleStartElement("mypayload2", "", attributes);
+ testling.handleEndElement("mypayload2", "");
+ testling.handleEndElement("mystanza", "");
+
+ assertNotNull(testling.getStanza().getPayload(new MyPayload1()));
+ assertNotNull(testling.getStanza().getPayload(new MyPayload2()));
+ }
+
+ @Test
+ public void testHandleEndElement_UnknownPayload() {
+ MyStanzaParser testling = new MyStanzaParser(factoryCollection_);
+
+ AttributeMap attributes = new AttributeMap();
+ testling.handleStartElement("mystanza", "", attributes);
+ testling.handleStartElement("mypayload1", "", attributes);
+ testling.handleEndElement("mypayload1", "");
+ testling.handleStartElement("unknown-payload", "", attributes);
+ testling.handleStartElement("unknown-payload-child", "", attributes);
+ testling.handleEndElement("unknown-payload-child", "");
+ testling.handleEndElement("unknown-payload", "");
+ testling.handleStartElement("mypayload2", "", attributes);
+ testling.handleEndElement("mypayload2", "");
+ testling.handleEndElement("mystanza", "");
+
+ assertNotNull(testling.getStanza().getPayload(new MyPayload1()));
+ assertNotNull(testling.getStanza().getPayload(new MyPayload2()));
+ }
+
+ @Test
+ public void testHandleParse_BasicAttributes() {
+ MyStanzaParser testling = new MyStanzaParser(factoryCollection_);
+
+ AttributeMap attributes = new AttributeMap();
+ attributes.addAttribute("to", "", "foo@example.com/blo");
+ attributes.addAttribute("from", "", "bar@example.com/baz");
+ attributes.addAttribute("id", "", "id-123");
+ testling.handleStartElement("mystanza", "", attributes);
+ testling.handleEndElement("mypayload1", "");
+
+ assertEquals(new JID("foo@example.com/blo"), testling.getStanza().getTo());
+ assertEquals(new JID("bar@example.com/baz"), testling.getStanza().getFrom());
+ assertEquals("id-123", testling.getStanza().getID());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/StanzaParserTester.java b/test/com/isode/stroke/parser/StanzaParserTester.java
new file mode 100644
index 0000000..09adcbb
--- /dev/null
+++ b/test/com/isode/stroke/parser/StanzaParserTester.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import com.isode.stroke.parser.XMLParser;
+import com.isode.stroke.eventloop.EventLoop;
+import com.isode.stroke.parser.XMLParserClient;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.StanzaParser;
+import com.isode.stroke.parser.PlatformXMLParserFactory;
+
+public class StanzaParserTester<ParserType extends StanzaParser> implements XMLParserClient {
+
+ private XMLParser xmlParser_;
+ private ParserType parser_;
+
+ public StanzaParserTester(ParserType parser) {
+ this.parser_ = parser;
+ xmlParser_ = PlatformXMLParserFactory.createXMLParser(this);
+ }
+
+ public boolean parse(String data) {
+ return xmlParser_.parse(data);
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ parser_.handleStartElement(element, ns, attributes);
+ }
+
+ public void handleEndElement(String element, String ns) {
+ parser_.handleEndElement(element, ns);
+ }
+
+ public void handleCharacterData(String data) {
+ parser_.handleCharacterData(data);
+ }
+}
+
diff --git a/test/com/isode/stroke/parser/StreamFeaturesParserTest.java b/test/com/isode/stroke/parser/StreamFeaturesParserTest.java
new file mode 100644
index 0000000..1a32a72
--- /dev/null
+++ b/test/com/isode/stroke/parser/StreamFeaturesParserTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2013 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;
+
+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.parser.StreamFeaturesParser;
+import com.isode.stroke.elements.StreamFeatures;
+import com.isode.stroke.parser.ElementParserTester;
+
+public class StreamFeaturesParserTest {
+
+ public StreamFeaturesParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ StreamFeaturesParser testling = new StreamFeaturesParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse(
+ "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
+ + "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>"
+ + "<compression xmlns=\"http://jabber.org/features/compress\">"
+ + "<method>zlib</method>"
+ + "<method>lzw</method>"
+ + "</compression>"
+ + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ + "<mechanism>DIGEST-MD5</mechanism>"
+ + "<mechanism>PLAIN</mechanism>"
+ + "</mechanisms>"
+ + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"
+ + "<sm xmlns='urn:xmpp:sm:2'/>"
+ + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
+ + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>"
+ + "</stream:features>"));
+
+ StreamFeatures element = (StreamFeatures)(testling.getElement());
+ assertTrue(element.hasStartTLS());
+ assertTrue(element.hasSession());
+ assertTrue(element.hasResourceBind());
+ assertTrue(element.hasCompressionMethod("zlib"));
+ assertTrue(element.hasCompressionMethod("lzw"));
+ assertTrue(element.hasAuthenticationMechanisms());
+ assertTrue(element.hasAuthenticationMechanism("DIGEST-MD5"));
+ assertTrue(element.hasAuthenticationMechanism("PLAIN"));
+ assertNull(element.getAuthenticationHostname());
+ assertTrue(element.hasStreamManagement());
+ assertTrue(element.hasRosterVersioning());
+ }
+
+ @Test
+ public void testParse_Empty() {
+ StreamFeaturesParser testling = new StreamFeaturesParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse("<stream:features xmlns:stream='http://etherx.jabber.org/streams'/>"));
+
+ StreamFeatures element = (StreamFeatures)(testling.getElement());
+ assertFalse(element.hasStartTLS());
+ assertFalse(element.hasSession());
+ assertFalse(element.hasResourceBind());
+ assertFalse(element.hasAuthenticationMechanisms());
+ }
+
+
+ @Test
+ public void testParse_AuthenticationHostname() {
+ StreamFeaturesParser testling = new StreamFeaturesParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+ String hostname = "auth42.us.example.com";
+
+ assertTrue(parser.parse(
+ "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
+ + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ + "<mechanism>GSSAPI</mechanism>"
+ + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\">auth42.us.example.com</hostname>"
+ + "</mechanisms>"
+ + "</stream:features>"));
+
+ StreamFeatures element = (StreamFeatures)(testling.getElement());
+ assertTrue(element.hasAuthenticationMechanism("GSSAPI"));
+ assertEquals(element.getAuthenticationHostname(), hostname);
+ }
+
+
+ @Test
+ public void testParse_AuthenticationHostnameEmpty() {
+ StreamFeaturesParser testling = new StreamFeaturesParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse(
+ "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
+ + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ + "<mechanism>GSSAPI</mechanism>"
+ + "<hostname xmlns=\"urn:xmpp:domain-based-name:1\"></hostname>"
+ + "</mechanisms>"
+ + "</stream:features>"));
+
+ StreamFeatures element = (StreamFeatures)(testling.getElement());
+ assertTrue(element.hasAuthenticationMechanism("GSSAPI"));
+ assertTrue(element.getAuthenticationHostname().isEmpty());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java b/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java
new file mode 100644
index 0000000..1ec3d30
--- /dev/null
+++ b/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013 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;
+
+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.parser.StreamManagementEnabledParser;
+import com.isode.stroke.elements.StreamManagementEnabled;
+import com.isode.stroke.parser.ElementParserTester;
+
+public class StreamManagementEnabledParserTest {
+
+ public StreamManagementEnabledParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ StreamManagementEnabledParser testling = new StreamManagementEnabledParser();
+ ElementParserTester parser = new ElementParserTester(testling);
+
+ assertTrue(parser.parse(
+ "<enabled xmlns=\"urn:xmpp:sm:3\" id=\"some-long-sm-id\" resume=\"true\"/>"));
+
+ StreamManagementEnabled element = (StreamManagementEnabled)(testling.getElement());
+ assertTrue(element.getResumeSupported());
+ assertEquals("some-long-sm-id", element.getResumeID());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java b/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java
new file mode 100644
index 0000000..12c67ac
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.Body;
+import com.isode.stroke.parser.payloadparsers.BodyParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class BodyParserTest {
+
+ public BodyParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+
+ assertNotNull(parser.parse("<body>foo<baz>bar</baz>fum</body>"));
+
+ Body payload = (Body)(parser.getPayload());
+ assertEquals("foobarfum", payload.getText());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java b/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java
new file mode 100644
index 0000000..d903b3b
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java
@@ -0,0 +1,47 @@
+/*
+ * 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 com.isode.stroke.parser.XMLParser;
+import com.isode.stroke.eventloop.EventLoop;
+import com.isode.stroke.parser.XMLParserClient;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.PayloadParser;
+import com.isode.stroke.parser.PlatformXMLParserFactory;
+
+public class PayloadParserTester<ParserType extends PayloadParser> implements XMLParserClient {
+
+ private XMLParser xmlParser_;
+ private ParserType parser_;
+
+ public PayloadParserTester(ParserType parser) {
+ this.parser_ = parser;
+ xmlParser_ = PlatformXMLParserFactory.createXMLParser(this);
+ }
+
+ public boolean parse(String data) {
+ return xmlParser_.parse(data);
+ }
+
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ parser_.handleStartElement(element, ns, attributes);
+ }
+
+ public void handleEndElement(String element, String ns) {
+ parser_.handleEndElement(element, ns);
+ }
+
+ public void handleCharacterData(String data) {
+ parser_.handleCharacterData(data);
+ }
+}
+
diff --git a/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java b/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java
new file mode 100644
index 0000000..004f68f
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.PrivateStorage;
+import com.isode.stroke.elements.Storage;
+import com.isode.stroke.parser.payloadparsers.PrivateStorageParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.parser.payloadparsers.PayloadParserTester;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+
+public class PrivateStorageParserTest {
+
+ public PrivateStorageParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+
+ assertNotNull(parser.parse(
+ "<query xmlns='jabber:iq:private'>"
+ + "<storage xmlns='storage:bookmarks'>"
+ + "<conference name='Swift' jid='swift@rooms.swift.im'>"
+ + "<nick>Alice</nick>"
+ + "</conference>"
+ + "</storage>"
+ + "</query>"));
+
+ PrivateStorage payload = (PrivateStorage)(parser.getPayload());
+ assertNotNull(payload);
+ Storage storage = (Storage)(payload.getPayload());
+ assertNotNull(storage);
+ assertEquals("Alice", storage.getRooms().get(0).nick);
+ assertEquals(new JID("swift@rooms.swift.im"), storage.getRooms().get(0).jid);
+ }
+
+ @Test
+ public void testParse_NoPayload() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+
+ assertNotNull(parser.parse("<query xmlns='jabber:iq:private'/>"));
+
+ PrivateStorage payload = (PrivateStorage)(parser.getPayload());
+ assertNotNull(payload);
+ assertNull(payload.getPayload());
+ }
+
+ @Test
+ public void testParse_MultiplePayloads() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+
+ assertNotNull(parser.parse(
+ "<query xmlns='jabber:iq:private'>"
+ + "<storage xmlns='storage:bookmarks'>"
+ + "<conference name='Swift' jid='swift@rooms.swift.im'>"
+ + "<nick>Alice</nick>"
+ + "</conference>"
+ + "</storage>"
+ + "<storage xmlns='storage:bookmarks'>"
+ + "<conference name='Swift' jid='swift@rooms.swift.im'>"
+ + "<nick>Rabbit</nick>"
+ + "</conference>"
+ + "</storage>"
+ + "</query>"));
+
+ PrivateStorage payload = (PrivateStorage)(parser.getPayload());
+ assertNotNull(payload);
+ Storage storage = (Storage)(payload.getPayload());
+ assertNotNull(storage);
+ assertEquals("Rabbit", storage.getRooms().get(0).nick);
+ }
+
+ @Test
+ public void testParse_UnsupportedPayload() {
+ PayloadParserFactoryCollection factories = new PayloadParserFactoryCollection();
+ PrivateStorageParser testling = new PrivateStorageParser(factories);
+ PayloadParserTester parser = new PayloadParserTester(testling);
+
+ assertNotNull(parser.parse(
+ "<query xmlns='jabber:iq:private'>" +
+ "<foo>Bar</foo>" +
+ "</query>"));
+
+ assertNull(((PrivateStorage)(testling.getPayload())).getPayload());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java
new file mode 100644
index 0000000..e416066
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.assertTrue;
+import org.junit.Test;
+import com.isode.stroke.elements.RawXMLPayload;
+import com.isode.stroke.parser.payloadparsers.RawXMLPayloadParser;
+import com.isode.stroke.parser.payloadparsers.PayloadParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class RawXMLPayloadParserTest {
+
+ public RawXMLPayloadParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ RawXMLPayloadParser testling = new RawXMLPayloadParser();
+ PayloadParserTester parser = new PayloadParserTester(testling);
+
+ String xml =
+ "<foo foo-attr=\"foo-val\" xmlns=\"ns:foo\">"
+ + "<bar bar-attr=\"bar-val\" xmlns=\"ns:bar\"/>"
+ + "<baz baz-attr=\"baz-val\" xmlns=\"ns:baz\"/>"
+ + "</foo>";
+ assertTrue(parser.parse(xml));
+
+ RawXMLPayload payload = (RawXMLPayload)(testling.getPayload());
+ assertNotNull(xml, payload.getRawXML());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java b/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java
new file mode 100644
index 0000000..d9e254c
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2010-2012 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.assertTrue;
+import org.junit.Test;
+import com.isode.stroke.elements.Storage;
+import com.isode.stroke.parser.payloadparsers.StorageParser;
+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 StorageParserTest {
+
+ public StorageParserTest() {
+
+ }
+
+ @Test
+ public void testParse_Room() {
+ DummyEventLoop eventloop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventloop);
+
+ assertNotNull(parser.parse(
+ "<storage xmlns='storage:bookmarks'>"
+ + "<conference "
+ + "name='Council of Oberon' "
+ + "autojoin='true' jid='council@conference.underhill.org'>"
+ + "<nick>Puck</nick>"
+ + "<password>MyPass</password>"
+ + "</conference>"
+ + "</storage>"));
+
+ Storage payload = (Storage)(parser.getPayload());
+ Vector<Storage.Room> rooms = payload.getRooms();
+ assertEquals(1, rooms.size());
+ assertEquals("Council of Oberon", rooms.get(0).name);
+ assertEquals(new JID("council@conference.underhill.org"), rooms.get(0).jid);
+ assertTrue(rooms.get(0).autoJoin);
+ assertEquals("Puck", rooms.get(0).nick);
+ assertEquals("MyPass", rooms.get(0).password);
+ }
+
+ @Test
+ public void testParse_MultipleRooms() {
+ DummyEventLoop eventloop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventloop);
+
+ assertNotNull(parser.parse(
+ "<storage xmlns='storage:bookmarks'>"
+ + "<conference "
+ + "name='Council of Oberon' "
+ + "jid='council@conference.underhill.org' />"
+ + "<conference "
+ + "name='Tea &amp; jam party' "
+ + "jid='teaparty@wonderland.lit' />"
+ + "</storage>"));
+
+ Storage payload = (Storage)(parser.getPayload());
+ Vector<Storage.Room> rooms = payload.getRooms();
+ assertEquals(2, rooms.size());
+ assertEquals("Council of Oberon", rooms.get(0).name);
+ assertEquals(new JID("council@conference.underhill.org"), rooms.get(0).jid);
+ assertEquals("Tea & jam party", rooms.get(1).name);
+ assertEquals(new JID("teaparty@wonderland.lit"), rooms.get(1).jid);
+ }
+
+ @Test
+ public void testParse_URL() {
+ DummyEventLoop eventloop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventloop);
+
+ assertNotNull(parser.parse(
+ "<storage xmlns='storage:bookmarks'>"
+ + "<url name='Complete Works of Shakespeare' url='http://the-tech.mit.edu/Shakespeare/'/>"
+ + "</storage>"));
+
+ Storage payload = (Storage)(parser.getPayload());
+ Vector<Storage.URL> urls = payload.getURLs();
+ assertEquals(1, urls.size());
+ assertEquals("Complete Works of Shakespeare", urls.get(0).name);
+ assertEquals("http://the-tech.mit.edu/Shakespeare/", urls.get(0).url);
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java b/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java
new file mode 100644
index 0000000..44ed1b8
--- /dev/null
+++ b/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.AuthChallengeSerializer;
+import com.isode.stroke.elements.AuthChallenge;
+import com.isode.stroke.base.ByteArray;
+
+public class AuthChallengeSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public AuthChallengeSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ AuthChallengeSerializer testling = new AuthChallengeSerializer();
+ AuthChallenge authChallenge = new AuthChallenge();
+ authChallenge.setValue(new ByteArray("foo"));
+
+ assertEquals(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "Zm9v" +
+ "</challenge>", testling.serialize(authChallenge));
+ }
+
+ @Test
+ public void testSerialize_NoMessage() {
+ AuthChallengeSerializer testling = new AuthChallengeSerializer();
+ AuthChallenge authChallenge = new AuthChallenge();
+
+ assertEquals(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"></challenge>", testling.serialize(authChallenge));
+ }
+
+ @Test
+ public void testSerialize_EmptyMessage() {
+ AuthChallengeSerializer testling = new AuthChallengeSerializer();
+ AuthChallenge authChallenge = new AuthChallenge();
+ authChallenge.setValue(new ByteArray());
+
+ assertEquals(
+ "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "=" +
+ "</challenge>", testling.serialize(authChallenge));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java b/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java
new file mode 100644
index 0000000..eae4354
--- /dev/null
+++ b/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.AuthRequestSerializer;
+import com.isode.stroke.elements.AuthRequest;
+import com.isode.stroke.base.ByteArray;
+
+public class AuthRequestSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public AuthRequestSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ AuthRequestSerializer testling = new AuthRequestSerializer();
+ AuthRequest authRequest = new AuthRequest("PLAIN");
+ authRequest.setMessage(new ByteArray("foo"));
+
+ assertEquals(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">" +
+ "Zm9v" +
+ "</auth>", testling.serialize(authRequest));
+ }
+
+ @Test
+ public void testSerialize_NoMessage() {
+ AuthRequestSerializer testling = new AuthRequestSerializer();
+ AuthRequest authRequest = new AuthRequest("PLAIN");
+
+ assertEquals(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">" +
+ "</auth>", testling.serialize(authRequest));
+ }
+
+ @Test
+ public void testSerialize_EmptyMessage() {
+ AuthRequestSerializer testling = new AuthRequestSerializer();
+ AuthRequest authRequest = new AuthRequest("PLAIN");
+ authRequest.setMessage(new ByteArray());
+
+ assertEquals(
+ "<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">" +
+ "=" +
+ "</auth>", testling.serialize(authRequest));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java b/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java
new file mode 100644
index 0000000..9b0fe71
--- /dev/null
+++ b/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.AuthResponseSerializer;
+import com.isode.stroke.elements.AuthResponse;
+import com.isode.stroke.base.ByteArray;
+
+public class AuthResponseSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public AuthResponseSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ AuthResponseSerializer testling = new AuthResponseSerializer();
+ AuthResponse authResponse = new AuthResponse();
+ authResponse.setValue(new ByteArray("foo"));
+
+ assertEquals(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "Zm9v" +
+ "</response>", testling.serialize(authResponse));
+ }
+
+ @Test
+ public void testSerialize_NoMessage() {
+ AuthResponseSerializer testling = new AuthResponseSerializer();
+ AuthResponse authResponse = new AuthResponse();
+
+ assertEquals(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "</response>", testling.serialize(authResponse));
+ }
+
+ @Test
+ public void testSerialize_EmptyMessage() {
+ AuthResponseSerializer testling = new AuthResponseSerializer();
+ AuthResponse authResponse = new AuthResponse();
+ authResponse.setValue(new ByteArray());
+
+ assertEquals(
+ "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "" +
+ "</response>", testling.serialize(authResponse));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java b/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java
new file mode 100644
index 0000000..ee9b595
--- /dev/null
+++ b/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.AuthSuccessSerializer;
+import com.isode.stroke.elements.AuthSuccess;
+import com.isode.stroke.base.ByteArray;
+
+public class AuthSuccessSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public AuthSuccessSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ AuthSuccessSerializer testling = new AuthSuccessSerializer();
+ AuthSuccess authSuccess = new AuthSuccess();
+ authSuccess.setValue(new ByteArray("foo"));
+
+ assertEquals(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "Zm9v" +
+ "</success>", testling.serialize(authSuccess));
+ }
+
+ @Test
+ public void testSerialize_NoMessage() {
+ AuthSuccessSerializer testling = new AuthSuccessSerializer();
+ AuthSuccess authSuccess = new AuthSuccess();
+
+ assertEquals(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "</success>", testling.serialize(authSuccess));
+ }
+
+ @Test
+ public void testSerialize_EmptyMessage() {
+ AuthSuccessSerializer testling = new AuthSuccessSerializer();
+ AuthSuccess authSuccess = new AuthSuccess();
+ authSuccess.setValue(new ByteArray());
+
+ assertEquals(
+ "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" +
+ "=" +
+ "</success>", testling.serialize(authSuccess));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java b/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java
new file mode 100644
index 0000000..67d9bb0
--- /dev/null
+++ b/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.StreamFeaturesSerializer;
+import com.isode.stroke.elements.StreamFeatures;
+
+public class StreamFeaturesSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public StreamFeaturesSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ StreamFeaturesSerializer testling = new StreamFeaturesSerializer();
+ StreamFeatures streamFeatures = new StreamFeatures();
+ streamFeatures.setHasStartTLS();
+ streamFeatures.addCompressionMethod("zlib");
+ streamFeatures.addCompressionMethod("lzw");
+ streamFeatures.addAuthenticationMechanism("DIGEST-MD5");
+ streamFeatures.addAuthenticationMechanism("PLAIN");
+ streamFeatures.setHasResourceBind();
+ streamFeatures.setHasSession();
+ streamFeatures.setHasStreamManagement();
+ streamFeatures.setHasRosterVersioning();
+
+ assertEquals(
+ "<stream:features>"
+ + "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>"
+ + "<compression xmlns=\"http://jabber.org/features/compress\">"
+ + "<method>zlib</method>"
+ + "<method>lzw</method>"
+ + "</compression>"
+ + "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
+ + "<mechanism>DIGEST-MD5</mechanism>"
+ + "<mechanism>PLAIN</mechanism>"
+ + "</mechanisms>"
+ + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"
+ + "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>"
+ + "<sm xmlns=\"urn:xmpp:sm:2\"/>"
+ + "<ver xmlns=\"urn:xmpp:features:rosterver\"/>"
+ + "</stream:features>", testling.serialize(streamFeatures));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java
new file mode 100644
index 0000000..42b9904
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010-2012 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.junit.BeforeClass;
+import com.isode.stroke.serializer.payloadserializers.ErrorSerializer;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.elements.ErrorPayload;
+import com.isode.stroke.elements.Delay;
+
+public class ErrorSerializerTest {
+
+ @BeforeClass
+ public static void init() throws Exception {
+ }
+
+ private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection();
+
+ /**
+ * Default Constructor.
+ */
+ public ErrorSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ ErrorSerializer testling = new ErrorSerializer(serializers);
+ ErrorPayload error = new ErrorPayload(ErrorPayload.Condition.BadRequest, ErrorPayload.Type.Cancel, "My Error");
+
+ assertEquals("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>", testling.serialize(error));
+ }
+
+ @Test
+ public void testSerialize_Payload() {
+ ErrorSerializer testling = new ErrorSerializer(serializers);
+ ErrorPayload error = new ErrorPayload();
+ error.setPayload(new Delay());
+
+ assertEquals(
+ "<error type=\"cancel\"><undefined-condition xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><delay xmlns=\"urn:xmpp:delay\"/></error>"
+ , testling.serialize(error));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java
new file mode 100644
index 0000000..ca9c5a8
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleFileTransferDescriptionSerializer;
+import com.isode.stroke.serializer.payloadserializers.StreamInitiationFileInfoSerializer;
+import com.isode.stroke.serializer.payloadserializers.JinglePayloadSerializer;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.StreamInitiationFileInfo;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.stringcodecs.Base64;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.network.HostAddress;
+import com.isode.stroke.network.HostAddressPort;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleSerializersTest {
+
+ private FullPayloadSerializerCollection collection = new FullPayloadSerializerCollection();
+
+ /**
+ * Default Constructor.
+ */
+ public JingleSerializersTest() {
+
+ }
+
+ public JinglePayloadSerializer createTestling() {
+ return new JinglePayloadSerializer(collection);
+ }
+
+ @Test
+ public void testSerialize_StreamInitiationFileInfo() {
+ String expected = "<file date=\"1969-07-21T02:56:15Z\" hash=\"552da749930852c69ae5d2141d3766b1\" name=\"test.txt\" size=\"1022\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\"><desc>This is a test. If this were a real file...</desc><range/></file>";
+
+ StreamInitiationFileInfo fileInfo = new StreamInitiationFileInfo();
+ fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z"));
+ fileInfo.setHash("552da749930852c69ae5d2141d3766b1");
+ fileInfo.setSize(1022);
+ fileInfo.setName("test.txt");
+ fileInfo.setDescription("This is a test. If this were a real file...");
+ fileInfo.setSupportsRangeRequests(true);
+
+ StreamInitiationFileInfoSerializer serializer = new StreamInitiationFileInfoSerializer();
+ assertEquals(expected, serializer.serializePayload(fileInfo));
+ }
+
+
+ @Test
+ public void testSerialize_StreamInitiationFileInfoRange() {
+ String expected = "<file hash=\"552da749930852c69ae5d2141d3766b1\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\"><range offset=\"270336\"/></file>";
+
+ StreamInitiationFileInfo fileInfo = new StreamInitiationFileInfo();
+ fileInfo.setHash("552da749930852c69ae5d2141d3766b1");
+ fileInfo.setSupportsRangeRequests(true);
+ fileInfo.setRangeOffset(270336);
+
+ StreamInitiationFileInfoSerializer serializer = new StreamInitiationFileInfoSerializer();
+ assertEquals(expected, serializer.serializePayload(fileInfo));
+ }
+
+
+ // IBB Transport Method Examples
+
+ // http://xmpp.org/extensions/xep-0261.html#example-1
+ @Test
+ public void testSerialize_Xep0261_Example1() {
+ String expected = "<jingle action=\"session-initiate\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><content creator=\"initiator\" name=\"ex\"><transport block-size=\"4096\" sid=\"ch3d9s71\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/></content></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.SessionInitiate);
+ payload.setSessionID("a73sjjvkla37jfea");
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+
+ JingleIBBTransportPayload transport = new JingleIBBTransportPayload();
+ transport.setBlockSize(4096);
+ transport.setSessionID("ch3d9s71");
+
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("ex");
+ content.addTransport(transport);
+
+ payload.addPayload(content);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-9
+ @Test
+ public void testSerialize_Xep0261_Example9() {
+ String expected = "<jingle action=\"transport-info\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><content creator=\"initiator\" name=\"ex\"><transport block-size=\"2048\" sid=\"bt8a71h6\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/></content></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.TransportInfo);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("a73sjjvkla37jfea");
+
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("ex");
+
+ JingleIBBTransportPayload transport = new JingleIBBTransportPayload();
+ transport.setBlockSize(2048);
+ transport.setSessionID("bt8a71h6");
+
+ content.addTransport(transport);
+ payload.addPayload(content);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-13
+ @Test
+ public void testSerialize_Xep0261_Example13() {
+ String expected = "<jingle action=\"session-terminate\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><reason><success/></reason></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.SessionTerminate);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("a73sjjvkla37jfea");
+ payload.setReason(new JinglePayload.Reason(JinglePayload.Reason.Type.Success));
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-1
+ @Test
+ public void testSerialize_Xep0234_Example1() {
+ String expected = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>1969-07-21T02:56:15Z</date><desc>This is a test. If this were a real file...</desc><name>test.txt</name><range/><size>1022</size><hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash></file></description>";
+
+ JingleFileTransferDescription desc = new JingleFileTransferDescription();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+
+ fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z"));
+ fileInfo.addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ==")));
+ fileInfo.setSize(1022);
+ fileInfo.setName("test.txt");
+ fileInfo.setDescription("This is a test. If this were a real file...");
+ fileInfo.setSupportsRangeRequests(true);
+
+ desc.setFileInfo(fileInfo);
+
+ assertEquals(expected, new JingleFileTransferDescriptionSerializer().serialize(desc));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-3
+ @Test
+ public void testSerialize_Xep0234_Example3() {
+ String expected = "<jingle action=\"session-accept\" initiator=\"romeo@montague.lit/orchard\" sid=\"851ba2\" xmlns=\"urn:xmpp:jingle:1\"><content creator=\"initiator\" name=\"a-file-offer\"><description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>1969-07-21T02:56:15Z</date><desc>This is a test. If this were a real file...</desc><name>test.txt</name><range/><size>1022</size><hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash></file></description></content></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.SessionAccept);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("851ba2");
+
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("a-file-offer");
+
+ JingleFileTransferDescription description = new JingleFileTransferDescription();
+ JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo();
+ fileInfo.setName("test.txt");
+ fileInfo.setSize(1022);
+ fileInfo.addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ==")));
+ fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z"));
+ fileInfo.setDescription("This is a test. If this were a real file...");
+ fileInfo.setSupportsRangeRequests(true);
+
+ description.setFileInfo(fileInfo);
+ content.addDescription(description);
+ payload.addPayload(content);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-5
+ @Test
+ public void testSerialize_Xep0234_Example5() {
+ String expected = "<jingle action=\"transport-info\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><content creator=\"initiator\" name=\"ex\"/></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.TransportInfo);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("a73sjjvkla37jfea");
+
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("ex");
+ payload.addPayload(content);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-8
+ @Test
+ public void testSerialize_Xep0234_Example8() {
+ String expected = "<jingle action=\"session-info\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash></file></checksum></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.SessionInfo);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("a73sjjvkla37jfea");
+
+ JingleFileTransferHash hash = new JingleFileTransferHash();
+ hash.getFileInfo().addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ==")));
+
+ payload.addPayload(hash);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+
+ // http://xmpp.org/extensions/xep-0260.html#example-1
+ @Test
+ public void testSerialize_Xep0260_Example1() {
+ String expected = "<jingle action=\"session-initiate\" initiator=\"romeo@montague.lit/orchard\" sid=\"a73sjjvkla37jfea\" xmlns=\"urn:xmpp:jingle:1\"><content creator=\"initiator\" name=\"ex\"><transport dstaddr=\"1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba\" mode=\"tcp\" sid=\"vj3hs98y\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\"><candidate cid=\"hft54dqy\" host=\"192.168.4.1\" jid=\"romeo@montague.lit/orchard\" port=\"5086\" priority=\"8257636\" type=\"direct\"/><candidate cid=\"hutr46fe\" host=\"24.24.24.1\" jid=\"romeo@montague.lit/orchard\" port=\"5087\" priority=\"8258636\" type=\"direct\"/></transport></content></jingle>";
+
+ JinglePayload payload = new JinglePayload();
+ payload.setAction(JinglePayload.Action.SessionInitiate);
+ payload.setInitiator(new JID("romeo@montague.lit/orchard"));
+ payload.setSessionID("a73sjjvkla37jfea");
+
+ JingleContentPayload content = new JingleContentPayload();
+ content.setCreator(JingleContentPayload.Creator.InitiatorCreator);
+ content.setName("ex");
+
+ JingleS5BTransportPayload transport = new JingleS5BTransportPayload();
+ transport.setMode(JingleS5BTransportPayload.Mode.TCPMode);
+ transport.setDstAddr("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba");
+ transport.setSessionID("vj3hs98y");
+
+ JingleS5BTransportPayload.Candidate candidate1 = new JingleS5BTransportPayload.Candidate();
+ candidate1.cid = "hft54dqy";
+ try {
+ candidate1.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("192.168.4.1")), 5086);
+ } catch (UnknownHostException e) {
+
+ }
+ candidate1.jid = new JID("romeo@montague.lit/orchard");
+ candidate1.priority = 8257636;
+ candidate1.type = JingleS5BTransportPayload.Candidate.Type.DirectType;
+ transport.addCandidate(candidate1);
+
+ JingleS5BTransportPayload.Candidate candidate2 = new JingleS5BTransportPayload.Candidate();
+ candidate2.cid = "hutr46fe";
+ try {
+ candidate2.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("24.24.24.1")), 5087);
+ } catch (UnknownHostException e) {
+
+ }
+ candidate2.jid = new JID("romeo@montague.lit/orchard");
+ candidate2.priority = 8258636;
+ candidate2.type = JingleS5BTransportPayload.Candidate.Type.DirectType;
+ transport.addCandidate(candidate2);
+
+ content.addTransport(transport);
+
+ payload.addPayload(content);
+
+ assertEquals(expected, createTestling().serialize(payload));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java b/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java
new file mode 100644
index 0000000..2008373
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java
@@ -0,0 +1,32 @@
+/*
+ * 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.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.serializer.PayloadSerializer;
+import com.isode.stroke.elements.Payload;
+
+public class PayloadsSerializer {
+
+ private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection();
+
+ public String serialize(Payload payload) {
+ PayloadSerializer serializer = serializers.getPayloadSerializer(payload);
+ if (serializer != null) {
+ return serializer.serialize(payload);
+ }
+ else {
+ assert(false);
+ return "";
+ }
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java
new file mode 100644
index 0000000..9ef2762
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.PayloadsSerializer;
+import com.isode.stroke.elements.PrivateStorage;
+import com.isode.stroke.elements.Storage;
+import com.isode.stroke.jid.JID;
+
+public class PrivateStorageSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public PrivateStorageSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ PayloadsSerializer serializer = new PayloadsSerializer();
+
+ PrivateStorage privateStorage = new PrivateStorage();
+ Storage storage = new Storage();
+ Storage.Room room = new Storage.Room();
+ room.name = "Swift";
+ room.jid = new JID("swift@rooms.swift.im");
+ room.nick = "Alice";
+ storage.addRoom(room);
+ privateStorage.setPayload(storage);
+
+ assertEquals(
+ "<query xmlns=\"jabber:iq:private\">"
+ + "<storage xmlns=\"storage:bookmarks\">"
+ + "<conference "
+ + "autojoin=\"0\" "
+ + "jid=\"swift@rooms.swift.im\" "
+ + "name=\"Swift\">"
+ + "<nick>Alice</nick>"
+ + "</conference>"
+ + "</storage>"
+ + "</query>", serializer.serialize(privateStorage));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java
new file mode 100644
index 0000000..af19175
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.PubSubItemSerializer;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.PubSubItem;
+import com.isode.stroke.elements.RawXMLPayload;
+
+public class PubSubItemSerializerTest {
+
+ private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection();
+
+ /**
+ * Default Constructor.
+ */
+ public PubSubItemSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ PubSubItemSerializer serializer = new PubSubItemSerializer(serializers);
+
+ RawXMLPayload payload = new RawXMLPayload();
+ payload.setRawXML("<payload xmlns=\"tmp\"/>");
+
+ PubSubItem item = new PubSubItem();
+ item.addData(payload);
+ item.setID("pubsub-item-1");
+
+ String expectedResult =
+ "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ + "<payload xmlns=\"tmp\"/>"
+ + "</item>";
+
+ assertEquals(expectedResult, serializer.serialize(item));
+ }
+
+ @Test
+ public void testSerializeEmptyID() {
+ PubSubItemSerializer serializer = new PubSubItemSerializer(serializers);
+
+ PubSubItem item = new PubSubItem();
+
+ String expectedResult =
+ "<item xmlns=\"http://jabber.org/protocol/pubsub\"/>";
+
+ assertEquals(expectedResult, serializer.serialize(item));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java
new file mode 100644
index 0000000..9745dac
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2014 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.PubSubItemsSerializer;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.PubSubItem;
+import com.isode.stroke.elements.PubSubItems;
+import com.isode.stroke.elements.RawXMLPayload;
+
+public class PubSubItemsSerializerTest {
+
+ private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection();
+
+ /**
+ * Default Constructor.
+ */
+ public PubSubItemsSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ PubSubItemsSerializer serializer = new PubSubItemsSerializer(serializers);
+
+ RawXMLPayload payload1 = new RawXMLPayload();
+ payload1.setRawXML("<payload xmlns=\"tmp\"/>");
+
+ PubSubItem item1 = new PubSubItem();
+ item1.addData(payload1);
+ item1.setID("pubsub-item-1");
+
+ RawXMLPayload payload2 = new RawXMLPayload();
+ payload2.setRawXML("<payload xmlns=\"other-tmp\"/>");
+
+ PubSubItem item2 = new PubSubItem();
+ item2.addData(payload2);
+ item2.setID("pubsub-item-2");
+
+ PubSubItems items = new PubSubItems();
+ items.setNode("test-node");
+ items.setSubscriptionID("sub-id");
+ items.addItem(item1);
+ items.addItem(item2);
+
+ String expectedResult =
+ "<items node=\"test-node\" subid=\"sub-id\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ + "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ + "<payload xmlns=\"tmp\"/>"
+ + "</item>"
+ + "<item id=\"pubsub-item-2\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ + "<payload xmlns=\"other-tmp\"/>"
+ + "</item>"
+ + "</items>";
+
+ assertEquals(expectedResult, serializer.serialize(items));
+ }
+
+ @Test
+ public void testSerializeEmptyItems() {
+ PubSubItemsSerializer serializer = new PubSubItemsSerializer(serializers);
+
+ PubSubItems items = new PubSubItems();
+
+ // Swiften code doesn't check for node being null in serializer and therefore will have extra node=\"\",
+ // BUT since it is being check in serializer here, there will be no node.
+ String expectedResult =
+ "<items xmlns=\"http://jabber.org/protocol/pubsub\"/>";
+
+ assertEquals(expectedResult, serializer.serialize(items));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java
new file mode 100644
index 0000000..036b366
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.PayloadsSerializer;
+import com.isode.stroke.elements.Storage;
+import com.isode.stroke.jid.JID;
+
+public class StorageSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public StorageSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize() {
+ PayloadsSerializer serializer = new PayloadsSerializer();
+ Storage storage = new Storage();
+ Storage.Room room = new Storage.Room();
+ room.name = "Council of Oberon";
+ room.autoJoin = true;
+ room.jid = new JID("council@conference.underhill.org");
+ room.nick = "Puck";
+ room.password = "MyPass";
+ storage.addRoom(room);
+ Storage.URL url = new Storage.URL();
+ url.name = "Complete Works of Shakespeare";
+ url.url = "http://the-tech.mit.edu/Shakespeare/";
+ storage.addURL(url);
+
+ assertEquals(
+ "<storage xmlns=\"storage:bookmarks\">"
+ + "<conference "
+ + "autojoin=\"1\" "
+ + "jid=\"council@conference.underhill.org\" "
+ + "name=\"Council of Oberon\">"
+ + "<nick>Puck</nick>"
+ + "<password>MyPass</password>"
+ + "</conference>"
+ + "<url name=\"Complete Works of Shakespeare\" url=\"http://the-tech.mit.edu/Shakespeare/\"/>"
+ + "</storage>", serializer.serialize(storage));
+ }
+
+ @Test
+ public void testSerialize_NoNickOrPassword() {
+ PayloadsSerializer serializer = new PayloadsSerializer();
+ Storage storage = new Storage();
+ Storage.Room room = new Storage.Room();
+ room.name = "Council of Oberon";
+ room.autoJoin = true;
+ room.jid = new JID("council@conference.underhill.org");
+ storage.addRoom(room);
+
+ assertEquals(
+ "<storage xmlns=\"storage:bookmarks\">"
+ + "<conference "
+ + "autojoin=\"1\" "
+ + "jid=\"council@conference.underhill.org\" "
+ + "name=\"Council of Oberon\"/>"
+ + "</storage>", serializer.serialize(storage));
+ }
+} \ No newline at end of file