diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-02-25 11:33:49 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-02-29 12:28:57 (GMT) |
commit | 191f768446f89a766b4f5c43ba9098c63c590032 (patch) | |
tree | e1a2d9bf96d590829ece8ac089eb8126dbb3672f /test | |
parent | d636d68c84229c82ff746c7697d2014ff4dd4477 (diff) | |
download | stroke-191f768446f89a766b4f5c43ba9098c63c590032.zip stroke-191f768446f89a766b4f5c43ba9098c63c590032.tar.bz2 |
Add Parser and Serializer classes
Add classes to the parser and serializer packages, including some tests.
Update PortingProgress with info on the classes that could not be imported in
this patch.
Test-information:
Unit tests pass ok.
Change-Id: If42af9c0cecb68151cf817f1839b86b4d7c8967c
Diffstat (limited to 'test')
3 files changed, 162 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java b/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java new file mode 100644 index 0000000..cf7df32 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/IdleParserTest.java @@ -0,0 +1,48 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.Idle; +import com.isode.stroke.elements.Presence; +import com.isode.stroke.parser.PresenceParser; +import com.isode.stroke.parser.StanzaParserTester; + +/** + * Test for {@link IdleParser} + */ +public class IdleParserTest { + + @Test + public void testParse_XepWhatever_Example1() { + PresenceParser testling = new PresenceParser(new FullPayloadParserFactoryCollection()); + StanzaParserTester<PresenceParser> parser = new StanzaParserTester<PresenceParser>(testling); + assertTrue(parser.parse( + "<presence from='juliet@capulet.com/balcony'>\n" + +"<show>away</show>\n" + +"<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n" + +"</presence>\n" + )); + + Presence presence = testling.getStanzaGeneric(); + assertNotNull(presence); + + Idle idle = presence.getPayload(new Idle()); + assertNotNull(idle); + assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"),idle.getSince()); + } + +} diff --git a/test/com/isode/stroke/serializer/XMPPSerializerTest.java b/test/com/isode/stroke/serializer/XMPPSerializerTest.java new file mode 100644 index 0000000..1c86034 --- /dev/null +++ b/test/com/isode/stroke/serializer/XMPPSerializerTest.java @@ -0,0 +1,80 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.serializer; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.isode.stroke.elements.ProtocolHeader; +import com.isode.stroke.elements.StreamType; +import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection; + +/** + * + */ +public class XMPPSerializerTest { + + private final PayloadSerializerCollection payloadSerializerCollection = + new FullPayloadSerializerCollection(); + + @Test + public void testSerializeHeader_Client() { + XMPPSerializer testling = createSerializer(StreamType.ClientStreamType); + ProtocolHeader protocolHeader = new ProtocolHeader(); + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + assertEquals("<?xml version=\"1.0\"?>" + + "<stream:stream xmlns=\"jabber:client\" " + + "xmlns:stream=\"http://etherx.jabber.org/streams\" " + + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">", + testling.serializeHeader(protocolHeader)); + } + + @Test + public void testSerializeHeader_Component() { + XMPPSerializer testling = createSerializer(StreamType.ComponentStreamType); + ProtocolHeader protocolHeader = new ProtocolHeader(); + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + assertEquals("<?xml version=\"1.0\"?>" + + "<stream:stream xmlns=\"jabber:component:accept\" " + + "xmlns:stream=\"http://etherx.jabber.org/streams\" " + + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">", + testling.serializeHeader(protocolHeader)); + } + + @Test + public void testSerializeHeader_Server() { + XMPPSerializer testling = createSerializer(StreamType.ServerStreamType); + ProtocolHeader protocolHeader = new ProtocolHeader(); + protocolHeader.setFrom("bla@foo.com"); + protocolHeader.setTo("foo.com"); + protocolHeader.setID("myid"); + protocolHeader.setVersion("0.99"); + + assertEquals("<?xml version=\"1.0\"?>" + + "<stream:stream xmlns=\"jabber:server\" " + + "xmlns:stream=\"http://etherx.jabber.org/streams\" " + + "from=\"bla@foo.com\" to=\"foo.com\" id=\"myid\" version=\"0.99\">", + testling.serializeHeader(protocolHeader)); + } + + private XMPPSerializer createSerializer(StreamType type) { + return new XMPPSerializer(payloadSerializerCollection, type, false); + } + +} diff --git a/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java new file mode 100644 index 0000000..6a50f01 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/IdleSerializerTest.java @@ -0,0 +1,34 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.serializer.payloadserializers; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.Idle; + +/** + * Test for {@link IdleSerializer} + * + */ +public class IdleSerializerTest { + + @Test + public void testSerialize() { + IdleSerializer testling = new IdleSerializer(); + Idle idle = new Idle(DateTime.stringToDate("1969-07-21T02:56:15Z")); + + assertEquals("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>", + testling.serialize(idle)); + } + +} |