diff options
24 files changed, 1502 insertions, 19 deletions
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<EMailAddress> emailAddresses_; - private List<Telephone> telephones_; - private List<Address> addresses_; - private List<AddressLabel> addressLabels_; - private List<JID> jids_; + private List<EMailAddress> emailAddresses_ = new ArrayList<EMailAddress>(); + private List<Telephone> telephones_ = new ArrayList<Telephone>(); + private List<Address> addresses_ = new ArrayList<Address>(); + private List<AddressLabel> addressLabels_ = new ArrayList<AddressLabel>(); + private List<JID> jids_ = new ArrayList<JID>(); private String description_ = ""; - private List<Organization> organizations_; - private List<String> titles_; - private List<String> roles_; - private List<String> urls_; + private List<Organization> organizations_ = new ArrayList<Organization>(); + private List<String> titles_ = new ArrayList<String>(); + private List<String> roles_ = new ArrayList<String>(); + private List<String> urls_ = new ArrayList<String>(); 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<String> units = new ArrayList<String>(); }; 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<DiscoInfo> { } 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<DiscoItems> { 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("<request xmlns='urn:xmpp:receipts'/>")); + + DeliveryReceiptRequest request = (DeliveryReceiptRequest)(parser.getPayload()); + + assertNotNull(request); + } + + @Test + public void testParseXEP0184Example4() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>")); + + 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( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + + "<feature var=\"foo-feature\"/>" + + "<feature var=\"bar-feature\"/>" + + "<feature var=\"baz-feature\"/>" + + "</query>")); + + 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( + "<query xmlns=\"http://jabber.org/protocol/disco#info\" node=\"blahblah\">" + + "<identity name=\"Swift\" category=\"client\" type=\"pc\" xml:lang=\"en\"/>" + + "<identity name=\"Vlug\" category=\"client\" type=\"pc\" xml:lang=\"nl\"/>" + + "<feature var=\"foo-feature\"/>" + + "<feature var=\"bar-feature\"/>" + + "<feature var=\"baz-feature\"/>" + + "</query>")); + + 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( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + + "<feature var=\"foo-feature\"/>" + + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + + "<title>Bot Configuration</title>" + + "<instructions>Hello!</instructions>" + + "</x>" + + "<feature var=\"bar-feature\"/>" + + "</query>")); + + 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( + "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" + + "<item jid='responder@domain' node='list' name='List Service Configurations'/>" + + "<item jid='responder@domain' node='config' name='Configure Service'/>" + + "</query>")); + + 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 id='bad1' xmlns='http://swift.im/protocol/replace'/>")); + 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 id='bad1' xmlns='http://swift.im/protocol/replace' ><child xmlns='blah' id=\"hi\"/></replace>")); + 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("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>somenode@example.com/someresource</jid></bind>")); + + 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("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>someresource</resource></bind>")); + + 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( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking fgcolor=\"black\" bgcolor=\"red\">SECRET</displaymarking>" + + "<label>" + + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + + "</label>" + + "<equivalentlabel>" + + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + + "</equivalentlabel>" + + "<equivalentlabel>" + + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + + "</equivalentlabel>" + + "</securitylabel>")); + + SecurityLabel payload = (SecurityLabel)(parser.getPayload()); + assertEquals("SECRET", payload.getDisplayMarking()); + assertEquals("black", payload.getForegroundColor()); + assertEquals("red", payload.getBackgroundColor()); + assertEquals("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>", payload.getLabel()); + assertEquals("<icismlabel classification=\"S\" disseminationControls=\"FOUO\" ownerProducer=\"USA\" xmlns=\"http://example.gov/IC-ISM/0\"/>", payload.getEquivalentLabels().toArray()[0]); + assertEquals("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>", 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( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" + + "<item selector='Classified|SECRET'>" + + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + + "</securitylabel>" + + "</item>" + + "<item selector='Classified|CONFIDENTIAL' default='true'>" + + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + + "</securitylabel>" + + "</item>" + + "<item selector='Unclassified|UNCLASSIFIED'/>" + + "</catalog>")); + + 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("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>", 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("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>", 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("<query xmlns=\"jabber:iq:version\">" + + "<name>myclient</name>" + + "<version>1.0</version>" + + "<os>Mac OS X</os>" + + "</query>")); + + 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("<status>foo<baz>bar</baz>fum</status>")); + + 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("<show>invalid</show>")); + + 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("<show>away</show>")); + + 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("<show>chat</show>")); + + 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("<show>xa</show>")); + + 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("<show>dnd</show>")); + + 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( + "<vCard xmlns=\"vcard-temp\">" + + "<VERSION>2.0</VERSION>" + + "<FN>Alice In Wonderland</FN>" + + "<N>" + + "<FAMILY>Wonderland</FAMILY>" + + "<GIVEN>Alice</GIVEN>" + + "<MIDDLE>In</MIDDLE>" + + "<PREFIX>Mrs</PREFIX>" + + "<SUFFIX>PhD</SUFFIX>" + + "</N>" + + "<EMAIL>" + + "<USERID>alice@wonderland.lit</USERID>" + + "<HOME/>" + + "<INTERNET/>" + + "<PREF/>" + + "</EMAIL>" + + "<EMAIL>" + + "<USERID>alice@teaparty.lit</USERID>" + + "<WORK/>" + + "<X400/>" + + "</EMAIL>" + + "<TEL>" + + "<NUMBER>555-6273</NUMBER>" + + "<HOME/>" + + "<VOICE/>" + + "</TEL>" + + "<ADR>" + + "<LOCALITY>Any Town</LOCALITY>" + + "<STREET>Fake Street 123</STREET>" + + "<PCODE>12345</PCODE>" + + "<CTRY>USA</CTRY>" + + "<HOME/>" + + "</ADR>" + + "<LABEL>" + + "<LINE>Fake Street 123</LINE>" + + "<LINE>12345 Any Town</LINE>" + + "<LINE>USA</LINE>" + + "<HOME/>" + + "</LABEL>" + + "<NICKNAME>DreamGirl</NICKNAME>" + + "<BDAY>1865-05-04T00:00:00Z</BDAY>" + + "<JID>alice@teaparty.lit</JID>" + + "<JID>alice@wonderland.lit</JID>" + + "<DESC>I once fell down a rabbit hole.</DESC>" + + "<ORG>" + + "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" + + "</ORG>" + + "<TITLE>Some Title</TITLE>" + + "<ROLE>Main Character</ROLE>" + + "<URL>http://wonderland.lit/~alice</URL>" + + "<URL>http://teaparty.lit/~alice2</URL>" + + "<MAILER>mutt</MAILER>" + + "</vCard>")); + + 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(("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload.getUnknownContent()); + } + + @Test + public void testParse_Photo() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "<vCard xmlns='vcard-temp'>" + + "<PHOTO>" + + "<TYPE>image/jpeg</TYPE>" + + "<BINVAL>" + + "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ej" + + "EyMzQ1Njc4OTA=" + + "</BINVAL>" + + "</PHOTO>" + + "</vCard>")); + + 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( + "<vCard xmlns='vcard-temp'>" + + "<PHOTO>" + + "<TYPE>image/jpeg</TYPE>" + + "<BINVAL>" + + "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n" + + "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n" + + "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n" + + "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n" + + "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo=" + + "</BINVAL>" + + "</PHOTO>" + + "</vCard>")); + + 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( + "<vCard xmlns='vcard-temp'>" + + "<NICKNAME>mynick</NICKNAME>" + + "</vCard>")); + + 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 = "<request xmlns=\"urn:xmpp:receipts\"/>"; + + DeliveryReceiptRequest receipt = new DeliveryReceiptRequest(); + + DeliveryReceiptRequestSerializer serializer = new DeliveryReceiptRequestSerializer(); + assertEquals(expected, serializer.serializePayload(receipt)); + } + + @Test + public void testSerialize_XEP0184Example4() { + String expected = "<received id=\"richard2-4.1.247\" xmlns=\"urn:xmpp:receipts\"/>"; + + 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 = + "<query node=\"http://swift.im#bla\" xmlns=\"http://jabber.org/protocol/disco#info\">" + + "<identity category=\"client\" name=\"Swift\" type=\"pc\"/>" + + "<identity category=\"client\" name=\"Vlug\" type=\"pc\" xml:lang=\"nl\"/>" + + "<feature var=\"http://jabber.org/protocol/caps\"/>" + + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + + "</query>"; + + 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 = + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + + "<feature var=\"http://jabber.org/protocol/caps\"/>" + + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + + "<x type=\"form\" xmlns=\"jabber:x:data\">" + + "<title>Bot Configuration</title>" + + "</x>" + + "</query>"; + + 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("<replace id = 'bad1' xmlns='urn:xmpp:message-correct:0'/>", 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( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + + "<jid>somenode@example.com/someresource</jid>" + + "</bind>", testling.serialize(resourceBind)); + } + + @Test + public void testSerialize_Resource() { + ResourceBindSerializer testling = new ResourceBindSerializer(); + ResourceBind resourceBind = new ResourceBind(); + resourceBind.setResource("someresource"); + + assertEquals( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + + "<resource>someresource</resource>" + + "</bind>", testling.serialize(resourceBind)); + } + + @Test + public void testSerialize_Empty() { + ResourceBindSerializer testling = new ResourceBindSerializer(); + ResourceBind resourceBind = new ResourceBind(); + + assertEquals("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>", 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("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + securityLabel.addEquivalentLabel("<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>"); + securityLabel.addEquivalentLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"); + + assertEquals( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + + "<label>" + + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + + "</label>" + + "<equivalentlabel>" + + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + + "</equivalentlabel>" + + "<equivalentlabel>" + + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + + "</equivalentlabel>" + + "</securitylabel>", testling.serialize(securityLabel)); + } + + @Test + public void testSerialize_EmptyLabel() { + SecurityLabelSerializer testling = new SecurityLabelSerializer(); + SecurityLabel securityLabel = new SecurityLabel(); + securityLabel.setDisplayMarking("SECRET"); + securityLabel.setLabel(""); + + assertEquals( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking>SECRET</displaymarking>" + + "<label></label>" + + "</securitylabel>", 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("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + 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("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"); + catalog.addItem(item2); + + SecurityLabelsCatalog.Item item3 = new SecurityLabelsCatalog.Item(); + item3.setSelector("Unclassified|UNCLASSIFIED"); + catalog.addItem(item3); + + assertEquals( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" + + "<item selector=\"Classified|SECRET\">" + + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + + "</securitylabel>" + + "</item>" + + "<item default=\"true\" selector=\"Classified|CONFIDENTIAL\">" + + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + + "</securitylabel>" + + "</item>" + + "<item selector=\"Unclassified|UNCLASSIFIED\"/>" + + "</catalog>", 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 = "<query xmlns=\"jabber:iq:version\"><name>Swift</name><version>0.1</version><os>Mac OS X</os></query>"; + 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 = "<status>I am away</status>"; + 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("<show>away</show>", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_FFC() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.FFC); + assertEquals("<show>chat</show>", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_XA() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.XA); + assertEquals("<show>xa</show>", testling.serialize(statusShow)); + } + + @Test + public void testSerialize_DND() { + StatusShowSerializer testling = new StatusShowSerializer(); + StatusShow statusShow = new StatusShow(StatusShow.Type.DND); + assertEquals("<show>dnd</show>", 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("<MAILER>mutt</MAILER>"); + + 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 = + "<vCard xmlns=\"vcard-temp\">" + + "<VERSION>2.0</VERSION>" + + "<FN>Alice In Wonderland</FN>" + + "<N>" + + "<FAMILY>Wonderland</FAMILY>" + + "<GIVEN>Alice</GIVEN>" + + "<MIDDLE>In</MIDDLE>" + + "<PREFIX>Mrs</PREFIX>" + + "<SUFFIX>PhD</SUFFIX>" + + "</N>" + + "<EMAIL>" + + "<USERID>alice@wonderland.lit</USERID>" + + "<HOME/>" + + "<INTERNET/>" + + "<PREF/>" + + "</EMAIL>" + + "<EMAIL>" + + "<USERID>alice@teaparty.lit</USERID>" + + "<WORK/>" + + "<X400/>" + + "</EMAIL>" + + "<NICKNAME>DreamGirl</NICKNAME>" + + "<PHOTO>" + + "<TYPE>image/png</TYPE>" + + "<BINVAL>YWJjZGVm</BINVAL>" + + "</PHOTO>" + + "<BDAY>1865-05-04T00:00:00Z</BDAY>" + + "<TEL>" + + "<NUMBER>555-6273</NUMBER>" + + "<HOME/>" + + "<VOICE/>" + + "</TEL>" + + "<ADR>" + + "<STREET>Fake Street 123</STREET>" + + "<LOCALITY>Any Town</LOCALITY>" + + "<PCODE>12345</PCODE>" + + "<CTRY>USA</CTRY>" + + "<HOME/>" + + "</ADR>" + + "<LABEL>" + + "<LINE>Fake Street 123</LINE>" + + "<LINE>12345 Any Town</LINE>" + + "<LINE>USA</LINE>" + + "<HOME/>" + + "</LABEL>" + + "<JID>alice@teaparty.lit</JID>" + + "<JID>alice@wonderland.lit</JID>" + + "<DESC>I once fell down a rabbit hole.</DESC>" + + "<ORG>" + + "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" + + "</ORG>" + + "<TITLE>Some Title</TITLE>" + + "<ROLE>Main Character</ROLE>" + + "<URL>http://wonderland.lit/~alice</URL>" + + "<URL>http://teaparty.lit/~alice2</URL>" + + "<MAILER>mutt</MAILER>" + + "</vCard>"; + + assertEquals(expectedResult, testling.serialize(vcard)); + } +}
\ No newline at end of file |