diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/BlockParserTest.java | 83 | ||||
-rw-r--r-- | test/com/isode/stroke/serializer/payloadserializers/BlockSerializerTest.java | 71 |
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); + } + +} |