summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-17 07:33:03 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-18 20:18:56 (GMT)
commitf9c7be7adde21ab29b5e268a726506bb06510ead (patch)
treeb1e2f276c7015eb74e955b856bdf944c8f4f4041 /test/com/isode/stroke/parser
parent4addb6419080db814094ab501d69111adffeb5be (diff)
downloadstroke-f9c7be7adde21ab29b5e268a726506bb06510ead.zip
stroke-f9c7be7adde21ab29b5e268a726506bb06510ead.tar.bz2
Adds Jingle Elements.
Adds: JinglePayload, its Parser and Serializer and JingleReasonParser. JingleContentPayload Element, its Parser and Serializer. JingleDesciption Element. JingleFileTransferDescription Element, its Parser and Serializer. JingleFileTransferFileInfo Element, its Parser and Serializer. JingleFileTransferHash Element, its Parser and Serializer. JingleIBBTransportPayload Element, its Parser and Serializer. JingleS5BTransportPayload Element, its Parser and Serializer. JingleTransportPayload Element and HashElement. Updates HostAddress access specifier for getInetAddress(). License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for: JingleParser JingleContentPayload Parser and Serializer. JingleFileTransferHash Parser and Serializer. JingleFileTranferFileInfo Parser and Serializer. JingleFileTransferDescription Parser and Serializer. JingleIBBTransportPayload Parser and Serializer. JingleS5BTransportPayload Parser and Serializer. All tests passes. Change-Id: Ife1b7fef00efc57d8d0d4290f3280327439abbb6
Diffstat (limited to 'test/com/isode/stroke/parser')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java90
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java79
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java65
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java79
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java34
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java649
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java50
7 files changed, 1046 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java
new file mode 100644
index 0000000..3498287
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleContentPayloadParserTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.HashElement;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.jid.JID;
+import java.util.Date;
+import java.util.TimeZone;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class JingleContentPayloadParserTest {
+
+ public JingleContentPayloadParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<content xmlns=\"urn:xmpp:jingle:1\" creator=\"initiator\" name=\"Erin\"><description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" +
+ "<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>" +
+ "</description><transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" +
+ "<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/><proxy-error/>" +
+ "<activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport></content>"));
+
+ JingleContentPayload content = (JingleContentPayload)parser.getPayload();
+
+ assertEquals (JingleContentPayload.Creator.InitiatorCreator, content.getCreator());
+ assertEquals ("Erin", content.getName());
+
+
+ assertEquals(1, content.getDescriptions().size());
+ JingleFileTransferDescription description = content.getDescription(new JingleFileTransferDescription());
+ assertNotNull(description);
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+
+ assertEquals(2, content.getTransports().size());
+ JingleIBBTransportPayload jingleIBBTransportPayload = content.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(jingleIBBTransportPayload);
+ assertEquals(Integer.valueOf(4), jingleIBBTransportPayload.getBlockSize());
+ assertEquals("546-45", jingleIBBTransportPayload.getSessionID());
+
+ JingleS5BTransportPayload jingleS5BTransportPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(jingleS5BTransportPayload);
+ assertEquals (JingleS5BTransportPayload.Mode.TCPMode, jingleS5BTransportPayload.getMode());
+ assertEquals ("Candidate", jingleS5BTransportPayload.getCandidateUsed());
+ assertEquals ("Activity", jingleS5BTransportPayload.getActivated());
+ assertEquals ("UK", jingleS5BTransportPayload.getDstAddr());
+ assertEquals (false, jingleS5BTransportPayload.hasCandidateError());
+ assertEquals (true, jingleS5BTransportPayload.hasProxyError());
+
+ assertEquals(1, jingleS5BTransportPayload.getCandidates().size());
+ JingleS5BTransportPayload.Candidate candidate = jingleS5BTransportPayload.getCandidates().get(0);
+ assertEquals("cid", candidate.cid);
+ assertEquals(new JID("blas@nal.vx"), candidate.jid);
+ assertEquals("/173.194.36.112", candidate.hostPort.getAddress().getInetAddress().toString());
+ assertEquals(4, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java
new file mode 100644
index 0000000..765af5c
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferDescriptionParserTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferDescriptionParser;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferDescriptionParserTest {
+
+ public JingleFileTransferDescriptionParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc>" +
+ "<media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>"));
+
+ JingleFileTransferDescription description = (JingleFileTransferDescription)parser.getPayload();
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>"));
+
+
+ JingleFileTransferDescription description = (JingleFileTransferDescription)parser.getPayload();
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java
new file mode 100644
index 0000000..5225a6d
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferFileInfoParserTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferFileInfoParserTest {
+
+ public JingleFileTransferFileInfoParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>"));
+
+ JingleFileTransferFileInfo fileInfo = (JingleFileTransferFileInfo)parser.getPayload();
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>"));
+
+ JingleFileTransferFileInfo fileInfo = (JingleFileTransferFileInfo)parser.getPayload();
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java
new file mode 100644
index 0000000..8dc8a6c
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleFileTransferHashParserTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferHashParser;
+import com.isode.stroke.parser.payloadparsers.JingleFileTransferFileInfoParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import java.util.Date;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.base.ByteArray;
+import java.util.TimeZone;
+
+public class JingleFileTransferHashParserTest {
+
+ public JingleFileTransferHashParserTest() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Test
+ public void testParse_with_all_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><date>2015-06-11T20:55:50Z</date><desc>It is good.</desc>" +
+ "<media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><range offset=\"566\"/><size>513</size>" +
+ "<hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>"));
+
+ JingleFileTransferHash hash = (JingleFileTransferHash)parser.getPayload();
+ assertNotNull(hash);
+
+ JingleFileTransferFileInfo fileInfo = hash.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(513L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(566L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+ @Test
+ public void testParse_with_Some_variables() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is good.</desc><media-type>MediaAAC</media-type>" +
+ "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file></checksum>"));
+
+
+ JingleFileTransferHash hash = (JingleFileTransferHash)parser.getPayload();
+ assertNotNull(hash);
+
+ JingleFileTransferFileInfo fileInfo = hash.getFileInfo();
+ assertNotNull(fileInfo);
+
+ assertEquals("Isaac", fileInfo.getName());
+ assertEquals("It is good.", fileInfo.getDescription());
+ assertEquals("MediaAAC", fileInfo.getMediaType());
+ assertEquals(0L, fileInfo.getSize());
+ assertEquals(DateTime.dateToString(new Date(0L)), DateTime.dateToString(fileInfo.getDate()));
+ assertEquals(false, fileInfo.getSupportsRangeRequests());
+ assertEquals(0L, fileInfo.getRangeOffset());
+ assertEquals(new ByteArray(), fileInfo.getHash("MD5"));
+ }
+
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java
new file mode 100644
index 0000000..46d9529
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleIBBTransportMethodPayloadParserTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.parser.payloadparsers.JingleIBBTransportMethodPayloadParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class JingleIBBTransportMethodPayloadParserTest {
+
+ public JingleIBBTransportMethodPayloadParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>"));
+
+ JingleIBBTransportPayload payload = (JingleIBBTransportPayload)parser.getPayload();
+ assertEquals(Integer.valueOf(4), payload.getBlockSize());
+ assertEquals("546-45", payload.getSessionID());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java
new file mode 100644
index 0000000..ec7f044
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleParserTest.java
@@ -0,0 +1,649 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+/*
+ * Copyright (c) 2015 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 org.junit.Test;
+import com.isode.stroke.serializer.payloadserializers.JingleContentPayloadSerializer;
+import com.isode.stroke.elements.JinglePayload;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.elements.JingleFileTransferDescription;
+import com.isode.stroke.elements.JingleFileTransferFileInfo;
+import com.isode.stroke.elements.JingleIBBTransportPayload;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleFileTransferHash;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.base.DateTime;
+import com.isode.stroke.stringcodecs.Base64;
+import java.util.Vector;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import com.isode.stroke.network.HostAddress;
+import com.isode.stroke.network.HostAddressPort;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class JingleParserTest {
+
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
+
+ public JingleParserTest() {
+
+ }
+
+ @Test
+ public void testParse_Xep0166_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason>\n" +
+ " <success/>\n" +
+ " </reason>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ }
+
+ //http://xmpp.org/extensions/xep-0166.html#example-8
+ @Test
+ public void testParse_Xep0166_Example8() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason>\n" +
+ " <success/>\n" +
+ " <text>Sorry, gotta go!</text>\n" +
+ " </reason>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ assertEquals("Sorry, gotta go!", jingle.getReason().text);
+ }
+
+ // IBB Transport Method Examples
+
+ // http://xmpp.org/extensions/xep-0261.html#example-1
+ @Test
+ public void testParse_Xep0261_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='4096'\n" +
+ " sid='ch3d9s71'/>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+ assertEquals(1, payload.getTransports().size());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(4096), transportPayload.getBlockSize());
+ assertEquals("ch3d9s71", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-1
+ @Test
+ public void testParse_Xep0261_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " responder='juliet@capulet.lit/balcony'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='2048'\n" +
+ " sid='ch3d9s71'/>\n" +
+ " </content>\n" +
+ " </jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals(new JID("juliet@capulet.lit/balcony"), jingle.getResponder());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+ assertEquals(1, payload.getTransports().size());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(2048), transportPayload.getBlockSize());
+ assertEquals("ch3d9s71", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-9
+ @Test
+ public void testParse_Xep0261_Example9() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='transport-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:ibb:1'\n" +
+ " block-size='2048'\n" +
+ " sid='bt8a71h6'/>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.TransportInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> payloads = jingle.getContents();
+ assertEquals(1, payloads.size());
+ JingleContentPayload payload = payloads.get(0);
+ assertEquals(JingleContentPayload.Creator.InitiatorCreator, payload.getCreator());
+ assertEquals("ex", payload.getName());
+
+ JingleIBBTransportPayload transportPayload = payload.getTransport(new JingleIBBTransportPayload());
+ assertNotNull(transportPayload);
+ assertEquals(Integer.valueOf(2048), transportPayload.getBlockSize());
+ assertEquals("bt8a71h6", transportPayload.getSessionID());
+ }
+
+ // http://xmpp.org/extensions/xep-0261.html#example-13
+ @Test
+ public void testParse_Xep0261_Example13() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-terminate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <reason><success/></reason>\n" +
+ " </jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionTerminate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+ assertEquals(JinglePayload.Reason.Type.Success, jingle.getReason().type);
+ }
+
+ // Jingle File Transfer Examples
+
+ // http://xmpp.org/extensions/xep-0234.html#example-1
+ @Test
+ public void testParse_Xep0234_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='851ba2'>\n" +
+ "<content creator='initiator' name='a-file-offer'>\n" +
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ "<file>\n" +
+ "<date>1969-07-21T02:56:15Z</date>\n" +
+ "<desc>This is a test. If this were a real file...</desc>\n" +
+ "<media-type>text/plain</media-type>\n" +
+ "<name>test.txt</name>\n" +
+ "<range/>\n" +
+ "<size>1022</size>\n" +
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ "</file>\n" +
+ "</description>\n" +
+ "<transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ "<candidate cid='hft54dqy'\n" +
+ " host='192.168.4.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5086'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ "<candidate cid='hutr46fe'\n" +
+ " host='24.24.24.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5087'\n" +
+ " priority='8258636'\n" +
+ " type='direct'/>\n" +
+ "</transport>\n" +
+ "</content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("851ba2", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleFileTransferDescription description = contents.get(0).getDescription(new JingleFileTransferDescription());
+
+ assertNotNull(description);
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertEquals("test.txt", fileInfo.getName());
+ assertEquals("sha-1", fileInfo.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(fileInfo.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(1022L, fileInfo.getSize());
+ assertEquals("This is a test. If this were a real file...", fileInfo.getDescription());
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"), fileInfo.getDate());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-3
+ @Test
+ public void testParse_Xep0234_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='851ba2'>\n" +
+ "<content creator='initiator' name='a-file-offer'>\n" +
+ "<description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ "<file>\n" +
+ "<date>1969-07-21T02:56:15Z</date>\n" +
+ "<desc>This is a test. If this were a real file...</desc>\n" +
+ "<media-type>text/plain</media-type>\n" +
+ "<name>test.txt</name>\n" +
+ "<range/>\n" +
+ "<size>1022</size>\n" +
+ "<hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ "</file>\n" +
+ "</description>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("851ba2", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleFileTransferDescription description = contents.get(0).getDescription(new JingleFileTransferDescription());
+
+ assertNotNull(description);
+
+ JingleFileTransferFileInfo fileInfo = description.getFileInfo();
+ assertEquals("test.txt", fileInfo.getName());
+ assertEquals("sha-1", fileInfo.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(fileInfo.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(1022L, fileInfo.getSize());
+ assertEquals("This is a test. If this were a real file...", fileInfo.getDescription());
+ assertEquals(true, fileInfo.getSupportsRangeRequests());
+ assertEquals(DateTime.stringToDate("1969-07-21T02:56:15Z"), fileInfo.getDate());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-5
+ @Test
+ public void testParse_Xep0234_Example5() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='transport-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate-used cid='hr65dqyd'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.TransportInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ Vector<JingleContentPayload> contents = jingle.getContents();
+ assertEquals(1, contents.size());
+
+ JingleS5BTransportPayload transport = contents.get(0).getTransport(new JingleS5BTransportPayload());
+ assertNotNull(transport);
+
+ assertEquals("vj3hs98y", transport.getSessionID());
+ assertEquals("hr65dqyd", transport.getCandidateUsed());
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-8
+ @Test
+ public void testParse_Xep0234_Example8() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-info'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <checksum xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ " <file>\n" +
+ " <hash xmlns='urn:xmpp:hashes:0' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ " </file>\n" +
+ " </checksum>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInfo, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleFileTransferHash hash = jingle.getPayload(new JingleFileTransferHash());
+ assertNotNull(hash);
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(hash.getFileInfo().getHash("sha-1")));
+ }
+
+ // http://xmpp.org/extensions/xep-0234.html#example-10
+ @Test
+ public void testParse_Xep0234_Example10() {
+ logger_.setLevel(Level.FINE);
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='uj3b2'>\n" +
+ " <content creator='initiator' name='a-file-request'>\n" +
+ " <description xmlns='urn:xmpp:jingle:apps:file-transfer:4'>\n" +
+ " <file>\n" +
+ " <hash xmlns='urn:xmpp:hashes:1' algo='sha-1'>VS2nSZMIUsaa5dIUHTdmsQ==</hash>\n" +
+ " <range offset='270336'/>\n" +
+ " </file>\n" +
+ " </description>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='xig361fj'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("uj3b2", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleFileTransferFileInfo file = content.getDescription(new JingleFileTransferDescription()).getFileInfo();
+ assertEquals("sha-1", file.getHashes().entrySet().iterator().next().getKey());
+ assertEquals("VS2nSZMIUsaa5dIUHTdmsQ==", Base64.encode(file.getHashes().entrySet().iterator().next().getValue()));
+ assertEquals(270336L, file.getRangeOffset());
+ assertEquals(true, file.getSupportsRangeRequests());
+ }
+
+ // http://xmpp.org/extensions/xep-0260.html#example-1
+ @Test
+ public void testParse_Xep0260_Example1() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-initiate'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='hft54dqy'\n" +
+ " host='192.168.4.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5086'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hutr46fe'\n" +
+ " host='24.24.24.1'\n" +
+ " jid='romeo@montague.lit/orchard'\n" +
+ " port='5087'\n" +
+ " priority='8258636'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionInitiate, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleS5BTransportPayload s5bPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(s5bPayload);
+
+ assertEquals("vj3hs98y", s5bPayload.getSessionID());
+ assertEquals(JingleS5BTransportPayload.Mode.TCPMode, s5bPayload.getMode());
+ assertEquals(false, s5bPayload.hasCandidateError());
+ assertEquals(false, s5bPayload.hasProxyError());
+ assertEquals("", s5bPayload.getActivated());
+ assertEquals("", s5bPayload.getCandidateUsed());
+ assertEquals(2, s5bPayload.getCandidates().size());
+
+ try {
+ JingleS5BTransportPayload.Candidate candidate;
+ candidate = s5bPayload.getCandidates().get(0);
+ assertEquals("hft54dqy", candidate.cid);
+ assertEquals(new JID("romeo@montague.lit/orchard"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("192.168.4.1")), 5086), candidate.hostPort);
+ assertEquals(8257636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(1);
+ assertEquals("hutr46fe", candidate.cid);
+ assertEquals(new JID("romeo@montague.lit/orchard"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("24.24.24.1")), 5087), candidate.hostPort);
+ assertEquals(8258636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+ } catch (UnknownHostException e) {
+
+ }
+ }
+
+ // http://xmpp.org/extensions/xep-0260.html#example-3
+ @Test
+ public void testParse_Xep0260_Example3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse(
+ "<jingle xmlns='urn:xmpp:jingle:1'\n" +
+ " action='session-accept'\n" +
+ " initiator='romeo@montague.lit/orchard'\n" +
+ " sid='a73sjjvkla37jfea'>\n" +
+ " <content creator='initiator' name='ex'>\n" +
+ " <description xmlns='urn:xmpp:example'/>\n" +
+ " <transport xmlns='urn:xmpp:jingle:transports:s5b:1'\n" +
+ " dstaddr='1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba'\n" +
+ " mode='tcp'\n" +
+ " sid='vj3hs98y'>\n" +
+ " <candidate cid='ht567dq'\n" +
+ " host='192.169.1.10'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257636'\n" +
+ " type='direct'/>\n" +
+ " <candidate cid='hr65dqyd'\n" +
+ " host='134.102.201.180'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='16453'\n" +
+ " priority='7929856'\n" +
+ " type='assisted'/>\n" +
+ " <candidate cid='grt654q2'\n" +
+ " host='2001:638:708:30c9:219:d1ff:fea4:a17d'\n" +
+ " jid='juliet@capulet.lit/balcony'\n" +
+ " port='6539'\n" +
+ " priority='8257606'\n" +
+ " type='direct'/>\n" +
+ " </transport>\n" +
+ " </content>\n" +
+ "</jingle>\n"
+ ));
+
+ JinglePayload jingle = (JinglePayload)parser.getPayload();
+ assertNotNull(jingle);
+ assertEquals(JinglePayload.Action.SessionAccept, jingle.getAction());
+ assertEquals(new JID("romeo@montague.lit/orchard"), jingle.getInitiator());
+ assertEquals("a73sjjvkla37jfea", jingle.getSessionID());
+
+ JingleContentPayload content = jingle.getPayload(new JingleContentPayload());
+ assertNotNull(content);
+
+ JingleS5BTransportPayload s5bPayload = content.getTransport(new JingleS5BTransportPayload());
+ assertNotNull(s5bPayload);
+
+ assertEquals("vj3hs98y", s5bPayload.getSessionID());
+ assertEquals(JingleS5BTransportPayload.Mode.TCPMode, s5bPayload.getMode());
+ assertEquals("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba", s5bPayload.getDstAddr());
+ assertEquals(false, s5bPayload.hasCandidateError());
+ assertEquals(false, s5bPayload.hasProxyError());
+ assertEquals("", s5bPayload.getActivated());
+ assertEquals("", s5bPayload.getCandidateUsed());
+ assertEquals(3, s5bPayload.getCandidates().size());
+
+ try {
+ JingleS5BTransportPayload.Candidate candidate;
+ candidate = s5bPayload.getCandidates().get(0);
+ assertEquals("ht567dq", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("192.169.1.10")), 6539), candidate.hostPort);
+ assertEquals(8257636, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(1);
+ assertEquals("hr65dqyd", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("134.102.201.180")), 16453), candidate.hostPort);
+ assertEquals(7929856, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+
+ candidate = s5bPayload.getCandidates().get(2);
+ assertEquals("grt654q2", candidate.cid);
+ assertEquals(new JID("juliet@capulet.lit/balcony"), candidate.jid);
+ assertEquals(new HostAddressPort(new HostAddress(InetAddress.getByName("2001:638:708:30c9:219:d1ff:fea4:a17d")), 6539), candidate.hostPort);
+ assertEquals(8257606, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.DirectType, candidate.type);
+ } catch (UnknownHostException e) {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java
new file mode 100644
index 0000000..ac9e03f
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/JingleS5BTransportMethodPayloadParserTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.junit.Test;
+import com.isode.stroke.elements.JingleS5BTransportPayload;
+import com.isode.stroke.elements.JingleTransportPayload;
+import com.isode.stroke.parser.payloadparsers.JingleS5BTransportMethodPayloadParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import com.isode.stroke.jid.JID;
+
+public class JingleS5BTransportMethodPayloadParserTest {
+
+ public JingleS5BTransportMethodPayloadParserTest() {
+
+ }
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<transport dstaddr=\"UK\" mode=\"tcp\" sid=\"\" xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" +
+ "<candidate cid=\"cid\" host=\"173.194.36.112\" jid=\"blas@nal.vx\" port=\"-1\" priority=\"4\" type=\"assisted\"/>" +
+ "<proxy-error/><activated cid=\"Activity\"/><candidate-used cid=\"Candidate\"/></transport>"));
+
+ JingleS5BTransportPayload payload = (JingleS5BTransportPayload)parser.getPayload();
+ assertEquals (JingleS5BTransportPayload.Mode.TCPMode, payload.getMode());
+ assertEquals ("Candidate", payload.getCandidateUsed());
+ assertEquals ("Activity", payload.getActivated());
+ assertEquals ("UK", payload.getDstAddr());
+ assertEquals (false, payload.hasCandidateError());
+ assertEquals (true, payload.hasProxyError());
+
+ assertEquals(1, payload.getCandidates().size());
+ JingleS5BTransportPayload.Candidate candidate = payload.getCandidates().get(0);
+ assertEquals("cid", candidate.cid);
+ assertEquals(new JID("blas@nal.vx"), candidate.jid);
+ assertEquals("/173.194.36.112", candidate.hostPort.getAddress().getInetAddress().toString());
+ assertEquals(4, candidate.priority);
+ assertEquals(JingleS5BTransportPayload.Candidate.Type.AssistedType, candidate.type);
+ }
+} \ No newline at end of file