summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-02-25 11:33:49 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-02-29 12:28:57 (GMT)
commit191f768446f89a766b4f5c43ba9098c63c590032 (patch)
treee1a2d9bf96d590829ece8ac089eb8126dbb3672f
parentd636d68c84229c82ff746c7697d2014ff4dd4477 (diff)
downloadstroke-191f768446f89a766b4f5c43ba9098c63c590032.zip
stroke-191f768446f89a766b4f5c43ba9098c63c590032.tar.bz2
Add Parser and Serializer classes
Add classes to the parser and serializer packages, including some tests. Update PortingProgress with info on the classes that could not be imported in this patch. Test-information: Unit tests pass ok. Change-Id: If42af9c0cecb68151cf817f1839b86b4d7c8967c
-rw-r--r--PortingProgress.txt6
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java48
-rw-r--r--test/com/isode/stroke/serializer/XMPPSerializerTest.java80
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java34
4 files changed, 166 insertions, 2 deletions
diff --git a/PortingProgress.txt b/PortingProgress.txt
index 7a8a986..c2844e6 100644
--- a/PortingProgress.txt
+++ b/PortingProgress.txt
@@ -155,7 +155,9 @@ Parser:
All files ported to 6ca201d0b48f4273e24dd7bff17c4a46eeaddf39 except for:
-ExpatParser, IdleParserTest, LibXMLParser, WhiteboardParser -- Not Yet Ported!
+ExpatParser -- Not yet ported. Requires expact library.
+LibXMLParser -- Not yet ported. Requires libxml library.
+WhiteboardParser -- Not Yet Ported! Needs Whiteboard classes importing.
-----
Presence:
@@ -192,7 +194,7 @@ Serializer:
All files ported to 6ca201d0b48f4273e24dd7bff17c4a46eeaddf39 except for:
-WhiteboardSerializer, XMPPSerializerTest, IdleSerializerTest -- Not Yet Ported!
+WhiteboardSerializer -- Not Yet Ported! Needs whiteboard classes importing.
-----
Session:
diff --git a/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java b/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java
new file mode 100644
index 0000000..cf7df32
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java
@@ -0,0 +1,48 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.elements.Idle;
+import com.isode.stroke.elements.Presence;
+import com.isode.stroke.parser.PresenceParser;
+import com.isode.stroke.parser.StanzaParserTester;
+
+/**
+ * Test for {@link IdleParser}
+ */
+public class IdleParserTest {
+
+ @Test
+ public void testParse_XepWhatever_Example1() {
+ PresenceParser testling = new PresenceParser(new FullPayloadParserFactoryCollection());
+ StanzaParserTester<PresenceParser> parser = new StanzaParserTester<PresenceParser>(testling);
+ assertTrue(parser.parse(
+ "<presence from='juliet@capulet.com/balcony'>\n"
+ +"<show>away</show>\n"
+ +"<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n"
+ +"</presence>\n"
+ ));
+
+ Presence presence = testling.getStanzaGeneric();
+ assertNotNull(presence);
+
+ Idle idle = presence.getPayload(new Idle());
+ assertNotNull(idle);
+ assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"),idle.getSince());
+ }
+
+}
diff --git a/test/com/isode/stroke/serializer/XMPPSerializerTest.java b/test/com/isode/stroke/serializer/XMPPSerializerTest.java
new file mode 100644
index 0000000..1c86034
--- /dev/null
+++ b/test/com/isode/stroke/serializer/XMPPSerializerTest.java
@@ -0,0 +1,80 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.serializer;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.isode.stroke.elements.ProtocolHeader;
+import com.isode.stroke.elements.StreamType;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+
+/**
+ *
+ */
+public class XMPPSerializerTest {
+
+ private final PayloadSerializerCollection payloadSerializerCollection =
+ new FullPayloadSerializerCollection();
+
+ @Test
+ public void testSerializeHeader_Client() {
+ XMPPSerializer testling = createSerializer(StreamType.ClientStreamType);
+ ProtocolHeader protocolHeader = new ProtocolHeader();
+ protocolHeader.setFrom("bla@foo.com");
+ protocolHeader.setTo("foo.com");
+ protocolHeader.setID("myid");
+ protocolHeader.setVersion("0.99");
+
+ assertEquals("<?xml version=\"1.0\"?>"
+ + "<stream:stream xmlns=\"jabber:client\" "
+ + "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">",
+ testling.serializeHeader(protocolHeader));
+ }
+
+ @Test
+ public void testSerializeHeader_Component() {
+ XMPPSerializer testling = createSerializer(StreamType.ComponentStreamType);
+ ProtocolHeader protocolHeader = new ProtocolHeader();
+ protocolHeader.setFrom("bla@foo.com");
+ protocolHeader.setTo("foo.com");
+ protocolHeader.setID("myid");
+ protocolHeader.setVersion("0.99");
+
+ assertEquals("<?xml version=\"1.0\"?>"
+ + "<stream:stream xmlns=\"jabber:component:accept\" "
+ + "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">",
+ testling.serializeHeader(protocolHeader));
+ }
+
+ @Test
+ public void testSerializeHeader_Server() {
+ XMPPSerializer testling = createSerializer(StreamType.ServerStreamType);
+ ProtocolHeader protocolHeader = new ProtocolHeader();
+ protocolHeader.setFrom("bla@foo.com");
+ protocolHeader.setTo("foo.com");
+ protocolHeader.setID("myid");
+ protocolHeader.setVersion("0.99");
+
+ assertEquals("<?xml version=\"1.0\"?>"
+ + "<stream:stream xmlns=\"jabber:server\" "
+ + "xmlns:stream=\"http://etherx.jabber.org/streams\" "
+ + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">",
+ testling.serializeHeader(protocolHeader));
+ }
+
+ private XMPPSerializer createSerializer(StreamType type) {
+ return new XMPPSerializer(payloadSerializerCollection, type, false);
+ }
+
+}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java
new file mode 100644
index 0000000..6a50f01
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java
@@ -0,0 +1,34 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.elements.Idle;
+
+/**
+ * Test for {@link IdleSerializer}
+ *
+ */
+public class IdleSerializerTest {
+
+ @Test
+ public void testSerialize() {
+ IdleSerializer testling = new IdleSerializer();
+ Idle idle = new Idle(DateTime.stringToDate("1969-07-21T02:56:15Z"));
+
+ assertEquals("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>",
+ testling.serialize(idle));
+ }
+
+}