From 25fade1995f559c8937b57585f462aaa2ae01c6a Mon Sep 17 00:00:00 2001 From: Tarun Gupta Date: Sun, 21 Jun 2015 18:03:44 +0530 Subject: Add tests for Payloads Parsers and Payloads Serializers. Updates DiscoInfoParser, DiscoItemsParser and VCard Element. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Test are added for: DeliveryReceipt Parser and Serializer. DiscoInfo Parser and Serializer, DiscoItemsParser. Replace Parser and Serializer. ResourceBind Parser and Serializer. SecurityLabel Parser and Serializer. SecurityLabelsCatalog Parser and Serializer. Status Parser and Serializer. StatusShow Parser and Serializer. SoftwareVersion Parser and Serializer. VCard Parser and Serializer. All tests passes. Change-Id: I8023372273e63813e1c8fe708fa6cdf39614e1f7 diff --git a/src/com/isode/stroke/elements/VCard.java b/src/com/isode/stroke/elements/VCard.java index 91a9093..ff4a02c 100644 --- a/src/com/isode/stroke/elements/VCard.java +++ b/src/com/isode/stroke/elements/VCard.java @@ -26,16 +26,16 @@ public class VCard extends Payload implements Serializable { private String nick_ = ""; private Date birthday_; private String unknownContent_ = ""; - private List emailAddresses_; - private List telephones_; - private List
addresses_; - private List addressLabels_; - private List jids_; + private List emailAddresses_ = new ArrayList(); + private List telephones_ = new ArrayList(); + private List
addresses_ = new ArrayList
(); + private List addressLabels_ = new ArrayList(); + private List jids_ = new ArrayList(); private String description_ = ""; - private List organizations_; - private List titles_; - private List roles_; - private List urls_; + private List organizations_ = new ArrayList(); + private List titles_ = new ArrayList(); + private List roles_ = new ArrayList(); + private List urls_ = new ArrayList(); public static class EMailAddress { public boolean isHome; @@ -43,7 +43,7 @@ public class VCard extends Payload implements Serializable { public boolean isInternet; public boolean isPreferred; public boolean isX400; - public String address; + public String address = ""; }; public static class Telephone { @@ -60,7 +60,7 @@ public class VCard extends Payload implements Serializable { public boolean isISDN; public boolean isPCS; public boolean isPreferred; - public String number; + public String number = ""; }; public static enum DeliveryType { @@ -77,13 +77,13 @@ public class VCard extends Payload implements Serializable { public DeliveryType deliveryType; public boolean isPreferred; - public String poBox; - public String addressExtension; - public String street; - public String locality; - public String region; - public String postalCode; - public String country; + public String poBox = ""; + public String addressExtension = ""; + public String street = ""; + public String locality = ""; + public String region = ""; + public String postalCode = ""; + public String country = ""; }; public static class AddressLabel { @@ -97,7 +97,7 @@ public class VCard extends Payload implements Serializable { }; public static class Organization { - public String name; + public String name = ""; public List units = new ArrayList(); }; diff --git a/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java b/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java index acd1ae0..181caa2 100644 --- a/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/DiscoInfoParser.java @@ -19,6 +19,11 @@ public class DiscoInfoParser extends GenericPayloadParser { } public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == TopLevel) { + if (attributes.getAttributeValue("node") != null) { + getPayloadInternal().setNode(attributes.getAttributeValue("node")); + } + } if (level_ == PayloadLevel) { if (element .equals("identity")) { getPayloadInternal().addIdentity(new DiscoInfo.Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); diff --git a/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java b/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java index 091fd32..abf7c29 100644 --- a/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/DiscoItemsParser.java @@ -26,6 +26,11 @@ public class DiscoItemsParser extends GenericPayloadParser { getPayloadInternal().addItem(item); } } + else if (level_ == TopLevel) { + if (element.equals("query")) { + getPayloadInternal().setNode(attributes.getAttribute("node")); + } + } ++level_; } diff --git a/test/com/isode/stroke/parser/payloadparsers/DeliveryReceiptParserTest.java b/test/com/isode/stroke/parser/payloadparsers/DeliveryReceiptParserTest.java new file mode 100644 index 0000000..fc74067 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/DeliveryReceiptParserTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the BSD license. + * See http://www.opensource.org/licenses/bsd-license.php 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.DeliveryReceiptRequest; +import com.isode.stroke.elements.DeliveryReceipt; +import com.isode.stroke.parser.payloadparsers.DeliveryReceiptParser; +import com.isode.stroke.parser.payloadparsers.DeliveryReceiptRequestParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class DeliveryReceiptParserTest { + + public DeliveryReceiptParserTest() { + + } + + @Test + public void testParseXEP0184Example3() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("")); + + DeliveryReceiptRequest request = (DeliveryReceiptRequest)(parser.getPayload()); + + assertNotNull(request); + } + + @Test + public void testParseXEP0184Example4() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("")); + + DeliveryReceipt receipt = (DeliveryReceipt)(parser.getPayload()); + + assertEquals("richard2-4.1.247", receipt.getReceivedID()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/DiscoInfoParserTest.java b/test/com/isode/stroke/parser/payloadparsers/DiscoInfoParserTest.java new file mode 100644 index 0000000..ef6fd72 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/DiscoInfoParserTest.java @@ -0,0 +1,115 @@ +/* + * 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.DiscoInfo; +import com.isode.stroke.parser.payloadparsers.DiscoInfoParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class DiscoInfoParserTest { + + public DiscoInfoParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "" + + "" + + "" + + "")); + + DiscoInfo payload = (DiscoInfo)(parser.getPayload()); + assertEquals(2, payload.getIdentities().size()); + assertEquals("Swift", payload.getIdentities().get(0).getName()); + assertEquals("pc", payload.getIdentities().get(0).getType()); + assertEquals("client", payload.getIdentities().get(0).getCategory()); + assertEquals("en", payload.getIdentities().get(0).getLanguage()); + assertEquals("Vlug", payload.getIdentities().get(1).getName()); + assertEquals("pc", payload.getIdentities().get(1).getType()); + assertEquals("client", payload.getIdentities().get(1).getCategory()); + assertEquals("nl", payload.getIdentities().get(1).getLanguage()); + assertEquals(3, payload.getFeatures().size()); + assertEquals("foo-feature", payload.getFeatures().get(0)); + assertEquals("bar-feature", payload.getFeatures().get(1)); + assertEquals("baz-feature", payload.getFeatures().get(2)); + assertTrue(payload.getNode().isEmpty()); + } + + @Test + public void testParse_Node() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "" + + "" + + "" + + "")); + + DiscoInfo payload = (DiscoInfo)(parser.getPayload()); + assertEquals(2, payload.getIdentities().size()); + assertEquals("Swift", payload.getIdentities().get(0).getName()); + assertEquals("pc", payload.getIdentities().get(0).getType()); + assertEquals("client", payload.getIdentities().get(0).getCategory()); + assertEquals("en", payload.getIdentities().get(0).getLanguage()); + assertEquals("Vlug", payload.getIdentities().get(1).getName()); + assertEquals("pc", payload.getIdentities().get(1).getType()); + assertEquals("client", payload.getIdentities().get(1).getCategory()); + assertEquals("nl", payload.getIdentities().get(1).getLanguage()); + assertEquals(3, payload.getFeatures().size()); + assertEquals("foo-feature", payload.getFeatures().get(0)); + assertEquals("bar-feature", payload.getFeatures().get(1)); + assertEquals("baz-feature", payload.getFeatures().get(2)); + assertEquals("blahblah", payload.getNode()); + } + + @Test + public void testParse_Form() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "Bot Configuration" + + "Hello!" + + "" + + "" + + "")); + + DiscoInfo payload = (DiscoInfo)(parser.getPayload()); + assertEquals(1, payload.getExtensions().size()); + assertEquals("Bot Configuration", payload.getExtensions().get(0).getTitle()); + assertEquals(2, payload.getFeatures().size()); + assertEquals("foo-feature", payload.getFeatures().get(0)); + assertEquals("bar-feature", payload.getFeatures().get(1)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/DiscoItemsParserTest.java b/test/com/isode/stroke/parser/payloadparsers/DiscoItemsParserTest.java new file mode 100644 index 0000000..2564633 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/DiscoItemsParserTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.Test; +import com.isode.stroke.elements.DiscoItems; +import com.isode.stroke.parser.payloadparsers.DiscoItemsParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class DiscoItemsParserTest { + + public DiscoItemsParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "")); + + DiscoItems payload =(DiscoItems)(parser.getPayload()); + assertEquals(2, payload.getItems().size()); + assertEquals("List Service Configurations", payload.getItems().get(0).getName()); + assertEquals("list", payload.getItems().get(0).getNode()); + assertEquals("responder@domain", payload.getItems().get(0).getJID().toString()); + assertEquals("Configure Service", payload.getItems().get(1).getName()); + assertEquals("config", payload.getItems().get(1).getNode()); + assertEquals("responder@domain", payload.getItems().get(1).getJID().toString()); + assertEquals("http://jabber.org/protocol/commands", payload.getNode()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/ReplaceTest.java b/test/com/isode/stroke/parser/payloadparsers/ReplaceTest.java new file mode 100644 index 0000000..256a09e --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/ReplaceTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.Test; +import com.isode.stroke.elements.Replace; +import com.isode.stroke.parser.payloadparsers.ReplaceParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class ReplaceTest { + + public ReplaceTest() { + + } + + @Test + public void testParseTrivial() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("")); + Replace payload = (Replace)(parser.getPayload()); + assertEquals("bad1", payload.getID()); + } + + @Test + public void testParseChild() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("")); + Replace payload = (Replace)(parser.getPayload()); + assertEquals("bad1", payload.getID()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/ResourceBindParserTest.java b/test/com/isode/stroke/parser/payloadparsers/ResourceBindParserTest.java new file mode 100644 index 0000000..337876a --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/ResourceBindParserTest.java @@ -0,0 +1,51 @@ +/* + * 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.ResourceBind; +import com.isode.stroke.parser.payloadparsers.ResourceBindParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; + +public class ResourceBindParserTest { + + public ResourceBindParserTest() { + + } + + @Test + public void testParse_JID() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse("somenode@example.com/someresource")); + + ResourceBind payload = (ResourceBind)(parser.getPayload()); + assertEquals(new JID("somenode@example.com/someresource"), payload.getJID()); + } + + @Test + public void testParse_Resource() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse("someresource")); + + ResourceBind payload = (ResourceBind)(parser.getPayload()); + assertEquals("someresource", payload.getResource()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/SecurityLabelParserTest.java b/test/com/isode/stroke/parser/payloadparsers/SecurityLabelParserTest.java new file mode 100644 index 0000000..7c97ee1 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/SecurityLabelParserTest.java @@ -0,0 +1,56 @@ +/* + * 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.SecurityLabel; +import com.isode.stroke.parser.payloadparsers.SecurityLabelParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class SecurityLabelParserTest { + + public SecurityLabelParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "SECRET" + + "" + + "" + + "" + + "" + + "" + + "MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=" + + "" + + "")); + + SecurityLabel payload = (SecurityLabel)(parser.getPayload()); + assertEquals("SECRET", payload.getDisplayMarking()); + assertEquals("black", payload.getForegroundColor()); + assertEquals("red", payload.getBackgroundColor()); + assertEquals("MQYCAQQGASk=", payload.getLabel()); + assertEquals("", payload.getEquivalentLabels().toArray()[0]); + assertEquals("MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=", payload.getEquivalentLabels().toArray()[1]); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParserTest.java b/test/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParserTest.java new file mode 100644 index 0000000..49bc4aa --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/SecurityLabelsCatalogParserTest.java @@ -0,0 +1,69 @@ +/* + * 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.SecurityLabelsCatalog; +import com.isode.stroke.parser.payloadparsers.SecurityLabelsCatalogParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; + +public class SecurityLabelsCatalogParserTest { + + public SecurityLabelsCatalogParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "SECRET" + + "" + + "" + + "" + + "" + + "" + + "CONFIDENTIAL" + + "" + + "" + + "" + + "" + + "")); + + SecurityLabelsCatalog payload = (SecurityLabelsCatalog)(parser.getPayload()); + assertEquals("Default", payload.getName()); + assertEquals("an example set of labels", payload.getDescription()); + assertEquals(new JID("example.com"), payload.getTo()); + assertEquals(3, payload.getItems().size()); + assertEquals("SECRET", payload.getItems().get(0).getLabel().getDisplayMarking()); + assertEquals("MQYCAQQGASk=", payload.getItems().get(0).getLabel().getLabel()); + assertEquals(false, payload.getItems().get(0).getIsDefault()); + assertEquals("Classified|SECRET", payload.getItems().get(0).getSelector()); + assertEquals("CONFIDENTIAL", payload.getItems().get(1).getLabel().getDisplayMarking()); + assertEquals("MQMGASk=", payload.getItems().get(1).getLabel().getLabel()); + assertEquals(true, payload.getItems().get(1).getIsDefault()); + assertEquals("Classified|CONFIDENTIAL", payload.getItems().get(1).getSelector()); + assertEquals(false, payload.getItems().get(2).getIsDefault()); + assertEquals("Unclassified|UNCLASSIFIED", payload.getItems().get(2).getSelector()); + assertNull(payload.getItems().get(2).getLabel()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/SoftwareVersionParserTest.java b/test/com/isode/stroke/parser/payloadparsers/SoftwareVersionParserTest.java new file mode 100644 index 0000000..46617bf --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/SoftwareVersionParserTest.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 org.junit.Test; +import com.isode.stroke.elements.SoftwareVersion; +import com.isode.stroke.parser.payloadparsers.SoftwareVersionParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class SoftwareVersionParserTest { + + public SoftwareVersionParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("" + + "myclient" + + "1.0" + + "Mac OS X" + + "")); + + SoftwareVersion payload = (SoftwareVersion)parser.getPayload(); + assertEquals("myclient", payload.getName()); + assertEquals("1.0", payload.getVersion()); + assertEquals("Mac OS X", payload.getOS()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/StatusParserTest.java b/test/com/isode/stroke/parser/payloadparsers/StatusParserTest.java new file mode 100644 index 0000000..3ecc736 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/StatusParserTest.java @@ -0,0 +1,38 @@ +/* + * 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.Status; +import com.isode.stroke.parser.payloadparsers.StatusParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class StatusParserTest { + + public StatusParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("foobarfum")); + + Status payload = (Status)(parser.getPayload()); + assertEquals("foobarfum", payload.getText()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/StatusShowParserTest.java b/test/com/isode/stroke/parser/payloadparsers/StatusShowParserTest.java new file mode 100644 index 0000000..6e30f1c --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/StatusShowParserTest.java @@ -0,0 +1,78 @@ +/* + * 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.StatusShow; +import com.isode.stroke.parser.payloadparsers.StatusShowParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class StatusShowParserTest { + + public StatusShowParserTest() { + + } + + @Test + public void testParse_Invalid() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("invalid")); + + StatusShow payload = (StatusShow)(parser.getPayload()); + assertEquals(StatusShow.Type.Online, payload.getType()); + } + + @Test + public void testParse_Away() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("away")); + + StatusShow payload = (StatusShow)(parser.getPayload()); + assertEquals(StatusShow.Type.Away, payload.getType()); + } + + @Test + public void testParse_FFC() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("chat")); + + StatusShow payload = (StatusShow)(parser.getPayload()); + assertEquals(StatusShow.Type.FFC, payload.getType()); + } + + @Test + public void testParse_XA() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("xa")); + + StatusShow payload = (StatusShow)(parser.getPayload()); + assertEquals(StatusShow.Type.XA, payload.getType()); + } + + @Test + public void testParse_DND() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("dnd")); + + StatusShow payload = (StatusShow)(parser.getPayload()); + assertEquals(StatusShow.Type.DND, payload.getType()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/VCardParserTest.java b/test/com/isode/stroke/parser/payloadparsers/VCardParserTest.java new file mode 100644 index 0000000..292df11 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/VCardParserTest.java @@ -0,0 +1,215 @@ +/* + * 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.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import org.junit.BeforeClass; +import org.junit.Test; +import com.isode.stroke.elements.VCard; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.parser.payloadparsers.VCardParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.base.ByteArray; +import com.isode.stroke.stringcodecs.Hexify; + +public class VCardParserTest { + + @Test + public void testParse() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "2.0" + + "Alice In Wonderland" + + "" + + "Wonderland" + + "Alice" + + "In" + + "Mrs" + + "PhD" + + "" + + "" + + "alice@wonderland.lit" + + "" + + "" + + "" + + "" + + "" + + "alice@teaparty.lit" + + "" + + "" + + "" + + "" + + "555-6273" + + "" + + "" + + "" + + "" + + "Any Town" + + "Fake Street 123" + + "12345" + + "USA" + + "" + + "" + + "" + + "DreamGirl" + + "1865-05-04T00:00:00Z" + + "alice@teaparty.lit" + + "alice@wonderland.lit" + + "I once fell down a rabbit hole." + + "" + + "Alice In Wonderland Inc." + + "" + + "Some Title" + + "Main Character" + + "http://wonderland.lit/~alice" + + "http://teaparty.lit/~alice2" + + "mutt" + + "")); + + VCard payload = (VCard)(parser.getPayload()); + assertEquals(("2.0"), payload.getVersion()); + assertEquals(("Alice In Wonderland"), payload.getFullName()); + assertEquals(("Alice"), payload.getGivenName()); + assertEquals(("In"), payload.getMiddleName()); + assertEquals(("Wonderland"), payload.getFamilyName()); + assertEquals(("Mrs"), payload.getPrefix()); + assertEquals(("PhD"), payload.getSuffix()); + assertEquals(("DreamGirl"), payload.getNickname()); + assertEquals(DateTime.stringToDate("1865-05-04T00:00:00Z"), payload.getBirthday()); + assertEquals(2, (payload.getEMailAddresses().size())); + assertEquals(("alice@wonderland.lit"), payload.getEMailAddresses().get(0).address); + assertTrue(payload.getEMailAddresses().get(0).isHome); + assertTrue(payload.getEMailAddresses().get(0).isInternet); + assertTrue(payload.getEMailAddresses().get(0).isPreferred); + assertFalse(payload.getEMailAddresses().get(0).isWork); + assertFalse(payload.getEMailAddresses().get(0).isX400); + assertEquals(("alice@teaparty.lit"), payload.getEMailAddresses().get(1).address); + assertFalse(payload.getEMailAddresses().get(1).isHome); + assertFalse(payload.getEMailAddresses().get(1).isInternet); + assertFalse(payload.getEMailAddresses().get(1).isPreferred); + assertTrue(payload.getEMailAddresses().get(1).isWork); + assertTrue(payload.getEMailAddresses().get(1).isX400); + + assertEquals(1, (payload.getTelephones().size())); + assertEquals(("555-6273"), payload.getTelephones().get(0).number); + assertTrue(payload.getTelephones().get(0).isHome); + assertTrue(payload.getTelephones().get(0).isVoice); + assertFalse(payload.getTelephones().get(0).isPreferred); + + assertEquals(1, (payload.getAddresses().size())); + assertEquals(("Any Town"), payload.getAddresses().get(0).locality); + assertEquals(("Fake Street 123"), payload.getAddresses().get(0).street); + assertEquals(("12345"), payload.getAddresses().get(0).postalCode); + assertEquals(("USA"), payload.getAddresses().get(0).country); + assertTrue(payload.getAddresses().get(0).isHome); + + assertEquals(1, (payload.getAddressLabels().size())); + assertEquals(("Fake Street 123"), payload.getAddressLabels().get(0).lines.get(0)); + assertEquals(("12345 Any Town"), payload.getAddressLabels().get(0).lines.get(1)); + assertEquals(("USA"), payload.getAddressLabels().get(0).lines.get(2)); + assertTrue(payload.getAddressLabels().get(0).isHome); + + assertEquals(2, (payload.getJIDs().size())); + assertEquals(new JID("alice@teaparty.lit"), payload.getJIDs().get(0)); + assertEquals(new JID("alice@wonderland.lit"), payload.getJIDs().get(1)); + + assertEquals(("I once fell down a rabbit hole."), payload.getDescription()); + + assertEquals(1, (payload.getOrganizations().size())); + assertEquals(("Alice In Wonderland Inc."), payload.getOrganizations().get(0).name); + assertEquals(0, (payload.getOrganizations().get(0).units.size())); + + assertEquals(1, (payload.getTitles().size())); + assertEquals(("Some Title"), payload.getTitles().get(0)); + assertEquals(1, (payload.getRoles().size())); + assertEquals(("Main Character"), payload.getRoles().get(0)); + assertEquals(2, (payload.getURLs().size())); + assertEquals(("http://wonderland.lit/~alice"), payload.getURLs().get(0)); + assertEquals(("http://teaparty.lit/~alice2"), payload.getURLs().get(1)); + + assertEquals(("mutt"), payload.getUnknownContent()); + } + + @Test + public void testParse_Photo() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "" + + "image/jpeg" + + "" + + "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" + + "EyMzQ1Njc4OTA=" + + "" + + "" + + "")); + + VCard payload = (VCard)(parser.getPayload()); + assertEquals(("image/jpeg"), payload.getPhotoType()); + assertEquals(new ByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload.getPhoto()); + } + + void testParse_NewlinedPhoto() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "" + + "image/jpeg" + + "" + + "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" + + "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" + + "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" + + "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" + + "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" + + "" + + "" + + "")); + + VCard payload = (VCard)(parser.getPayload()); + assertEquals(("image/jpeg"), payload.getPhotoType()); + assertEquals("753B044CA480B2482EDBF06A54EFA881CBB70C9CB84004C626AA6C6BACE75B034688B9D512555507A3ED4BE993887517B2B3A52AF463B6FCD554392735A445E7C1259AEE440BA5680A594110407F9457F47A6627DA0929D17D6484D8BBE5D97EACE8FDE40AFA5EEC0B87E668492B6AC0E5A3A48A71999995C3B13AF6AAF4158D28237CDC6B15F0CC7C3B2F1F507F8B07EEE7D0BC837CF206BE870A7C3225DEBE1DC073CA4DD3492020D96AF4063F6D824BE35F18FFAC16B096E09AB27F37BF3048CA42ED556CCCB05956FF2E167BA9B9BCA2F0EA6177FD702165B33CFC006C185EA5655BD683E2144053E4C34A08C4CF122D27A57B5E755CF41D06DB3CD215C26A", Hexify.hexify(payload.getPhoto())); + } + + + @Test + public void testParse_Nickname() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "mynick" + + "")); + + VCard payload = (VCard)(parser.getPayload()); + assertEquals(("mynick"), payload.getNickname()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/DeliveryReceiptSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/DeliveryReceiptSerializerTest.java new file mode 100644 index 0000000..9115bd6 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/DeliveryReceiptSerializerTest.java @@ -0,0 +1,44 @@ +/* + * 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.DeliveryReceiptRequestSerializer; +import com.isode.stroke.serializer.payloadserializers.DeliveryReceiptSerializer; +import com.isode.stroke.elements.DeliveryReceiptRequest; +import com.isode.stroke.elements.DeliveryReceipt; + +public class DeliveryReceiptSerializerTest { + + /** + * Default Constructor. + */ + public DeliveryReceiptSerializerTest() { + + } + + @Test + public void testSerialize_XEP0184Example3() { + String expected = ""; + + DeliveryReceiptRequest receipt = new DeliveryReceiptRequest(); + + DeliveryReceiptRequestSerializer serializer = new DeliveryReceiptRequestSerializer(); + assertEquals(expected, serializer.serializePayload(receipt)); + } + + @Test + public void testSerialize_XEP0184Example4() { + String expected = ""; + + DeliveryReceipt receipt = new DeliveryReceipt("richard2-4.1.247"); + + DeliveryReceiptSerializer serializer = new DeliveryReceiptSerializer(); + assertEquals(expected, serializer.serializePayload(receipt)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/DiscoInfoSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/DiscoInfoSerializerTest.java new file mode 100644 index 0000000..7ae9778 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/DiscoInfoSerializerTest.java @@ -0,0 +1,71 @@ +/* + * 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.DiscoInfoSerializer; +import com.isode.stroke.elements.DiscoInfo; +import com.isode.stroke.elements.Form; + +public class DiscoInfoSerializerTest { + + /** + * Default Constructor. + */ + public DiscoInfoSerializerTest() { + + } + + @Test + public void testSerialize() { + DiscoInfoSerializer testling = new DiscoInfoSerializer(); + DiscoInfo discoInfo = new DiscoInfo(); + discoInfo.addIdentity(new DiscoInfo.Identity("Swift", "client", "pc")); + discoInfo.addIdentity(new DiscoInfo.Identity("Vlug", "client", "pc", "nl")); + discoInfo.addFeature("http://jabber.org/protocol/caps"); + discoInfo.addFeature("http://jabber.org/protocol/disco#info"); + discoInfo.setNode("http://swift.im#bla"); + + String expectedResult = + "" + + "" + + "" + + "" + + "" + + ""; + + assertEquals(expectedResult, testling.serialize(discoInfo)); + } + + @Test + public void testSerialize_Form() { + DiscoInfoSerializer testling = new DiscoInfoSerializer(); + DiscoInfo discoInfo = new DiscoInfo(); + discoInfo.addFeature("http://jabber.org/protocol/caps"); + discoInfo.addFeature("http://jabber.org/protocol/disco#info"); + Form form = new Form(Form.Type.FORM_TYPE); + form.setTitle("Bot Configuration"); + discoInfo.addExtension(form); + + String expectedResult = + "" + + "" + + "" + + "" + + "Bot Configuration" + + "" + + ""; + + assertEquals(expectedResult, testling.serialize(discoInfo)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/ReplaceSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/ReplaceSerializerTest.java new file mode 100644 index 0000000..8ee7469 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/ReplaceSerializerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011 Vlad Voicu + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +/* + * Copyright (c) 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 com.isode.stroke.serializer.payloadserializers.ReplaceSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.Replace; + +public class ReplaceSerializerTest { + + /** + * Default Constructor. + */ + public ReplaceSerializerTest() { + + } + + @Test + public void testSerialize() { + ReplaceSerializer testling = new ReplaceSerializer(); + Replace replace = new Replace(); + replace.setID("bad1"); + assertEquals("", testling.serialize(replace)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/ResourceBindSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/ResourceBindSerializerTest.java new file mode 100644 index 0000000..16a9ed2 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/ResourceBindSerializerTest.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.serializer.payloadserializers; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.payloadserializers.ResourceBindSerializer; +import com.isode.stroke.elements.ResourceBind; +import com.isode.stroke.jid.JID; + +public class ResourceBindSerializerTest { + + /** + * Default Constructor. + */ + public ResourceBindSerializerTest() { + + } + + @Test + public void testSerialize_JID() { + ResourceBindSerializer testling = new ResourceBindSerializer(); + ResourceBind resourceBind = new ResourceBind(); + resourceBind.setJID(new JID("somenode@example.com/someresource")); + + assertEquals( + "" + + "somenode@example.com/someresource" + + "", testling.serialize(resourceBind)); + } + + @Test + public void testSerialize_Resource() { + ResourceBindSerializer testling = new ResourceBindSerializer(); + ResourceBind resourceBind = new ResourceBind(); + resourceBind.setResource("someresource"); + + assertEquals( + "" + + "someresource" + + "", testling.serialize(resourceBind)); + } + + @Test + public void testSerialize_Empty() { + ResourceBindSerializer testling = new ResourceBindSerializer(); + ResourceBind resourceBind = new ResourceBind(); + + assertEquals("", testling.serialize(resourceBind)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelSerializerTest.java new file mode 100644 index 0000000..d9ddccb --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelSerializerTest.java @@ -0,0 +1,67 @@ +/* + * 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.SecurityLabelSerializer; +import com.isode.stroke.elements.SecurityLabel; + +public class SecurityLabelSerializerTest { + + /** + * Default Constructor. + */ + public SecurityLabelSerializerTest() { + + } + + @Test + public void testSerialize() { + SecurityLabelSerializer testling = new SecurityLabelSerializer(); + SecurityLabel securityLabel = new SecurityLabel(); + securityLabel.setDisplayMarking("SECRET"); + securityLabel.setForegroundColor("black"); + securityLabel.setBackgroundColor("red"); + securityLabel.setLabel("MQYCAQQGASk="); + securityLabel.addEquivalentLabel(""); + securityLabel.addEquivalentLabel("MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk="); + + assertEquals( + "" + + "SECRET" + + "" + + "" + + "" + + "" + + "" + + "MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=" + + "" + + "", testling.serialize(securityLabel)); + } + + @Test + public void testSerialize_EmptyLabel() { + SecurityLabelSerializer testling = new SecurityLabelSerializer(); + SecurityLabel securityLabel = new SecurityLabel(); + securityLabel.setDisplayMarking("SECRET"); + securityLabel.setLabel(""); + + assertEquals( + "" + + "SECRET" + + "" + + "", testling.serialize(securityLabel)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelsCatalogSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelsCatalogSerializerTest.java new file mode 100644 index 0000000..d61cfab --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/SecurityLabelsCatalogSerializerTest.java @@ -0,0 +1,81 @@ +/* + * 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.SecurityLabelsCatalogSerializer; +import com.isode.stroke.elements.SecurityLabelsCatalog; +import com.isode.stroke.elements.SecurityLabel; +import com.isode.stroke.jid.JID; + +public class SecurityLabelsCatalogSerializerTest { + + /** + * Default Constructor. + */ + public SecurityLabelsCatalogSerializerTest() { + + } + + @Test + public void testSerialize() { + SecurityLabelsCatalogSerializer testling = new SecurityLabelsCatalogSerializer(); + SecurityLabelsCatalog catalog = new SecurityLabelsCatalog(); + catalog.setTo(new JID("example.com")); + catalog.setName("Default"); + catalog.setDescription("an example set of labels"); + + SecurityLabelsCatalog.Item item1 = new SecurityLabelsCatalog.Item(); + SecurityLabel securityLabel1 = new SecurityLabel(); + item1.setLabel(securityLabel1); + securityLabel1.setDisplayMarking("SECRET"); + securityLabel1.setForegroundColor("black"); + securityLabel1.setBackgroundColor("red"); + item1.setIsDefault(false); + item1.setSelector("Classified|SECRET"); + securityLabel1.setLabel("MQYCAQQGASk="); + catalog.addItem(item1); + + SecurityLabelsCatalog.Item item2 = new SecurityLabelsCatalog.Item(); + SecurityLabel securityLabel2 = new SecurityLabel(); + item2.setLabel(securityLabel2); + securityLabel2.setDisplayMarking("CONFIDENTIAL"); + securityLabel2.setForegroundColor("black"); + securityLabel2.setBackgroundColor("navy"); + item2.setIsDefault(true); + item2.setSelector("Classified|CONFIDENTIAL"); + securityLabel2.setLabel("MQMGASk="); + catalog.addItem(item2); + + SecurityLabelsCatalog.Item item3 = new SecurityLabelsCatalog.Item(); + item3.setSelector("Unclassified|UNCLASSIFIED"); + catalog.addItem(item3); + + assertEquals( + "" + + "" + + "" + + "SECRET" + + "" + + "" + + "" + + "" + + "" + + "CONFIDENTIAL" + + "" + + "" + + "" + + "" + + "", testling.serialize(catalog)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/SoftwareVersionSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/SoftwareVersionSerializerTest.java new file mode 100644 index 0000000..1361033 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/SoftwareVersionSerializerTest.java @@ -0,0 +1,35 @@ +/* + * 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.SoftwareVersionSerializer; +import com.isode.stroke.elements.SoftwareVersion; + +public class SoftwareVersionSerializerTest { + + /** + * Default Constructor. + */ + public SoftwareVersionSerializerTest() { + + } + + @Test + public void testSerialize() { + SoftwareVersionSerializer testling = new SoftwareVersionSerializer(); + SoftwareVersion softwareVersion = new SoftwareVersion("Swift", "0.1", "Mac OS X"); + String expectedResult = "Swift0.1Mac OS X"; + assertEquals(expectedResult, testling.serialize(softwareVersion)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/StatusSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/StatusSerializerTest.java new file mode 100644 index 0000000..32b4390 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/StatusSerializerTest.java @@ -0,0 +1,37 @@ +/* + * 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.StatusSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.Status; + +public class StatusSerializerTest { + + /** + * Default Constructor. + */ + public StatusSerializerTest() { + + } + + @Test + public void testSerialize() { + StatusSerializer testling = new StatusSerializer(); + Status status = new Status("I am away"); + String expectedResult = "I am away"; + assertEquals(expectedResult, testling.serialize(status)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/StatusShowSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/StatusShowSerializerTest.java new file mode 100644 index 0000000..7eae46e --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/StatusShowSerializerTest.java @@ -0,0 +1,71 @@ +/* + * 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.StatusShowSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.StatusShow; + +public class StatusShowSerializerTest { + + /** + * Default Constructor. + */ + public StatusShowSerializerTest() { + + } + + @Test + public void testSerialize_Online() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.Online); + assertEquals("", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_Away() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.Away); + assertEquals("away", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_FFC() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.FFC); + assertEquals("chat", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_XA() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.XA); + assertEquals("xa", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_DND() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.DND); + assertEquals("dnd", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_None() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.None); + assertEquals("", testling.serialize(statusShow)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/VCardSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/VCardSerializerTest.java new file mode 100644 index 0000000..57c4d1e --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/VCardSerializerTest.java @@ -0,0 +1,151 @@ +/* + * 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.BeforeClass; +import org.junit.Test; +import com.isode.stroke.elements.VCard; +import com.isode.stroke.serializer.payloadserializers.VCardSerializer; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.jid.JID; +import com.isode.stroke.base.ByteArray; + +public class VCardSerializerTest { + + @Test + public void testSerialize() { + VCardSerializer testling = new VCardSerializer(); + VCard vcard = new VCard(); + vcard.setVersion("2.0"); + vcard.setFullName("Alice In Wonderland"); + vcard.setPrefix("Mrs"); + vcard.setGivenName("Alice"); + vcard.setMiddleName("In"); + vcard.setFamilyName("Wonderland"); + vcard.setSuffix("PhD"); + vcard.setNickname("DreamGirl"); + vcard.setPhoto(new ByteArray("abcdef")); + vcard.setPhotoType("image/png"); + vcard.setBirthday(DateTime.stringToDate("1865-05-04T00:00:00Z")); + vcard.addUnknownContent("mutt"); + + VCard.EMailAddress emailAddress1 = new VCard.EMailAddress(); + emailAddress1.address = "alice@wonderland.lit"; + emailAddress1.isHome = true; + emailAddress1.isPreferred = true; + emailAddress1.isInternet = true; + vcard.addEMailAddress(emailAddress1); + + VCard.EMailAddress address2 = new VCard.EMailAddress(); + address2.address = "alice@teaparty.lit"; + address2.isWork = true; + address2.isX400 = true; + vcard.addEMailAddress(address2); + + VCard.Telephone telephone1 = new VCard.Telephone(); + telephone1.number = "555-6273"; + telephone1.isHome = true; + telephone1.isVoice = true; + vcard.addTelephone(telephone1); + + VCard.Address address1 = new VCard.Address(); + address1.locality = "Any Town"; + address1.street = "Fake Street 123"; + address1.postalCode = "12345"; + address1.country = "USA"; + address1.isHome = true; + vcard.addAddress(address1); + + VCard.AddressLabel label1 = new VCard.AddressLabel(); + label1.lines.add("Fake Street 123"); + label1.lines.add("12345 Any Town"); + label1.lines.add("USA"); + label1.isHome = true; + vcard.addAddressLabel(label1); + + vcard.addJID(new JID("alice@teaparty.lit")); + vcard.addJID(new JID("alice@wonderland.lit")); + + vcard.setDescription("I once fell down a rabbit hole."); + + VCard.Organization org1 = new VCard.Organization(); + org1.name = "Alice In Wonderland Inc."; + vcard.addOrganization(org1); + + vcard.addTitle("Some Title"); + vcard.addRole("Main Character"); + vcard.addURL("http://wonderland.lit/~alice"); + vcard.addURL("http://teaparty.lit/~alice2"); + + String expectedResult = + "" + + "2.0" + + "Alice In Wonderland" + + "" + + "Wonderland" + + "Alice" + + "In" + + "Mrs" + + "PhD" + + "" + + "" + + "alice@wonderland.lit" + + "" + + "" + + "" + + "" + + "" + + "alice@teaparty.lit" + + "" + + "" + + "" + + "DreamGirl" + + "" + + "image/png" + + "YWJjZGVm" + + "" + + "1865-05-04T00:00:00Z" + + "" + + "555-6273" + + "" + + "" + + "" + + "" + + "Fake Street 123" + + "Any Town" + + "12345" + + "USA" + + "" + + "" + + "" + + "alice@teaparty.lit" + + "alice@wonderland.lit" + + "I once fell down a rabbit hole." + + "" + + "Alice In Wonderland Inc." + + "" + + "Some Title" + + "Main Character" + + "http://wonderland.lit/~alice" + + "http://teaparty.lit/~alice2" + + "mutt" + + ""; + + assertEquals(expectedResult, testling.serialize(vcard)); + } +} \ No newline at end of file -- cgit v0.10.2-6-g49f6