summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-20 12:10:51 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-30 13:23:04 (GMT)
commitba7342e593920595af36fcd8e8e44ec206f8b561 (patch)
treefa8921599a20d85845d23d9a97bbc1cf230c7a51 /test
parenta673d269487fd86efe7f9c5f9b4cd1c00cab556d (diff)
downloadstroke-ba7342e593920595af36fcd8e8e44ec206f8b561.zip
stroke-ba7342e593920595af36fcd8e8e44ec206f8b561.tar.bz2
Add StreamInitiation Elements.
Adds StreamInitiationFileInfo Element, its Parser and Serializer. Adds StreamInitiation Element, its Parser and Serializer. Adds StreamError Parser and Serializer. Updates StreamManagementEnabled Element. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for StreamInitiation Parser and Serializer, which passes. Change-Id: I21a7de3f6a5ac0955b6e5aaae3c2607a30eae002
Diffstat (limited to 'test')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/StreamInitiationParserTest.java80
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/StreamInitiationSerializerTest.java73
2 files changed, 153 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/StreamInitiationParserTest.java b/test/com/isode/stroke/parser/payloadparsers/StreamInitiationParserTest.java
new file mode 100644
index 0000000..ed30aeb
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/StreamInitiationParserTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.StreamInitiation;
+import com.isode.stroke.elements.StreamInitiationFileInfo;
+import com.isode.stroke.parser.payloadparsers.StreamInitiationParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class StreamInitiationParserTest {
+
+ public StreamInitiationParserTest() {
+
+ }
+
+ @Test
+ public void testParse_Request() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<si xmlns='http://jabber.org/protocol/si' id='a0' mime-type='text/plain' profile='http://jabber.org/protocol/si/profile/file-transfer'>" +
+ "<file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='test.txt' size='1022'>" +
+ "<desc>This is info about the file.</desc>" +
+ "</file>" +
+ "<feature xmlns='http://jabber.org/protocol/feature-neg'>" +
+ "<x xmlns='jabber:x:data' type='form'>" +
+ "<field var='stream-method' type='list-single'>" +
+ "<option><value>http://jabber.org/protocol/bytestreams</value></option>" +
+ "<option><value>jabber:iq:oob</value></option>" +
+ "<option><value>http://jabber.org/protocol/ibb</value></option>" +
+ "</field>" +
+ "</x>" +
+ "</feature>" +
+ "</si>"));
+
+ StreamInitiation si = (StreamInitiation)parser.getPayload();
+ assertTrue(si.getIsFileTransfer());
+ assertNotNull(si.getFileInfo());
+ assertEquals("test.txt", si.getFileInfo().getName());
+ assertEquals(1022L, si.getFileInfo().getSize());
+ assertEquals("This is info about the file.", si.getFileInfo().getDescription());
+ assertEquals(3, si.getProvidedMethods().size());
+ assertEquals("http://jabber.org/protocol/bytestreams", si.getProvidedMethods().get(0));
+ assertEquals("jabber:iq:oob", si.getProvidedMethods().get(1));
+ assertEquals("http://jabber.org/protocol/ibb", si.getProvidedMethods().get(2));
+ }
+
+ @Test
+ public void testParse_Response() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<si xmlns='http://jabber.org/protocol/si'>" +
+ "<feature xmlns='http://jabber.org/protocol/feature-neg'>" +
+ "<x xmlns='jabber:x:data' type='submit'>" +
+ "<field var='stream-method'>" +
+ "<value>http://jabber.org/protocol/bytestreams</value>" +
+ "</field>" +
+ "</x>" +
+ "</feature>" +
+ "</si>"));
+
+ StreamInitiation si = (StreamInitiation)parser.getPayload();
+ assertTrue(si.getIsFileTransfer());
+ assertEquals("http://jabber.org/protocol/bytestreams", si.getRequestedMethod());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/StreamInitiationSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/StreamInitiationSerializerTest.java
new file mode 100644
index 0000000..54e7f87
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/StreamInitiationSerializerTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.StreamInitiationSerializer;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.StreamInitiation;
+import com.isode.stroke.elements.StreamInitiationFileInfo;
+
+public class StreamInitiationSerializerTest {
+
+ /**
+ * Default Constructor.
+ */
+ public StreamInitiationSerializerTest() {
+
+ }
+
+ @Test
+ public void testSerialize_Request() {
+ StreamInitiationSerializer testling = new StreamInitiationSerializer();
+ StreamInitiation streamInitiation = new StreamInitiation();
+ StreamInitiationFileInfo fileInfo = new StreamInitiationFileInfo("test.txt", "This is info about the file.", 1022);
+ streamInitiation.setID("a0");
+ streamInitiation.setFileInfo(fileInfo);
+ streamInitiation.addProvidedMethod("http://jabber.org/protocol/bytestreams");
+ streamInitiation.addProvidedMethod("jabber:iq:oob");
+ streamInitiation.addProvidedMethod("http://jabber.org/protocol/ibb");
+ String expectedResult = "<si id=\"a0\" profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">"
+ + "<file name=\"test.txt\" size=\"1022\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">"
+ + "<desc>This is info about the file.</desc>"
+ + "</file>"
+ + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">"
+ + "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ + "<field type=\"list-single\" var=\"stream-method\">"
+ + "<option><value>http://jabber.org/protocol/bytestreams</value></option>"
+ + "<option><value>jabber:iq:oob</value></option>"
+ + "<option><value>http://jabber.org/protocol/ibb</value></option>"
+ + "</field>"
+ + "</x>"
+ + "</feature>"
+ + "</si>";
+ assertEquals(expectedResult, testling.serialize(streamInitiation));
+ }
+
+ @Test
+ public void testSerialize_Response() {
+ StreamInitiationSerializer testling = new StreamInitiationSerializer();
+ StreamInitiation streamInitiation = new StreamInitiation();
+ streamInitiation.setRequestedMethod("http://jabber.org/protocol/bytestreams");
+ String expectedResult = "<si profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">"
+ + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">"
+ + "<x type=\"submit\" xmlns=\"jabber:x:data\">"
+ + "<field type=\"list-single\" var=\"stream-method\">"
+ + "<value>http://jabber.org/protocol/bytestreams</value>"
+ + "</field>"
+ + "</x>"
+ + "</feature>"
+ + "</si>";
+ assertEquals(expectedResult, testling.serialize(streamInitiation));
+ }
+} \ No newline at end of file