From 191f768446f89a766b4f5c43ba9098c63c590032 Mon Sep 17 00:00:00 2001 From: Alex Clayton Date: Thu, 25 Feb 2016 11:33:49 +0000 Subject: 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 diff --git a/PortingProgress.txt b/PortingProgress.txt index 7a8a986..c2844e6 100644 --- a/PortingProgress.txt +++ b/PortingProgress.txt @@ -155,7 +155,9 @@ Parser: All files ported to 6ca201d0b48f4273e24dd7bff17c4a46eeaddf39 except for: -ExpatParser, IdleParserTest, LibXMLParser, WhiteboardParser -- Not Yet Ported! +ExpatParser -- Not yet ported. Requires expact library. +LibXMLParser -- Not yet ported. Requires libxml library. +WhiteboardParser -- Not Yet Ported! Needs Whiteboard classes importing. ----- Presence: @@ -192,7 +194,7 @@ Serializer: All files ported to 6ca201d0b48f4273e24dd7bff17c4a46eeaddf39 except for: -WhiteboardSerializer, XMPPSerializerTest, IdleSerializerTest -- Not Yet Ported! +WhiteboardSerializer -- Not Yet Ported! Needs whiteboard classes importing. ----- Session: 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 parser = new StanzaParserTester(testling); + assertTrue(parser.parse( + "\n" + +"away\n" + +"\n" + +"\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("" + + "", + 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("" + + "", + 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("" + + "", + 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("", + testling.serialize(idle)); + } + +} -- cgit v0.10.2-6-g49f6