diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-08 19:16:57 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-14 13:30:22 (GMT) |
commit | 9518f8b9d6924e95e4ad839f40866560bd7a7878 (patch) | |
tree | 6d7532fd1628c2f3e0e71b4a10fc14bec8c49a29 /test/com/isode | |
parent | afaf2c8e7a9276bc4a61337357092c49e6817159 (diff) | |
download | stroke-9518f8b9d6924e95e4ad839f40866560bd7a7878.zip stroke-9518f8b9d6924e95e4ad839f40866560bd7a7878.tar.bz2 |
Add the Bytestreams Element.
Adds Bytestreams Element, Parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests added for both Parser and Serializer, which passes.
Change-Id: Ia623f8fcd628d7b34f7f8f935602c6c4c0ffaac1
Diffstat (limited to 'test/com/isode')
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/BytestreamsParserTest.java | 46 | ||||
-rw-r--r-- | test/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializerTest.java | 59 |
2 files changed, 105 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/BytestreamsParserTest.java b/test/com/isode/stroke/parser/payloadparsers/BytestreamsParserTest.java new file mode 100644 index 0000000..ead1de2 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/BytestreamsParserTest.java @@ -0,0 +1,46 @@ +/* + * 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 org.junit.Test; +import com.isode.stroke.elements.Bytestreams; +import com.isode.stroke.jid.JID; +import com.isode.stroke.parser.payloadparsers.BytestreamsParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class BytestreamsParserTest { + + public BytestreamsParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" + + "<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/>" + + "<streamhost host=\"bal.zyx.ude\" jid=\"user1@baz.com/bal\" port=\"449\"/>" + + "</query>")); + + Bytestreams payload = (Bytestreams)parser.getPayload(); + assertEquals("hello", payload.getStreamID()); + + assertEquals(2, payload.getStreamHosts().size()); + + assertEquals("blah.xyz.edu", payload.getStreamHosts().get(0).getHost()); + assertEquals(new JID("user1@bar.com/bla"), payload.getStreamHosts().get(0).getJID()); + assertEquals(445, payload.getStreamHosts().get(0).getPort()); + + assertEquals("bal.zyx.ude", payload.getStreamHosts().get(1).getHost()); + assertEquals(new JID("user1@baz.com/bal"), payload.getStreamHosts().get(1).getJID()); + assertEquals(449, payload.getStreamHosts().get(1).getPort()); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializerTest.java new file mode 100644 index 0000000..331a6a5 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializerTest.java @@ -0,0 +1,59 @@ +/* + * 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.BytestreamsSerializer; +import com.isode.stroke.elements.Bytestreams; +import com.isode.stroke.jid.JID; + +public class BytestreamsSerializerTest { + + public BytestreamsSerializerTest() { + + } + + @Test + public void testSerialize_withoutUsedStreamHost_singleStreamHost() { + BytestreamsSerializer testling = new BytestreamsSerializer(); + Bytestreams byteStreams = new Bytestreams(); + byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445)); + byteStreams.setStreamID("hello"); + String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" + + "<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/></query>"; + assertEquals(expectedResult, testling.serialize(byteStreams)); + } + + @Test + public void testSerialize_withoutUsedStreamHost_doubleStreamHost() { + BytestreamsSerializer testling = new BytestreamsSerializer(); + Bytestreams byteStreams = new Bytestreams(); + byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445)); + byteStreams.addStreamHost(byteStreams.new StreamHost("bal.zyx.ude", new JID("user1@baz.com/bal"), 449)); + byteStreams.setStreamID("hello"); + String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" + + "<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/>" + + "<streamhost host=\"bal.zyx.ude\" jid=\"user1@baz.com/bal\" port=\"449\"/>" + + "</query>"; + assertEquals(expectedResult, testling.serialize(byteStreams)); + } + + @Test + public void testSerialize_withUsedStreamHost() { + BytestreamsSerializer testling = new BytestreamsSerializer(); + Bytestreams byteStreams = new Bytestreams(); + byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445)); + byteStreams.setUsedStreamHost(new JID("user1@baz.com/bal")); + byteStreams.setStreamID("hello"); + String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" + + "<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/>" + + "<streamhost-used jid=\"user1@baz.com/bal\"/>" + + "</query>"; + assertEquals(expectedResult, testling.serialize(byteStreams)); + } +}
\ No newline at end of file |