summaryrefslogtreecommitdiffstats
path: root/test/com
diff options
context:
space:
mode:
Diffstat (limited to 'test/com')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/BytestreamsParserTest.java46
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/BytestreamsSerializerTest.java59
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