summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-02-02 11:26:01 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-02-04 10:09:21 (GMT)
commitbe72c822d3cffd840e753e01fe28857b081cf6f3 (patch)
treeae3fe8fe22175f9bfee89f0688b71ca377f7f1e9 /test/com/isode
parent2c9305a872e4ca958bfd86472c4540cc10d11a2f (diff)
downloadstroke-be72c822d3cffd840e753e01fe28857b081cf6f3.zip
stroke-be72c822d3cffd840e753e01fe28857b081cf6f3.tar.bz2
Add Block Parser and Serializer
Add BlockParser and BlockSerializer for the block payload classes. This required slightly different approach to the Swiften code as C++ templates are different to Java generics. In short needed to add a type hierachy to the Block payload classes and to the Parsers and Serilaizers associated with them. Test-information: Ran unit tests everything passed ok. Change-Id: I3ea2d66afd7cb3b5c4c3515be3a1ef99d7dbb566
Diffstat (limited to 'test/com/isode')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/BlockParserTest.java83
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/BlockSerializerTest.java71
2 files changed, 154 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/BlockParserTest.java b/test/com/isode/stroke/parser/payloadparsers/BlockParserTest.java
new file mode 100644
index 0000000..bd2d5cf
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/BlockParserTest.java
@@ -0,0 +1,83 @@
+/* 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.assertTrue;
+
+import org.junit.Test;
+
+import com.isode.stroke.elements.BlockListPayload;
+import com.isode.stroke.elements.BlockPayload;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.UnblockPayload;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+
+/**
+ * Test for {@link BlockParser} (and its subclasses)
+ */
+public class BlockParserTest {
+
+ /**
+ * Constructor
+ */
+ public BlockParserTest() {
+
+ }
+
+ @Test
+ public void testExample4() {
+ PayloadsParserTester parser =
+ new PayloadsParserTester(new DummyEventLoop());
+ boolean success = parser.parse("<blocklist xmlns='urn:xmpp:blocking'>"
+ + "<item jid='romeo@montague.net'/>"
+ + "<item jid='iago@shakespeare.lit'/>"
+ + "</blocklist>");
+ assertTrue(success);
+ Payload payload = parser.getPayload();
+ assertTrue(payload instanceof BlockListPayload);
+ BlockListPayload blockListPayload = (BlockListPayload) payload;
+ assertEquals(2,blockListPayload.getItems().size());
+ assertEquals(new JID("romeo@montague.net"),blockListPayload.getItems().get(0));
+ assertEquals(new JID("iago@shakespeare.lit"),blockListPayload.getItems().get(1));
+ }
+
+ @Test
+ public void testExample6() {
+ PayloadsParserTester parser =
+ new PayloadsParserTester(new DummyEventLoop());
+ boolean success = parser.parse("<block xmlns='urn:xmpp:blocking'>"
+ +"<item jid='romeo@montague.net'/>"
+ +"</block>");
+ assertTrue(success);
+ Payload payload = parser.getPayload();
+ assertTrue(payload instanceof BlockPayload);
+ BlockPayload blockPayload = (BlockPayload) payload;
+ assertEquals(1,blockPayload.getItems().size());
+ assertEquals(new JID("romeo@montague.net"),blockPayload.getItems().get(0));
+ }
+
+ @Test
+ public void testExample10() {
+ PayloadsParserTester parser =
+ new PayloadsParserTester(new DummyEventLoop());
+ boolean success = parser.parse("<unblock xmlns='urn:xmpp:blocking'>"
+ +"<item jid='romeo@montague.net'/>"
+ +"</unblock>");
+ assertTrue(success);
+ Payload payload = parser.getPayload();
+ assertTrue(payload instanceof UnblockPayload);
+ UnblockPayload unblockPayload = (UnblockPayload) payload;
+ assertEquals(1,unblockPayload.getItems().size());
+ assertEquals(new JID("romeo@montague.net"),unblockPayload.getItems().get(0));
+ }
+
+}
diff --git a/test/com/isode/stroke/serializer/payloadserializers/BlockSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/BlockSerializerTest.java
new file mode 100644
index 0000000..42f2132
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/BlockSerializerTest.java
@@ -0,0 +1,71 @@
+/* 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.elements.BlockListPayload;
+import com.isode.stroke.elements.BlockPayload;
+import com.isode.stroke.elements.UnblockPayload;
+import com.isode.stroke.jid.JID;
+
+/**
+ * Test for {@link BlockSerializer} classes
+ */
+public class BlockSerializerTest {
+
+ /**
+ * Constructor
+ */
+ public BlockSerializerTest() {
+ // Empty Constructor
+ }
+
+ @Test
+ public void testExample4() {
+ BlockBlockListPayloadSerializer testling = new BlockBlockListPayloadSerializer("blocklist");
+ BlockListPayload blockList = new BlockListPayload();
+ blockList.addItem(new JID("romeo@montague.net"));
+ blockList.addItem(new JID("iago@shakespeare.lit"));
+ String serializedBlockList = testling.serialize(blockList);
+ String expected = "<blocklist xmlns=\"urn:xmpp:blocking\">"
+ + "<item jid=\"romeo@montague.net\"/>"
+ + "<item jid=\"iago@shakespeare.lit\"/>"
+ + "</blocklist>";
+ assertEquals(expected,serializedBlockList);
+ }
+
+ @Test
+ public void testExample6() {
+ BlockBlockPayloadSerializer testling = new BlockBlockPayloadSerializer("block");
+ BlockPayload block = new BlockPayload();
+ block.addItem(new JID("romeo@montague.net"));
+ String serializedBlock = testling.serialize(block);
+ String expected = "<block xmlns=\"urn:xmpp:blocking\">"
+ + "<item jid=\"romeo@montague.net\"/>"
+ + "</block>";
+ assertEquals(expected,serializedBlock);
+ }
+
+ @Test
+ public void testExample10() {
+ BlockUnblockPayloadSerializer testling = new BlockUnblockPayloadSerializer("unblock");
+ UnblockPayload unblock = new UnblockPayload();
+ unblock.addItem(new JID("romeo@montague.net"));
+ String serializedBlock = testling.serialize(unblock);
+ String expected = "<unblock xmlns=\"urn:xmpp:blocking\">"
+ + "<item jid=\"romeo@montague.net\"/>"
+ + "</unblock>";
+ assertEquals(serializedBlock,expected);
+ }
+
+}