From ae1f4d65b253fa1a263556be7419836a37683dd2 Mon Sep 17 00:00:00 2001 From: Tarun Gupta Date: Tue, 23 Jun 2015 01:59:55 +0530 Subject: Adds tests for Parser and Serializers. Adds PubSubEvent Element. Adds StreamFeaturesSerializer. Adds ParserTester, ElementParserTester, StanzaParserTester, PayloadParserTester, PayloadsSerializer and EnumParser. Updates Error Payload, JingleFIleTransferHash Elements/ Updates StreamFeaturesParser, ParserElement. Updates Delay Serializer, Error Serializer. Updates AuthChallenge and AuthRequest Element. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Test are added for: AuthChallenge Serializer, AuthRequest Serializer, AuthResponse Serializer, AuthSuccess Serializer. GenericPayloadTreeParserTest. IQ Parser. Message Parser. Presence Parser. StanzaAck Parser. Stanza Parser. StreamFeatures Parser and Serializer. StreamManagementEnabled Parser. Private Storage Parser and Serializer. RawXMLPayload Parser. Storage Parser and Serializer. Error Serializer. Jingle Serializer. PubSubItem Serializer and PubSubItems Serializer. Serializing Parser. All tests passes. Change-Id: I79e00dc5b5c4f85e659bf88b1547dd7c17825805 diff --git a/src/com/isode/stroke/base/SafeByteArray.java b/src/com/isode/stroke/base/SafeByteArray.java index af43261..d6f817a 100644 --- a/src/com/isode/stroke/base/SafeByteArray.java +++ b/src/com/isode/stroke/base/SafeByteArray.java @@ -12,6 +12,10 @@ import com.isode.stroke.base.ByteArray; */ public class SafeByteArray extends ByteArray { + public SafeByteArray() { + + } + public SafeByteArray(String s) { super(s); } diff --git a/src/com/isode/stroke/elements/AuthChallenge.java b/src/com/isode/stroke/elements/AuthChallenge.java index 552af13..d83c19e 100644 --- a/src/com/isode/stroke/elements/AuthChallenge.java +++ b/src/com/isode/stroke/elements/AuthChallenge.java @@ -13,7 +13,7 @@ import com.isode.stroke.base.ByteArray; public class AuthChallenge implements Element { //FIXME: parser/serialiser public AuthChallenge() { - value_ = new ByteArray(); + } public AuthChallenge(ByteArray value) { diff --git a/src/com/isode/stroke/elements/AuthRequest.java b/src/com/isode/stroke/elements/AuthRequest.java index 291d31d..97ac8a0 100644 --- a/src/com/isode/stroke/elements/AuthRequest.java +++ b/src/com/isode/stroke/elements/AuthRequest.java @@ -41,6 +41,6 @@ public class AuthRequest implements Element { public void setMechanism(String mechanism) { mechanism_ = mechanism; } - private String mechanism_; - private ByteArray message_ = new ByteArray(); -} + private String mechanism_ = ""; + private ByteArray message_; +} \ No newline at end of file diff --git a/src/com/isode/stroke/elements/ErrorPayload.java b/src/com/isode/stroke/elements/ErrorPayload.java index 42e9c61..103115c 100644 --- a/src/com/isode/stroke/elements/ErrorPayload.java +++ b/src/com/isode/stroke/elements/ErrorPayload.java @@ -15,7 +15,7 @@ package com.isode.stroke.elements; public class ErrorPayload extends Payload { private Condition condition_; private Type type_; - private String text_; + private String text_ = ""; private Payload payload_; public enum Type { Cancel, Continue, Modify, Auth, Wait }; diff --git a/src/com/isode/stroke/elements/JingleFileTransferHash.java b/src/com/isode/stroke/elements/JingleFileTransferHash.java index b018549..4c22da5 100644 --- a/src/com/isode/stroke/elements/JingleFileTransferHash.java +++ b/src/com/isode/stroke/elements/JingleFileTransferHash.java @@ -23,7 +23,7 @@ import com.isode.stroke.base.NotNull; public class JingleFileTransferHash extends Payload { - private JingleFileTransferFileInfo fileInfo_; + private JingleFileTransferFileInfo fileInfo_ = new JingleFileTransferFileInfo(); /** * Default Constructor. diff --git a/src/com/isode/stroke/elements/PubSubEvent.java b/src/com/isode/stroke/elements/PubSubEvent.java new file mode 100644 index 0000000..6d5e3d2 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEvent.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2013 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.elements; + +import com.isode.stroke.elements.ContainerPayload; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEvent extends ContainerPayload { + +} \ No newline at end of file diff --git a/src/com/isode/stroke/elements/StreamFeatures.java b/src/com/isode/stroke/elements/StreamFeatures.java index 39ebb04..db38dd2 100644 --- a/src/com/isode/stroke/elements/StreamFeatures.java +++ b/src/com/isode/stroke/elements/StreamFeatures.java @@ -73,6 +73,14 @@ public class StreamFeatures implements Element { return !authenticationMechanisms_.isEmpty(); } + public String getAuthenticationHostname() { + return authenticationHostname_; + } + + public void setAuthenticationHostname(String authenticationHostname) { + authenticationHostname_ = authenticationHostname; + } + public boolean hasStreamManagement() { return hasStreamManagement_; } @@ -106,4 +114,5 @@ public class StreamFeatures implements Element { private boolean hasSession_; private boolean hasStreamManagement_; private boolean hasRosterVersioning_; + private String authenticationHostname_; } diff --git a/src/com/isode/stroke/parser/EnumParser.java b/src/com/isode/stroke/parser/EnumParser.java new file mode 100644 index 0000000..2d35c79 --- /dev/null +++ b/src/com/isode/stroke/parser/EnumParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 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; + +import java.util.Map; +import java.util.HashMap; + +public class EnumParser { + + private Map values = new HashMap(); + + public EnumParser() { + + } + + public EnumParser addValue(T value, String text) { + values.put(text, value); + return this; + } + + public T parse(String value) { + if(values.containsKey(value)) { + return values.get(value); + } else { + return null; + } + } +} \ No newline at end of file diff --git a/src/com/isode/stroke/parser/StreamFeaturesParser.java b/src/com/isode/stroke/parser/StreamFeaturesParser.java index 5c98268..ee4f9dc 100644 --- a/src/com/isode/stroke/parser/StreamFeaturesParser.java +++ b/src/com/isode/stroke/parser/StreamFeaturesParser.java @@ -31,6 +31,8 @@ class StreamFeaturesParser extends GenericElementParser { inMechanisms_ = true; } else if (element.equals("compression") && ns.equals("http://jabber.org/features/compress")) { inCompression_ = true; + } else if (element.equals("ver") && ns.equals("urn:xmpp:features:rosterver")) { + getElementGeneric().setHasRosterVersioning(); } } else if (currentDepth_ == 2) { if (inCompression_ && element.equals("method")) { @@ -39,6 +41,9 @@ class StreamFeaturesParser extends GenericElementParser { } else if (inMechanisms_ && element.equals("mechanism")) { inMechanism_ = true; currentText_ = ""; + } else if (inMechanisms_ && element.equals("hostname") && ns.equals("urn:xmpp:domain-based-name:1")) { + inAuthenticationHostname_ = true; + currentText_ = ""; } } ++currentDepth_; @@ -57,6 +62,9 @@ class StreamFeaturesParser extends GenericElementParser { } else if (inMechanism_) { getElementGeneric().addAuthenticationMechanism(currentText_); inMechanism_ = false; + } else if (inAuthenticationHostname_) { + getElementGeneric().setAuthenticationHostname(currentText_); + inAuthenticationHostname_ = false; } } } @@ -71,4 +79,5 @@ class StreamFeaturesParser extends GenericElementParser { private boolean inMechanism_ = false; private boolean inCompression_ = false; private boolean inCompressionMethod_ = false; + private boolean inAuthenticationHostname_ = false; } diff --git a/src/com/isode/stroke/serializer/AuthRequestSerializer.java b/src/com/isode/stroke/serializer/AuthRequestSerializer.java index 2eaed47..318eab8 100644 --- a/src/com/isode/stroke/serializer/AuthRequestSerializer.java +++ b/src/com/isode/stroke/serializer/AuthRequestSerializer.java @@ -35,4 +35,4 @@ class AuthRequestSerializer extends GenericElementSerializer { return "" + value + ""; } -} +} \ No newline at end of file diff --git a/src/com/isode/stroke/serializer/AuthResponseSerializer.java b/src/com/isode/stroke/serializer/AuthResponseSerializer.java index 8deb9b8..97bf91a 100644 --- a/src/com/isode/stroke/serializer/AuthResponseSerializer.java +++ b/src/com/isode/stroke/serializer/AuthResponseSerializer.java @@ -25,7 +25,7 @@ class AuthResponseSerializer extends GenericElementSerializer { ByteArray message = authResponse.getValue(); if (message != null) { if (message.isEmpty()) { - value = "="; + value = ""; } else { value = Base64.encode(message); } diff --git a/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java b/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java new file mode 100644 index 0000000..b5eb598 --- /dev/null +++ b/src/com/isode/stroke/serializer/StreamFeaturesSerializer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010-2014 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; + +import com.isode.stroke.serializer.GenericElementSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLTextNode; +import com.isode.stroke.elements.StreamFeatures; +import com.isode.stroke.elements.Element; + +public class StreamFeaturesSerializer extends GenericElementSerializer { + + public StreamFeaturesSerializer() { + super(StreamFeatures.class); + } + + public String serialize(Element element) { + StreamFeatures streamFeatures = (StreamFeatures)(element); + + XMLElement streamFeaturesElement = new XMLElement("stream:features"); + if (streamFeatures.hasStartTLS()) { + streamFeaturesElement.addNode(new XMLElement("starttls", "urn:ietf:params:xml:ns:xmpp-tls")); + } + if (!streamFeatures.getCompressionMethods().isEmpty()) { + XMLElement compressionElement = new XMLElement("compression", "http://jabber.org/features/compress"); + for(String method : streamFeatures.getCompressionMethods()) { + XMLElement methodElement = new XMLElement("method"); + methodElement.addNode(new XMLTextNode(method)); + compressionElement.addNode(methodElement); + } + streamFeaturesElement.addNode(compressionElement); + } + if (!streamFeatures.getAuthenticationMechanisms().isEmpty()) { + XMLElement mechanismsElement = new XMLElement("mechanisms", "urn:ietf:params:xml:ns:xmpp-sasl"); + for(String mechanism : streamFeatures.getAuthenticationMechanisms()) { + XMLElement mechanismElement = new XMLElement("mechanism"); + mechanismElement.addNode(new XMLTextNode(mechanism)); + mechanismsElement.addNode(mechanismElement); + } + streamFeaturesElement.addNode(mechanismsElement); + } + if (streamFeatures.hasResourceBind()) { + streamFeaturesElement.addNode(new XMLElement("bind", "urn:ietf:params:xml:ns:xmpp-bind")); + } + if (streamFeatures.hasSession()) { + streamFeaturesElement.addNode(new XMLElement("session", "urn:ietf:params:xml:ns:xmpp-session")); + } + if (streamFeatures.hasStreamManagement()) { + streamFeaturesElement.addNode(new XMLElement("sm", "urn:xmpp:sm:2")); + } + if (streamFeatures.hasRosterVersioning()) { + streamFeaturesElement.addNode(new XMLElement("ver", "urn:xmpp:features:rosterver")); + } + return streamFeaturesElement.serialize(); + } +} \ No newline at end of file diff --git a/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java index f54f38f..38e1eba 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java @@ -25,7 +25,8 @@ public class DelaySerializer extends GenericPayloadSerializer { if (delay.getFrom() != null && delay.getFrom().isValid()) { delayElement.setAttribute("from", delay.getFrom().toString()); } - delayElement.setAttribute("stamp", DateTime.dateToString(delay.getStamp())); + if(delay.getStamp() != null) + delayElement.setAttribute("stamp", DateTime.dateToString(delay.getStamp())); return delayElement.serialize(); } } diff --git a/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java index 33d064d..47373f8 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/ErrorSerializer.java @@ -12,11 +12,16 @@ package com.isode.stroke.serializer.payloadserializers; import com.isode.stroke.elements.ErrorPayload; import com.isode.stroke.serializer.GenericPayloadSerializer; import com.isode.stroke.serializer.xml.XMLTextNode; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.PayloadSerializer; class ErrorSerializer extends GenericPayloadSerializer { - public ErrorSerializer() { + private PayloadSerializerCollection serializers; + + public ErrorSerializer(PayloadSerializerCollection serializers) { super(ErrorPayload.class); + this.serializers = serializers; } @Override @@ -63,6 +68,13 @@ class ErrorSerializer extends GenericPayloadSerializer { result += "" + textNode.serialize() + ""; } + if (error.getPayload() != null) { + PayloadSerializer serializer = serializers.getPayloadSerializer(error.getPayload()); + if (serializer != null) { + result += serializer.serialize(error.getPayload()); + } + } + result += ""; return result; } diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index 001d126..ac093c0 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -26,7 +26,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection addSerializer(new CarbonsReceivedSerializer(this)); addSerializer(new CarbonsSentSerializer(this)); addSerializer(new PrioritySerializer()); - addSerializer(new ErrorSerializer()); + addSerializer(new ErrorSerializer(this)); addSerializer(new InBandRegistrationPayloadSerializer()); addSerializer(new IBBSerializer()); addSerializer(new JingleIBBTransportPayloadSerializer()); diff --git a/test/com/isode/stroke/parser/AttributeMapTest.java b/test/com/isode/stroke/parser/AttributeMapTest.java new file mode 100644 index 0000000..45f5a4c --- /dev/null +++ b/test/com/isode/stroke/parser/AttributeMapTest.java @@ -0,0 +1,91 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.AttributeMap; + +public class AttributeMapTest { + + public AttributeMapTest() { + + } + + @Test + public void testGetAttribute_Namespaced() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("lang", "", "nl"); + testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); + testling.addAttribute("lang", "", "fr"); + + assertEquals("en", testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); + } + + @Test + public void testGetBoolAttribute_True() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("foo", "", "true"); + + assertTrue(testling.getBoolAttribute("foo")); + } + + @Test + public void testGetBoolAttribute_1() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("foo", "", "1"); + + assertTrue(testling.getBoolAttribute("foo")); + } + + @Test + public void testGetBoolAttribute_False() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("foo", "", "false"); + + assertFalse(testling.getBoolAttribute("foo", true)); + } + + @Test + public void testGetBoolAttribute_0() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("foo", "", "0"); + + assertFalse(testling.getBoolAttribute("foo", true)); + } + + @Test + public void testGetBoolAttribute_Invalid() { + AttributeMap testling = new AttributeMap(); + testling.addAttribute("foo", "", "bla"); + + assertFalse(testling.getBoolAttribute("foo", true)); + } + + @Test + public void testGetBoolAttribute_UnknownWithDefaultTrue() { + AttributeMap testling = new AttributeMap(); + + assertTrue(testling.getBoolAttribute("foo", true)); + } + + @Test + public void testGetBoolAttribute_UnknownWithDefaultFalse() { + AttributeMap testling = new AttributeMap(); + + assertFalse(testling.getBoolAttribute("foo", false)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/ElementParserTester.java b/test/com/isode/stroke/parser/ElementParserTester.java new file mode 100644 index 0000000..d8a0252 --- /dev/null +++ b/test/com/isode/stroke/parser/ElementParserTester.java @@ -0,0 +1,47 @@ +/* + * 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; + +import com.isode.stroke.parser.XMLParser; +import com.isode.stroke.eventloop.EventLoop; +import com.isode.stroke.parser.XMLParserClient; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.ElementParser; +import com.isode.stroke.parser.PlatformXMLParserFactory; + +public class ElementParserTester implements XMLParserClient { + + private XMLParser xmlParser_; + private ParserType parser_; + + public ElementParserTester(ParserType parser) { + this.parser_ = parser; + xmlParser_ = PlatformXMLParserFactory.createXMLParser(this); + } + + public boolean parse(String data) { + return xmlParser_.parse(data); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + parser_.handleStartElement(element, ns, attributes); + } + + public void handleEndElement(String element, String ns) { + parser_.handleEndElement(element, ns); + } + + public void handleCharacterData(String data) { + parser_.handleCharacterData(data); + } +} + diff --git a/test/com/isode/stroke/parser/EnumParserTest.java b/test/com/isode/stroke/parser/EnumParserTest.java new file mode 100644 index 0000000..aa20873 --- /dev/null +++ b/test/com/isode/stroke/parser/EnumParserTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.EnumParser; + +public class EnumParserTest { + + public EnumParserTest() { + + } + + public enum MyEnum { + MyValue1, + MyValue2, + MyValue3 + }; + + @Test + public void testParse() { + EnumParser parser = new EnumParser(); + parser.addValue(MyEnum.MyValue1, "my-value-1"); + parser.addValue(MyEnum.MyValue2, "my-value-2"); + parser.addValue(MyEnum.MyValue3, "my-value-3"); + assertEquals(MyEnum.MyValue2, parser.parse("my-value-2")); + } + + @Test + public void testParse_NoValue() { + EnumParser parser = new EnumParser(); + parser.addValue(MyEnum.MyValue1, "my-value-1"); + parser.addValue(MyEnum.MyValue2, "my-value-2"); + parser.addValue(MyEnum.MyValue3, "my-value-3"); + assertNull(parser.parse("my-value-4")); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java b/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java new file mode 100644 index 0000000..1021eae --- /dev/null +++ b/test/com/isode/stroke/parser/GenericPayloadTreeParserTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2011 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.GenericPayloadTreeParser; +import com.isode.stroke.elements.RawXMLPayload; +import com.isode.stroke.parser.tree.ParserElement; +import com.isode.stroke.parser.tree.NullParserElement; +import com.isode.stroke.parser.payloadparsers.PayloadParserTester; + +public class GenericPayloadTreeParserTest { + + public GenericPayloadTreeParserTest() { + + } + + private class MyParser extends GenericPayloadTreeParser { + + public MyParser() { + super(new RawXMLPayload()); + } + + public void handleTree(ParserElement root) { + tree = root; + } + + public ParserElement tree; + } + + @Test + public void testTree() { + MyParser testling = new MyParser(); + + String data = ""; + + PayloadParserTester tester = new PayloadParserTester(testling); + tester.parse(data); + + ParserElement tree = testling.tree; + + assertEquals("topLevel", tree.getName()); + assertEquals("urn:test:top", tree.getNamespace()); + assertNotNull(tree.getChild("firstLevelInheritedEmpty", "urn:test:top")); + assertTrue(tree.getChild("firstLevelInheritedEmpty", "") instanceof NullParserElement); + assertNotNull(tree.getChild("firstLevelInherited", "urn:test:top")); + assertEquals(2, tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").size()); + assertEquals("1", tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").get(0).getAttributes().getAttribute("num")); + assertEquals("2", tree.getChild("firstLevelInherited", "urn:test:top").getChildren("secondLevelMultiChildren", "urn:test:top").get(1).getAttributes().getAttribute("num")); + assertNotNull(tree.getChild("firstLevelNS", "urn:test:first")); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/IQParserTest.java b/test/com/isode/stroke/parser/IQParserTest.java new file mode 100644 index 0000000..603caec --- /dev/null +++ b/test/com/isode/stroke/parser/IQParserTest.java @@ -0,0 +1,79 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.StanzaParserTester; +import com.isode.stroke.parser.IQParser; +import com.isode.stroke.elements.IQ; + +public class IQParserTest { + + private PayloadParserFactoryCollection factoryCollection_; + + public IQParserTest() { + + } + + @Before + public void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } + + @Test + public void testParse_Set() { + IQParser testling = new IQParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(IQ.Type.Set, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Get() { + IQParser testling = new IQParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(IQ.Type.Get, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Result() { + IQParser testling = new IQParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(IQ.Type.Result, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Error() { + IQParser testling = new IQParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(IQ.Type.Error, testling.getStanzaGeneric().getType()); + } + +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/MessageParserTest.java b/test/com/isode/stroke/parser/MessageParserTest.java new file mode 100644 index 0000000..5b5e08a --- /dev/null +++ b/test/com/isode/stroke/parser/MessageParserTest.java @@ -0,0 +1,89 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.StanzaParserTester; +import com.isode.stroke.parser.MessageParser; +import com.isode.stroke.elements.Message; + +public class MessageParserTest { + + private PayloadParserFactoryCollection factoryCollection_; + + public MessageParserTest() { + + } + + @Before + public void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } + + @Test + public void testParse_Chat() { + MessageParser testling = new MessageParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Message.Type.Chat, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Groupchat() { + MessageParser testling = new MessageParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Message.Type.Groupchat, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Error() { + MessageParser testling = new MessageParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Message.Type.Error, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Headline() { + MessageParser testling = new MessageParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Message.Type.Headline, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Normal() { + MessageParser testling = new MessageParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Message.Type.Normal, testling.getStanzaGeneric().getType()); + } + +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/ParserTester.java b/test/com/isode/stroke/parser/ParserTester.java new file mode 100644 index 0000000..90c9586 --- /dev/null +++ b/test/com/isode/stroke/parser/ParserTester.java @@ -0,0 +1,47 @@ +/* + * 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; + +import com.isode.stroke.parser.XMLParser; +import com.isode.stroke.eventloop.EventLoop; +import com.isode.stroke.parser.XMLParserClient; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.ElementParser; +import com.isode.stroke.parser.PlatformXMLParserFactory; + +public class ParserTester implements XMLParserClient { + + private XMLParser xmlParser_; + private ParserType parser_; + + public ParserTester(ParserType parser) { + this.parser_ = parser; + xmlParser_ = PlatformXMLParserFactory.createXMLParser(this); + } + + public boolean parse(String data) { + return xmlParser_.parse(data); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + parser_.handleStartElement(element, ns, attributes); + } + + public void handleEndElement(String element, String ns) { + parser_.handleEndElement(element, ns); + } + + public void handleCharacterData(String data) { + parser_.handleCharacterData(data); + } +} + diff --git a/test/com/isode/stroke/parser/PresenceParserTest.java b/test/com/isode/stroke/parser/PresenceParserTest.java new file mode 100644 index 0000000..bcd617a --- /dev/null +++ b/test/com/isode/stroke/parser/PresenceParserTest.java @@ -0,0 +1,118 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.StanzaParserTester; +import com.isode.stroke.parser.PresenceParser; +import com.isode.stroke.elements.Presence; + +public class PresenceParserTest { + + private PayloadParserFactoryCollection factoryCollection_; + + public PresenceParserTest() { + + } + + @Before + public void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + } + + @Test + public void testParse_Available() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Available, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Unavailable() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Unavailable, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Probe() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Probe, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Subscribe() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Subscribe, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Subscribed() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Subscribed, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Unsubscribe() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Unsubscribe, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Unsubscribed() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Unsubscribed, testling.getStanzaGeneric().getType()); + } + + @Test + public void testParse_Error() { + PresenceParser testling = new PresenceParser(factoryCollection_); + StanzaParserTester parser = new StanzaParserTester(testling); + + assertTrue(parser.parse("")); + + assertEquals(Presence.Type.Error, testling.getStanzaGeneric().getType()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/SerializingParserTest.java b/test/com/isode/stroke/parser/SerializingParserTest.java new file mode 100644 index 0000000..eff8d6a --- /dev/null +++ b/test/com/isode/stroke/parser/SerializingParserTest.java @@ -0,0 +1,74 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.SerializingParser; +import com.isode.stroke.parser.XMLParserClient; +import com.isode.stroke.parser.ParserTester; +import com.isode.stroke.parser.AttributeMap; + +public class SerializingParserTest { + + private class ToTestSerializingParser extends SerializingParser implements XMLParserClient { + + } + + public SerializingParserTest() { + + } + + @Test + public void testParse() { + ToTestSerializingParser testling = new ToTestSerializingParser(); + ParserTester parser = new ParserTester(testling); + + assertTrue(parser.parse( + "" + + "Hello<&World" + + "" + + "foobarbaz" + + "" + + "")); + + assertEquals( + "" + + "Hello<&World" + + "foobarbaz" + + "", testling.getResult()); + } + + @Test + public void testParse_Empty() { + ToTestSerializingParser testling = new ToTestSerializingParser(); + + assertEquals("", testling.getResult()); + } + + @Test + public void testParse_ToplevelCharacterData() { + ToTestSerializingParser testling = new ToTestSerializingParser(); + + AttributeMap attributes = new AttributeMap(); + testling.handleCharacterData("foo"); + testling.handleStartElement("message", "", attributes); + testling.handleEndElement("message", ""); + testling.handleCharacterData("bar"); + + assertEquals("", testling.getResult()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/StanzaAckParserTest.java b/test/com/isode/stroke/parser/StanzaAckParserTest.java new file mode 100644 index 0000000..ad6b951 --- /dev/null +++ b/test/com/isode/stroke/parser/StanzaAckParserTest.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.parser; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.StanzaAckParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.ElementParserTester; + +public class StanzaAckParserTest { + + public StanzaAckParserTest() { + + } + + @Test + public void testParse() { + StanzaAckParser testling = new StanzaAckParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse("")); + + assertTrue(testling.getElementGeneric().isValid()); + assertEquals(12, testling.getElementGeneric().getHandledStanzasCount()); + } + + @Test + public void testParse_Invalid() { + StanzaAckParser testling = new StanzaAckParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse("")); + + assertFalse(testling.getElementGeneric().isValid()); + } + + @Test + public void testParse_Empty() { + StanzaAckParser testling = new StanzaAckParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse("")); + + assertFalse(testling.getElementGeneric().isValid()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/StanzaParserTest.java b/test/com/isode/stroke/parser/StanzaParserTest.java new file mode 100644 index 0000000..de10d44 --- /dev/null +++ b/test/com/isode/stroke/parser/StanzaParserTest.java @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2010-2014 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.parser.StanzaParser; +import com.isode.stroke.parser.PayloadParserFactory; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Stanza; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.Element; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.jid.JID; + +public class StanzaParserTest { + + public StanzaParserTest() { + + } + + private class MyPayload1 extends Payload { + + public MyPayload1() { + this.hasChild = false; + } + + public boolean hasChild; + } + + private class MyPayload1Parser extends GenericPayloadParser { + + public MyPayload1Parser() { + super(new MyPayload1()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (!element.equals("mypayload1")) { + getPayloadInternal().hasChild = true; + } + } + + public void handleEndElement(String element, String ns) {} + public void handleCharacterData(String data) {} + } + + private class MyPayload1ParserFactory implements PayloadParserFactory { + + public MyPayload1ParserFactory() { + + } + + public PayloadParser createPayloadParser() { + return new MyPayload1Parser(); + } + + public boolean canParse(String element, String ns, AttributeMap attributes) { + return element.equals("mypayload1"); + } + } + + private class MyPayload2 extends Payload { + + public MyPayload2() { + + } + } + + private class MyPayload2Parser extends GenericPayloadParser { + + public MyPayload2Parser() { + super(new MyPayload2()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) {} + public void handleEndElement(String element, String ns) {} + public void handleCharacterData(String data) {} + } + + private class MyPayload2ParserFactory implements PayloadParserFactory { + + public MyPayload2ParserFactory() { + + } + + public PayloadParser createPayloadParser() { + return new MyPayload2Parser(); + } + + public boolean canParse(String element, String ns, AttributeMap attributes) { + return element.equals("mypayload2"); + } + } + + + private class MyStanza extends Stanza { + + public MyStanza() {} + } + + private class MyStanzaParser extends StanzaParser { + + public MyStanzaParser(PayloadParserFactoryCollection collection) { + super(collection); + stanza_ = new MyStanza(); + } + + public Element getElement() { + return stanza_; + } + + private MyStanza stanza_; + } + + private MyPayload1ParserFactory factory1_ = new MyPayload1ParserFactory(); + private MyPayload2ParserFactory factory2_ = new MyPayload2ParserFactory(); + private PayloadParserFactoryCollection factoryCollection_; + + @Before + public void setUp() { + factoryCollection_ = new PayloadParserFactoryCollection(); + factoryCollection_.addFactory(factory1_); + factoryCollection_.addFactory(factory2_); + } + + @Test + public void testHandleEndElement_OnePayload() { + MyStanzaParser testling = new MyStanzaParser(factoryCollection_); + + AttributeMap attributes = new AttributeMap(); + attributes.addAttribute("foo", "", "fum"); + attributes.addAttribute("bar", "", "baz"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleStartElement("child", "", attributes); + testling.handleEndElement("child", ""); + testling.handleEndElement("mypayload1", ""); + testling.handleEndElement("mystanza", ""); + + assertNotNull(testling.getStanza().getPayload(new MyPayload1())); + assertTrue(testling.getStanza().getPayload(new MyPayload1()).hasChild); + } + + @Test + public void testHandleEndElement_MultiplePayloads() { + MyStanzaParser testling = new MyStanzaParser(factoryCollection_); + + AttributeMap attributes = new AttributeMap(); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + assertNotNull(testling.getStanza().getPayload(new MyPayload1())); + assertNotNull(testling.getStanza().getPayload(new MyPayload2())); + } + + @Test + public void testHandleEndElement_StrayCharacterData() { + MyStanzaParser testling = new MyStanzaParser(factoryCollection_); + + AttributeMap attributes = new AttributeMap(); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleCharacterData("bla"); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + assertNotNull(testling.getStanza().getPayload(new MyPayload1())); + assertNotNull(testling.getStanza().getPayload(new MyPayload2())); + } + + @Test + public void testHandleEndElement_UnknownPayload() { + MyStanzaParser testling = new MyStanzaParser(factoryCollection_); + + AttributeMap attributes = new AttributeMap(); + testling.handleStartElement("mystanza", "", attributes); + testling.handleStartElement("mypayload1", "", attributes); + testling.handleEndElement("mypayload1", ""); + testling.handleStartElement("unknown-payload", "", attributes); + testling.handleStartElement("unknown-payload-child", "", attributes); + testling.handleEndElement("unknown-payload-child", ""); + testling.handleEndElement("unknown-payload", ""); + testling.handleStartElement("mypayload2", "", attributes); + testling.handleEndElement("mypayload2", ""); + testling.handleEndElement("mystanza", ""); + + assertNotNull(testling.getStanza().getPayload(new MyPayload1())); + assertNotNull(testling.getStanza().getPayload(new MyPayload2())); + } + + @Test + public void testHandleParse_BasicAttributes() { + MyStanzaParser testling = new MyStanzaParser(factoryCollection_); + + AttributeMap attributes = new AttributeMap(); + attributes.addAttribute("to", "", "foo@example.com/blo"); + attributes.addAttribute("from", "", "bar@example.com/baz"); + attributes.addAttribute("id", "", "id-123"); + testling.handleStartElement("mystanza", "", attributes); + testling.handleEndElement("mypayload1", ""); + + assertEquals(new JID("foo@example.com/blo"), testling.getStanza().getTo()); + assertEquals(new JID("bar@example.com/baz"), testling.getStanza().getFrom()); + assertEquals("id-123", testling.getStanza().getID()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/StanzaParserTester.java b/test/com/isode/stroke/parser/StanzaParserTester.java new file mode 100644 index 0000000..09adcbb --- /dev/null +++ b/test/com/isode/stroke/parser/StanzaParserTester.java @@ -0,0 +1,47 @@ +/* + * 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; + +import com.isode.stroke.parser.XMLParser; +import com.isode.stroke.eventloop.EventLoop; +import com.isode.stroke.parser.XMLParserClient; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.StanzaParser; +import com.isode.stroke.parser.PlatformXMLParserFactory; + +public class StanzaParserTester implements XMLParserClient { + + private XMLParser xmlParser_; + private ParserType parser_; + + public StanzaParserTester(ParserType parser) { + this.parser_ = parser; + xmlParser_ = PlatformXMLParserFactory.createXMLParser(this); + } + + public boolean parse(String data) { + return xmlParser_.parse(data); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + parser_.handleStartElement(element, ns, attributes); + } + + public void handleEndElement(String element, String ns) { + parser_.handleEndElement(element, ns); + } + + public void handleCharacterData(String data) { + parser_.handleCharacterData(data); + } +} + diff --git a/test/com/isode/stroke/parser/StreamFeaturesParserTest.java b/test/com/isode/stroke/parser/StreamFeaturesParserTest.java new file mode 100644 index 0000000..1a32a72 --- /dev/null +++ b/test/com/isode/stroke/parser/StreamFeaturesParserTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2013 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.StreamFeaturesParser; +import com.isode.stroke.elements.StreamFeatures; +import com.isode.stroke.parser.ElementParserTester; + +public class StreamFeaturesParserTest { + + public StreamFeaturesParserTest() { + + } + + @Test + public void testParse() { + StreamFeaturesParser testling = new StreamFeaturesParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse( + "" + + "" + + "" + + "zlib" + + "lzw" + + "" + + "" + + "DIGEST-MD5" + + "PLAIN" + + "" + + "" + + "" + + "" + + "" + + "")); + + StreamFeatures element = (StreamFeatures)(testling.getElement()); + assertTrue(element.hasStartTLS()); + assertTrue(element.hasSession()); + assertTrue(element.hasResourceBind()); + assertTrue(element.hasCompressionMethod("zlib")); + assertTrue(element.hasCompressionMethod("lzw")); + assertTrue(element.hasAuthenticationMechanisms()); + assertTrue(element.hasAuthenticationMechanism("DIGEST-MD5")); + assertTrue(element.hasAuthenticationMechanism("PLAIN")); + assertNull(element.getAuthenticationHostname()); + assertTrue(element.hasStreamManagement()); + assertTrue(element.hasRosterVersioning()); + } + + @Test + public void testParse_Empty() { + StreamFeaturesParser testling = new StreamFeaturesParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse("")); + + StreamFeatures element = (StreamFeatures)(testling.getElement()); + assertFalse(element.hasStartTLS()); + assertFalse(element.hasSession()); + assertFalse(element.hasResourceBind()); + assertFalse(element.hasAuthenticationMechanisms()); + } + + + @Test + public void testParse_AuthenticationHostname() { + StreamFeaturesParser testling = new StreamFeaturesParser(); + ElementParserTester parser = new ElementParserTester(testling); + String hostname = "auth42.us.example.com"; + + assertTrue(parser.parse( + "" + + "" + + "GSSAPI" + + "auth42.us.example.com" + + "" + + "")); + + StreamFeatures element = (StreamFeatures)(testling.getElement()); + assertTrue(element.hasAuthenticationMechanism("GSSAPI")); + assertEquals(element.getAuthenticationHostname(), hostname); + } + + + @Test + public void testParse_AuthenticationHostnameEmpty() { + StreamFeaturesParser testling = new StreamFeaturesParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse( + "" + + "" + + "GSSAPI" + + "" + + "" + + "")); + + StreamFeatures element = (StreamFeatures)(testling.getElement()); + assertTrue(element.hasAuthenticationMechanism("GSSAPI")); + assertTrue(element.getAuthenticationHostname().isEmpty()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java b/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java new file mode 100644 index 0000000..1ec3d30 --- /dev/null +++ b/test/com/isode/stroke/parser/StreamManagementEnabledParserTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.parser.StreamManagementEnabledParser; +import com.isode.stroke.elements.StreamManagementEnabled; +import com.isode.stroke.parser.ElementParserTester; + +public class StreamManagementEnabledParserTest { + + public StreamManagementEnabledParserTest() { + + } + + @Test + public void testParse() { + StreamManagementEnabledParser testling = new StreamManagementEnabledParser(); + ElementParserTester parser = new ElementParserTester(testling); + + assertTrue(parser.parse( + "")); + + StreamManagementEnabled element = (StreamManagementEnabled)(testling.getElement()); + assertTrue(element.getResumeSupported()); + assertEquals("some-long-sm-id", element.getResumeID()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java b/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java new file mode 100644 index 0000000..12c67ac --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/BodyParserTest.java @@ -0,0 +1,39 @@ +/* + * 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.Body; +import com.isode.stroke.parser.payloadparsers.BodyParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class BodyParserTest { + + public BodyParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse("foobarfum")); + + Body payload = (Body)(parser.getPayload()); + assertEquals("foobarfum", payload.getText()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java b/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java new file mode 100644 index 0000000..d903b3b --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/PayloadParserTester.java @@ -0,0 +1,47 @@ +/* + * 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 com.isode.stroke.parser.XMLParser; +import com.isode.stroke.eventloop.EventLoop; +import com.isode.stroke.parser.XMLParserClient; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PlatformXMLParserFactory; + +public class PayloadParserTester implements XMLParserClient { + + private XMLParser xmlParser_; + private ParserType parser_; + + public PayloadParserTester(ParserType parser) { + this.parser_ = parser; + xmlParser_ = PlatformXMLParserFactory.createXMLParser(this); + } + + public boolean parse(String data) { + return xmlParser_.parse(data); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + parser_.handleStartElement(element, ns, attributes); + } + + public void handleEndElement(String element, String ns) { + parser_.handleEndElement(element, ns); + } + + public void handleCharacterData(String data) { + parser_.handleCharacterData(data); + } +} + diff --git a/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java b/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java new file mode 100644 index 0000000..004f68f --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/PrivateStorageParserTest.java @@ -0,0 +1,106 @@ +/* + * 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.PrivateStorage; +import com.isode.stroke.elements.Storage; +import com.isode.stroke.parser.payloadparsers.PrivateStorageParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.parser.payloadparsers.PayloadParserTester; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; + +public class PrivateStorageParserTest { + + public PrivateStorageParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "Alice" + + "" + + "" + + "")); + + PrivateStorage payload = (PrivateStorage)(parser.getPayload()); + assertNotNull(payload); + Storage storage = (Storage)(payload.getPayload()); + assertNotNull(storage); + assertEquals("Alice", storage.getRooms().get(0).nick); + assertEquals(new JID("swift@rooms.swift.im"), storage.getRooms().get(0).jid); + } + + @Test + public void testParse_NoPayload() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse("")); + + PrivateStorage payload = (PrivateStorage)(parser.getPayload()); + assertNotNull(payload); + assertNull(payload.getPayload()); + } + + @Test + public void testParse_MultiplePayloads() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "Alice" + + "" + + "" + + "" + + "" + + "Rabbit" + + "" + + "" + + "")); + + PrivateStorage payload = (PrivateStorage)(parser.getPayload()); + assertNotNull(payload); + Storage storage = (Storage)(payload.getPayload()); + assertNotNull(storage); + assertEquals("Rabbit", storage.getRooms().get(0).nick); + } + + @Test + public void testParse_UnsupportedPayload() { + PayloadParserFactoryCollection factories = new PayloadParserFactoryCollection(); + PrivateStorageParser testling = new PrivateStorageParser(factories); + PayloadParserTester parser = new PayloadParserTester(testling); + + assertNotNull(parser.parse( + "" + + "Bar" + + "")); + + assertNull(((PrivateStorage)(testling.getPayload())).getPayload()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.java new file mode 100644 index 0000000..e416066 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/RawXMLPayloadParserTest.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 static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.elements.RawXMLPayload; +import com.isode.stroke.parser.payloadparsers.RawXMLPayloadParser; +import com.isode.stroke.parser.payloadparsers.PayloadParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class RawXMLPayloadParserTest { + + public RawXMLPayloadParserTest() { + + } + + @Test + public void testParse() { + RawXMLPayloadParser testling = new RawXMLPayloadParser(); + PayloadParserTester parser = new PayloadParserTester(testling); + + String xml = + "" + + "" + + "" + + ""; + assertTrue(parser.parse(xml)); + + RawXMLPayload payload = (RawXMLPayload)(testling.getPayload()); + assertNotNull(xml, payload.getRawXML()); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java b/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java new file mode 100644 index 0000000..d9e254c --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/StorageParserTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2010-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.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.Storage; +import com.isode.stroke.parser.payloadparsers.StorageParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; +import java.util.Vector; + +public class StorageParserTest { + + public StorageParserTest() { + + } + + @Test + public void testParse_Room() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "" + + "Puck" + + "MyPass" + + "" + + "")); + + Storage payload = (Storage)(parser.getPayload()); + Vector rooms = payload.getRooms(); + assertEquals(1, rooms.size()); + assertEquals("Council of Oberon", rooms.get(0).name); + assertEquals(new JID("council@conference.underhill.org"), rooms.get(0).jid); + assertTrue(rooms.get(0).autoJoin); + assertEquals("Puck", rooms.get(0).nick); + assertEquals("MyPass", rooms.get(0).password); + } + + @Test + public void testParse_MultipleRooms() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "" + + "" + + "")); + + Storage payload = (Storage)(parser.getPayload()); + Vector rooms = payload.getRooms(); + assertEquals(2, rooms.size()); + assertEquals("Council of Oberon", rooms.get(0).name); + assertEquals(new JID("council@conference.underhill.org"), rooms.get(0).jid); + assertEquals("Tea & jam party", rooms.get(1).name); + assertEquals(new JID("teaparty@wonderland.lit"), rooms.get(1).jid); + } + + @Test + public void testParse_URL() { + DummyEventLoop eventloop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventloop); + + assertNotNull(parser.parse( + "" + + "" + + "")); + + Storage payload = (Storage)(parser.getPayload()); + Vector urls = payload.getURLs(); + assertEquals(1, urls.size()); + assertEquals("Complete Works of Shakespeare", urls.get(0).name); + assertEquals("http://the-tech.mit.edu/Shakespeare/", urls.get(0).url); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java b/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java new file mode 100644 index 0000000..44ed1b8 --- /dev/null +++ b/test/com/isode/stroke/serializer/AuthChallengeSerializerTest.java @@ -0,0 +1,61 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.AuthChallengeSerializer; +import com.isode.stroke.elements.AuthChallenge; +import com.isode.stroke.base.ByteArray; + +public class AuthChallengeSerializerTest { + + /** + * Default Constructor. + */ + public AuthChallengeSerializerTest() { + + } + + @Test + public void testSerialize() { + AuthChallengeSerializer testling = new AuthChallengeSerializer(); + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setValue(new ByteArray("foo")); + + assertEquals( + "" + + "Zm9v" + + "", testling.serialize(authChallenge)); + } + + @Test + public void testSerialize_NoMessage() { + AuthChallengeSerializer testling = new AuthChallengeSerializer(); + AuthChallenge authChallenge = new AuthChallenge(); + + assertEquals( + "", testling.serialize(authChallenge)); + } + + @Test + public void testSerialize_EmptyMessage() { + AuthChallengeSerializer testling = new AuthChallengeSerializer(); + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setValue(new ByteArray()); + + assertEquals( + "" + + "=" + + "", testling.serialize(authChallenge)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java b/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java new file mode 100644 index 0000000..eae4354 --- /dev/null +++ b/test/com/isode/stroke/serializer/AuthRequestSerializerTest.java @@ -0,0 +1,62 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.AuthRequestSerializer; +import com.isode.stroke.elements.AuthRequest; +import com.isode.stroke.base.ByteArray; + +public class AuthRequestSerializerTest { + + /** + * Default Constructor. + */ + public AuthRequestSerializerTest() { + + } + + @Test + public void testSerialize() { + AuthRequestSerializer testling = new AuthRequestSerializer(); + AuthRequest authRequest = new AuthRequest("PLAIN"); + authRequest.setMessage(new ByteArray("foo")); + + assertEquals( + "" + + "Zm9v" + + "", testling.serialize(authRequest)); + } + + @Test + public void testSerialize_NoMessage() { + AuthRequestSerializer testling = new AuthRequestSerializer(); + AuthRequest authRequest = new AuthRequest("PLAIN"); + + assertEquals( + "" + + "", testling.serialize(authRequest)); + } + + @Test + public void testSerialize_EmptyMessage() { + AuthRequestSerializer testling = new AuthRequestSerializer(); + AuthRequest authRequest = new AuthRequest("PLAIN"); + authRequest.setMessage(new ByteArray()); + + assertEquals( + "" + + "=" + + "", testling.serialize(authRequest)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java b/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java new file mode 100644 index 0000000..9b0fe71 --- /dev/null +++ b/test/com/isode/stroke/serializer/AuthResponseSerializerTest.java @@ -0,0 +1,62 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.AuthResponseSerializer; +import com.isode.stroke.elements.AuthResponse; +import com.isode.stroke.base.ByteArray; + +public class AuthResponseSerializerTest { + + /** + * Default Constructor. + */ + public AuthResponseSerializerTest() { + + } + + @Test + public void testSerialize() { + AuthResponseSerializer testling = new AuthResponseSerializer(); + AuthResponse authResponse = new AuthResponse(); + authResponse.setValue(new ByteArray("foo")); + + assertEquals( + "" + + "Zm9v" + + "", testling.serialize(authResponse)); + } + + @Test + public void testSerialize_NoMessage() { + AuthResponseSerializer testling = new AuthResponseSerializer(); + AuthResponse authResponse = new AuthResponse(); + + assertEquals( + "" + + "", testling.serialize(authResponse)); + } + + @Test + public void testSerialize_EmptyMessage() { + AuthResponseSerializer testling = new AuthResponseSerializer(); + AuthResponse authResponse = new AuthResponse(); + authResponse.setValue(new ByteArray()); + + assertEquals( + "" + + "" + + "", testling.serialize(authResponse)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java b/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java new file mode 100644 index 0000000..ee9b595 --- /dev/null +++ b/test/com/isode/stroke/serializer/AuthSuccessSerializerTest.java @@ -0,0 +1,62 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.AuthSuccessSerializer; +import com.isode.stroke.elements.AuthSuccess; +import com.isode.stroke.base.ByteArray; + +public class AuthSuccessSerializerTest { + + /** + * Default Constructor. + */ + public AuthSuccessSerializerTest() { + + } + + @Test + public void testSerialize() { + AuthSuccessSerializer testling = new AuthSuccessSerializer(); + AuthSuccess authSuccess = new AuthSuccess(); + authSuccess.setValue(new ByteArray("foo")); + + assertEquals( + "" + + "Zm9v" + + "", testling.serialize(authSuccess)); + } + + @Test + public void testSerialize_NoMessage() { + AuthSuccessSerializer testling = new AuthSuccessSerializer(); + AuthSuccess authSuccess = new AuthSuccess(); + + assertEquals( + "" + + "", testling.serialize(authSuccess)); + } + + @Test + public void testSerialize_EmptyMessage() { + AuthSuccessSerializer testling = new AuthSuccessSerializer(); + AuthSuccess authSuccess = new AuthSuccess(); + authSuccess.setValue(new ByteArray()); + + assertEquals( + "" + + "=" + + "", testling.serialize(authSuccess)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java b/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java new file mode 100644 index 0000000..67d9bb0 --- /dev/null +++ b/test/com/isode/stroke/serializer/StreamFeaturesSerializerTest.java @@ -0,0 +1,59 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.StreamFeaturesSerializer; +import com.isode.stroke.elements.StreamFeatures; + +public class StreamFeaturesSerializerTest { + + /** + * Default Constructor. + */ + public StreamFeaturesSerializerTest() { + + } + + @Test + public void testSerialize() { + StreamFeaturesSerializer testling = new StreamFeaturesSerializer(); + StreamFeatures streamFeatures = new StreamFeatures(); + streamFeatures.setHasStartTLS(); + streamFeatures.addCompressionMethod("zlib"); + streamFeatures.addCompressionMethod("lzw"); + streamFeatures.addAuthenticationMechanism("DIGEST-MD5"); + streamFeatures.addAuthenticationMechanism("PLAIN"); + streamFeatures.setHasResourceBind(); + streamFeatures.setHasSession(); + streamFeatures.setHasStreamManagement(); + streamFeatures.setHasRosterVersioning(); + + assertEquals( + "" + + "" + + "" + + "zlib" + + "lzw" + + "" + + "" + + "DIGEST-MD5" + + "PLAIN" + + "" + + "" + + "" + + "" + + "" + + "", testling.serialize(streamFeatures)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java new file mode 100644 index 0000000..42b9904 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/ErrorSerializerTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2010-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 org.junit.BeforeClass; +import com.isode.stroke.serializer.payloadserializers.ErrorSerializer; +import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.Delay; + +public class ErrorSerializerTest { + + @BeforeClass + public static void init() throws Exception { + } + + private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection(); + + /** + * Default Constructor. + */ + public ErrorSerializerTest() { + + } + + @Test + public void testSerialize() { + ErrorSerializer testling = new ErrorSerializer(serializers); + ErrorPayload error = new ErrorPayload(ErrorPayload.Condition.BadRequest, ErrorPayload.Type.Cancel, "My Error"); + + assertEquals("My Error", testling.serialize(error)); + } + + @Test + public void testSerialize_Payload() { + ErrorSerializer testling = new ErrorSerializer(serializers); + ErrorPayload error = new ErrorPayload(); + error.setPayload(new Delay()); + + assertEquals( + "" + , testling.serialize(error)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java new file mode 100644 index 0000000..ca9c5a8 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleSerializersTest.java @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +/* + * Copyright (c) 2015 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.JingleFileTransferDescriptionSerializer; +import com.isode.stroke.serializer.payloadserializers.StreamInitiationFileInfoSerializer; +import com.isode.stroke.serializer.payloadserializers.JinglePayloadSerializer; +import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; +import com.isode.stroke.elements.JingleFileTransferDescription; +import com.isode.stroke.elements.JingleFileTransferFileInfo; +import com.isode.stroke.elements.JingleIBBTransportPayload; +import com.isode.stroke.elements.JingleS5BTransportPayload; +import com.isode.stroke.elements.JingleFileTransferHash; +import com.isode.stroke.elements.JinglePayload; +import com.isode.stroke.elements.HashElement; +import com.isode.stroke.elements.JingleContentPayload; +import com.isode.stroke.elements.StreamInitiationFileInfo; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.stringcodecs.Base64; +import com.isode.stroke.jid.JID; +import com.isode.stroke.network.HostAddress; +import com.isode.stroke.network.HostAddressPort; +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class JingleSerializersTest { + + private FullPayloadSerializerCollection collection = new FullPayloadSerializerCollection(); + + /** + * Default Constructor. + */ + public JingleSerializersTest() { + + } + + public JinglePayloadSerializer createTestling() { + return new JinglePayloadSerializer(collection); + } + + @Test + public void testSerialize_StreamInitiationFileInfo() { + String expected = "This is a test. If this were a real file..."; + + StreamInitiationFileInfo fileInfo = new StreamInitiationFileInfo(); + fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z")); + fileInfo.setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo.setSize(1022); + fileInfo.setName("test.txt"); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + StreamInitiationFileInfoSerializer serializer = new StreamInitiationFileInfoSerializer(); + assertEquals(expected, serializer.serializePayload(fileInfo)); + } + + + @Test + public void testSerialize_StreamInitiationFileInfoRange() { + String expected = ""; + + StreamInitiationFileInfo fileInfo = new StreamInitiationFileInfo(); + fileInfo.setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(270336); + + StreamInitiationFileInfoSerializer serializer = new StreamInitiationFileInfoSerializer(); + assertEquals(expected, serializer.serializePayload(fileInfo)); + } + + + // IBB Transport Method Examples + + // http://xmpp.org/extensions/xep-0261.html#example-1 + @Test + public void testSerialize_Xep0261_Example1() { + String expected = ""; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.SessionInitiate); + payload.setSessionID("a73sjjvkla37jfea"); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + + JingleIBBTransportPayload transport = new JingleIBBTransportPayload(); + transport.setBlockSize(4096); + transport.setSessionID("ch3d9s71"); + + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("ex"); + content.addTransport(transport); + + payload.addPayload(content); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-9 + @Test + public void testSerialize_Xep0261_Example9() { + String expected = ""; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.TransportInfo); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("ex"); + + JingleIBBTransportPayload transport = new JingleIBBTransportPayload(); + transport.setBlockSize(2048); + transport.setSessionID("bt8a71h6"); + + content.addTransport(transport); + payload.addPayload(content); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-13 + @Test + public void testSerialize_Xep0261_Example13() { + String expected = ""; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.SessionTerminate); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("a73sjjvkla37jfea"); + payload.setReason(new JinglePayload.Reason(JinglePayload.Reason.Type.Success)); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-1 + @Test + public void testSerialize_Xep0234_Example1() { + String expected = "1969-07-21T02:56:15ZThis is a test. If this were a real file...test.txt1022VS2nSZMIUsaa5dIUHTdmsQ=="; + + JingleFileTransferDescription desc = new JingleFileTransferDescription(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + + fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z")); + fileInfo.addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + fileInfo.setSize(1022); + fileInfo.setName("test.txt"); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + desc.setFileInfo(fileInfo); + + assertEquals(expected, new JingleFileTransferDescriptionSerializer().serialize(desc)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-3 + @Test + public void testSerialize_Xep0234_Example3() { + String expected = "1969-07-21T02:56:15ZThis is a test. If this were a real file...test.txt1022VS2nSZMIUsaa5dIUHTdmsQ=="; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.SessionAccept); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("851ba2"); + + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("a-file-offer"); + + JingleFileTransferDescription description = new JingleFileTransferDescription(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("test.txt"); + fileInfo.setSize(1022); + fileInfo.addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + fileInfo.setDate(DateTime.stringToDate("1969-07-21T02:56:15Z")); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + description.setFileInfo(fileInfo); + content.addDescription(description); + payload.addPayload(content); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-5 + @Test + public void testSerialize_Xep0234_Example5() { + String expected = ""; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.TransportInfo); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("ex"); + payload.addPayload(content); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-8 + @Test + public void testSerialize_Xep0234_Example8() { + String expected = "VS2nSZMIUsaa5dIUHTdmsQ=="; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.SessionInfo); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("a73sjjvkla37jfea"); + + JingleFileTransferHash hash = new JingleFileTransferHash(); + hash.getFileInfo().addHash(new HashElement("sha-1", Base64.decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + + payload.addPayload(hash); + + assertEquals(expected, createTestling().serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0260.html#example-1 + @Test + public void testSerialize_Xep0260_Example1() { + String expected = ""; + + JinglePayload payload = new JinglePayload(); + payload.setAction(JinglePayload.Action.SessionInitiate); + payload.setInitiator(new JID("romeo@montague.lit/orchard")); + payload.setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("ex"); + + JingleS5BTransportPayload transport = new JingleS5BTransportPayload(); + transport.setMode(JingleS5BTransportPayload.Mode.TCPMode); + transport.setDstAddr("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"); + transport.setSessionID("vj3hs98y"); + + JingleS5BTransportPayload.Candidate candidate1 = new JingleS5BTransportPayload.Candidate(); + candidate1.cid = "hft54dqy"; + try { + candidate1.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("192.168.4.1")), 5086); + } catch (UnknownHostException e) { + + } + candidate1.jid = new JID("romeo@montague.lit/orchard"); + candidate1.priority = 8257636; + candidate1.type = JingleS5BTransportPayload.Candidate.Type.DirectType; + transport.addCandidate(candidate1); + + JingleS5BTransportPayload.Candidate candidate2 = new JingleS5BTransportPayload.Candidate(); + candidate2.cid = "hutr46fe"; + try { + candidate2.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("24.24.24.1")), 5087); + } catch (UnknownHostException e) { + + } + candidate2.jid = new JID("romeo@montague.lit/orchard"); + candidate2.priority = 8258636; + candidate2.type = JingleS5BTransportPayload.Candidate.Type.DirectType; + transport.addCandidate(candidate2); + + content.addTransport(transport); + + payload.addPayload(content); + + assertEquals(expected, createTestling().serialize(payload)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java b/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java new file mode 100644 index 0000000..2008373 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/PayloadsSerializer.java @@ -0,0 +1,32 @@ +/* + * 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 com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; +import com.isode.stroke.serializer.PayloadSerializer; +import com.isode.stroke.elements.Payload; + +public class PayloadsSerializer { + + private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection(); + + public String serialize(Payload payload) { + PayloadSerializer serializer = serializers.getPayloadSerializer(payload); + if (serializer != null) { + return serializer.serialize(payload); + } + else { + assert(false); + return ""; + } + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java new file mode 100644 index 0000000..9ef2762 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/PrivateStorageSerializerTest.java @@ -0,0 +1,55 @@ +/* + * 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.PayloadsSerializer; +import com.isode.stroke.elements.PrivateStorage; +import com.isode.stroke.elements.Storage; +import com.isode.stroke.jid.JID; + +public class PrivateStorageSerializerTest { + + /** + * Default Constructor. + */ + public PrivateStorageSerializerTest() { + + } + + @Test + public void testSerialize() { + PayloadsSerializer serializer = new PayloadsSerializer(); + + PrivateStorage privateStorage = new PrivateStorage(); + Storage storage = new Storage(); + Storage.Room room = new Storage.Room(); + room.name = "Swift"; + room.jid = new JID("swift@rooms.swift.im"); + room.nick = "Alice"; + storage.addRoom(room); + privateStorage.setPayload(storage); + + assertEquals( + "" + + "" + + "" + + "Alice" + + "" + + "" + + "", serializer.serialize(privateStorage)); + } +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java new file mode 100644 index 0000000..af19175 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 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.PubSubItemSerializer; +import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.RawXMLPayload; + +public class PubSubItemSerializerTest { + + private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection(); + + /** + * Default Constructor. + */ + public PubSubItemSerializerTest() { + + } + + @Test + public void testSerialize() { + PubSubItemSerializer serializer = new PubSubItemSerializer(serializers); + + RawXMLPayload payload = new RawXMLPayload(); + payload.setRawXML(""); + + PubSubItem item = new PubSubItem(); + item.addData(payload); + item.setID("pubsub-item-1"); + + String expectedResult = + "" + + "" + + ""; + + assertEquals(expectedResult, serializer.serialize(item)); + } + + @Test + public void testSerializeEmptyID() { + PubSubItemSerializer serializer = new PubSubItemSerializer(serializers); + + PubSubItem item = new PubSubItem(); + + String expectedResult = + ""; + + assertEquals(expectedResult, serializer.serialize(item)); + } + +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java new file mode 100644 index 0000000..9745dac --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializerTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014 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.PubSubItemsSerializer; +import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubItems; +import com.isode.stroke.elements.RawXMLPayload; + +public class PubSubItemsSerializerTest { + + private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection(); + + /** + * Default Constructor. + */ + public PubSubItemsSerializerTest() { + + } + + @Test + public void testSerialize() { + PubSubItemsSerializer serializer = new PubSubItemsSerializer(serializers); + + RawXMLPayload payload1 = new RawXMLPayload(); + payload1.setRawXML(""); + + PubSubItem item1 = new PubSubItem(); + item1.addData(payload1); + item1.setID("pubsub-item-1"); + + RawXMLPayload payload2 = new RawXMLPayload(); + payload2.setRawXML(""); + + PubSubItem item2 = new PubSubItem(); + item2.addData(payload2); + item2.setID("pubsub-item-2"); + + PubSubItems items = new PubSubItems(); + items.setNode("test-node"); + items.setSubscriptionID("sub-id"); + items.addItem(item1); + items.addItem(item2); + + String expectedResult = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + assertEquals(expectedResult, serializer.serialize(items)); + } + + @Test + public void testSerializeEmptyItems() { + PubSubItemsSerializer serializer = new PubSubItemsSerializer(serializers); + + PubSubItems items = new PubSubItems(); + + // Swiften code doesn't check for node being null in serializer and therefore will have extra node=\"\", + // BUT since it is being check in serializer here, there will be no node. + String expectedResult = + ""; + + assertEquals(expectedResult, serializer.serialize(items)); + } + +} \ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java new file mode 100644 index 0000000..036b366 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/StorageSerializerTest.java @@ -0,0 +1,76 @@ +/* + * 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.PayloadsSerializer; +import com.isode.stroke.elements.Storage; +import com.isode.stroke.jid.JID; + +public class StorageSerializerTest { + + /** + * Default Constructor. + */ + public StorageSerializerTest() { + + } + + @Test + public void testSerialize() { + PayloadsSerializer serializer = new PayloadsSerializer(); + Storage storage = new Storage(); + Storage.Room room = new Storage.Room(); + room.name = "Council of Oberon"; + room.autoJoin = true; + room.jid = new JID("council@conference.underhill.org"); + room.nick = "Puck"; + room.password = "MyPass"; + storage.addRoom(room); + Storage.URL url = new Storage.URL(); + url.name = "Complete Works of Shakespeare"; + url.url = "http://the-tech.mit.edu/Shakespeare/"; + storage.addURL(url); + + assertEquals( + "" + + "" + + "Puck" + + "MyPass" + + "" + + "" + + "", serializer.serialize(storage)); + } + + @Test + public void testSerialize_NoNickOrPassword() { + PayloadsSerializer serializer = new PayloadsSerializer(); + Storage storage = new Storage(); + Storage.Room room = new Storage.Room(); + room.name = "Council of Oberon"; + room.autoJoin = true; + room.jid = new JID("council@conference.underhill.org"); + storage.addRoom(room); + + assertEquals( + "" + + "" + + "", serializer.serialize(storage)); + } +} \ No newline at end of file -- cgit v0.10.2-6-g49f6