diff options
Diffstat (limited to 'test/com/isode')
13 files changed, 1510 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 diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java new file mode 100644 index 0000000..686ad7e --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleContentPayloadSerializerTest.java @@ -0,0 +1,189 @@ +/* + * 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.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 com.isode.stroke.network.HostAddress; +import com.isode.stroke.network.HostAddressPort; +import java.util.Date; +import java.util.TimeZone; +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class JingleContentPayloadSerializerTest { + + /** + * Default Constructor. + */ + public JingleContentPayloadSerializerTest() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + @Test + public void testSerialize() { + JingleContentPayloadSerializer testling = new JingleContentPayloadSerializer(); + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("Erin"); + + JingleFileTransferDescription description = new JingleFileTransferDescription(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.setSize(513L); + fileInfo.setDate(new Date(1434056150620L)); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(566L); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + description.setFileInfo(fileInfo); + content.addDescription(description); + + JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload(); + jingleIBBTransportPayload.setBlockSize(4); + jingleIBBTransportPayload.setSessionID("546-45"); + content.addTransport(jingleIBBTransportPayload); + + JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload(); + jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode); + JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate(); + candidate.cid = "cid"; + candidate.jid = new JID("blas@nal.vx"); + try { + candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112"))); + } catch (UnknownHostException e) { + + } + candidate.priority = 4; + candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType; + jingleS5BTransportPayload.addCandidate(candidate); + jingleS5BTransportPayload.setCandidateUsed("Candidate"); + jingleS5BTransportPayload.setActivated("Activity"); + jingleS5BTransportPayload.setDstAddr("UK"); + jingleS5BTransportPayload.setCandidateError(false); + jingleS5BTransportPayload.setProxyError(true); + content.addTransport(jingleS5BTransportPayload); + + String expectedResult = "<content 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>"; + assertEquals(expectedResult, testling.serialize(content)); + } + + @Test + public void testSerialize_MultiplePayloads() { + JingleContentPayloadSerializer testling = new JingleContentPayloadSerializer(); + JingleContentPayload content = new JingleContentPayload(); + content.setCreator(JingleContentPayload.Creator.InitiatorCreator); + content.setName("Erin"); + + JingleFileTransferDescription description = new JingleFileTransferDescription(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.setSize(513L); + fileInfo.setDate(new Date(1434056150620L)); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(566L); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + description.setFileInfo(fileInfo); + content.addDescription(description); + + JingleFileTransferDescription description2 = new JingleFileTransferDescription(); + JingleFileTransferFileInfo fileInfo2 = new JingleFileTransferFileInfo(); + fileInfo2.setName("Newton"); + fileInfo2.setDescription("It is bad."); + fileInfo2.setMediaType("MediaJPG"); + fileInfo2.setSize(556L); + fileInfo2.setSupportsRangeRequests(false); + fileInfo2.addHash(new HashElement("SHA-1", new ByteArray())); + description2.setFileInfo(fileInfo2); + content.addDescription(description2); + + JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload(); + jingleIBBTransportPayload.setBlockSize(4); + jingleIBBTransportPayload.setSessionID("546-45"); + content.addTransport(jingleIBBTransportPayload); + + + JingleIBBTransportPayload jingleIBBTransportPayload2 = new JingleIBBTransportPayload(); + jingleIBBTransportPayload2.setBlockSize(43); + jingleIBBTransportPayload2.setSessionID("546-452"); + content.addTransport(jingleIBBTransportPayload2); + + JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload(); + jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode); + JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate(); + candidate.cid = "cid"; + candidate.jid = new JID("blas@nal.vx"); + try { + candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112"))); + } catch (UnknownHostException e) { + + } + candidate.priority = 4; + candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType; + jingleS5BTransportPayload.addCandidate(candidate); + jingleS5BTransportPayload.setCandidateUsed("Candidate"); + jingleS5BTransportPayload.setActivated("Activity"); + jingleS5BTransportPayload.setDstAddr("UK"); + jingleS5BTransportPayload.setCandidateError(false); + jingleS5BTransportPayload.setProxyError(true); + content.addTransport(jingleS5BTransportPayload); + + JingleS5BTransportPayload jingleS5BTransportPayload2 = new JingleS5BTransportPayload(); + jingleS5BTransportPayload2.setMode(JingleS5BTransportPayload.Mode.TCPMode); + JingleS5BTransportPayload.Candidate candidate2 = new JingleS5BTransportPayload.Candidate(); + candidate2.cid = "cid"; + candidate2.jid = new JID("blas@nal.vx"); + try { + candidate2.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112"))); + } catch (UnknownHostException e) { + + } + candidate2.priority = 4; + candidate2.type = JingleS5BTransportPayload.Candidate.Type.AssistedType; + jingleS5BTransportPayload2.addCandidate(candidate2); + jingleS5BTransportPayload2.setCandidateUsed("Candy"); + jingleS5BTransportPayload2.setActivated("Active"); + jingleS5BTransportPayload2.setDstAddr("USA"); + jingleS5BTransportPayload2.setCandidateError(true); + jingleS5BTransportPayload2.setProxyError(false); + content.addTransport(jingleS5BTransportPayload2); + + String expectedResult = "<content 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>" + + "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\"><file><desc>It is bad.</desc><media-type>MediaJPG</media-type>" + + "<name>Newton</name><size>556</size><hash algo=\"SHA-1\" xmlns=\"urn:xmpp:hashes:1\"/></file></description>" + + "<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" + + "<transport block-size=\"43\" sid=\"546-452\" 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>" + + "<transport dstaddr=\"USA\" 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\"/><candidate-error/>" + + "<activated cid=\"Active\"/><candidate-used cid=\"Candy\"/></transport></content>"; + assertEquals(expectedResult, testling.serialize(content)); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java new file mode 100644 index 0000000..720aa65 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferDescriptionSerializerTest.java @@ -0,0 +1,66 @@ +/* + * 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.JingleFileTransferDescriptionSerializer; +import com.isode.stroke.elements.JingleFileTransferDescription; +import com.isode.stroke.elements.JingleFileTransferFileInfo; +import com.isode.stroke.elements.HashElement; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.base.ByteArray; +import java.util.Date; +import java.util.TimeZone; + +public class JingleFileTransferDescriptionSerializerTest { + + /** + * Default Constructor. + */ + public JingleFileTransferDescriptionSerializerTest() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + @Test + public void testSerialize_FileInfo_withAllVariables() { + JingleFileTransferDescriptionSerializer testling = new JingleFileTransferDescriptionSerializer(); + JingleFileTransferDescription description = new JingleFileTransferDescription(); + + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.setSize(513L); + fileInfo.setDate(new Date(1434056150620L)); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(566L); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + + description.setFileInfo(fileInfo); + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(description)); + } + + @Test + public void testSerialize_FileInfo_withSomeVariables() { + JingleFileTransferDescriptionSerializer testling = new JingleFileTransferDescriptionSerializer(); + JingleFileTransferDescription description = new JingleFileTransferDescription(); + + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + description.setFileInfo(fileInfo); + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(description)); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java new file mode 100644 index 0000000..69e5606 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferFileInfoSerializerTest.java @@ -0,0 +1,57 @@ +/* + * 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.JingleFileTransferFileInfoSerializer; +import com.isode.stroke.elements.JingleFileTransferFileInfo; +import com.isode.stroke.elements.HashElement; +import com.isode.stroke.base.ByteArray; +import java.util.Date; +import java.util.TimeZone; + +public class JingleFileTransferFileInfoSerializerTest { + + /** + * Default Constructor. + */ + public JingleFileTransferFileInfoSerializerTest() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + @Test + public void testSerialize_withAllVariables() { + JingleFileTransferFileInfoSerializer testling = new JingleFileTransferFileInfoSerializer(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.setSize(513L); + fileInfo.setDate(new Date(1434056150620L)); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(566L); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(fileInfo)); + } + + @Test + public void testSerialize_withSomeVariables() { + JingleFileTransferFileInfoSerializer testling = new JingleFileTransferFileInfoSerializer(); + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + String expectedResult = "<file><desc>It is good.</desc><media-type>MediaAAC</media-type>" + + "<name>Isaac</name><hash algo=\"MD5\" xmlns=\"urn:xmpp:hashes:1\"/></file>"; + assertEquals(expectedResult, testling.serialize(fileInfo)); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.java new file mode 100644 index 0000000..96410bf --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleFileTransferHashSerializerTest.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.serializer.payloadserializers; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.payloadserializers.JingleFileTransferHashSerializer; +import com.isode.stroke.elements.JingleFileTransferHash; +import com.isode.stroke.elements.JingleFileTransferFileInfo; +import com.isode.stroke.elements.HashElement; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.base.ByteArray; +import java.util.Date; + +public class JingleFileTransferHashSerializerTest { + + /** + * Default Constructor. + */ + public JingleFileTransferHashSerializerTest() { + + } + + @Test + public void testSerialize_FileInfo_withAllVariables() { + JingleFileTransferHashSerializer testling = new JingleFileTransferHashSerializer(); + JingleFileTransferHash hash = new JingleFileTransferHash(); + + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.setSize(513L); + fileInfo.setDate(new Date(1434056150620L)); + fileInfo.setSupportsRangeRequests(true); + fileInfo.setRangeOffset(566L); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + + hash.setFileInfo(fileInfo); + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(hash)); + } + + @Test + public void testSerialize_FileInfo_withSomeVariables() { + JingleFileTransferHashSerializer testling = new JingleFileTransferHashSerializer(); + JingleFileTransferHash hash = new JingleFileTransferHash(); + + JingleFileTransferFileInfo fileInfo = new JingleFileTransferFileInfo(); + fileInfo.setName("Isaac"); + fileInfo.setDescription("It is good."); + fileInfo.setMediaType("MediaAAC"); + fileInfo.addHash(new HashElement("MD5", new ByteArray())); + hash.setFileInfo(fileInfo); + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(hash)); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java new file mode 100644 index 0000000..3f1f576 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleIBBTransportPayloadSerializerTest.java @@ -0,0 +1,32 @@ +/* + * 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.JingleIBBTransportPayloadSerializer; +import com.isode.stroke.elements.JingleIBBTransportPayload; + +public class JingleIBBTransportPayloadSerializerTest { + + /** + * Default Constructor. + */ + public JingleIBBTransportPayloadSerializerTest() { + + } + + @Test + public void testSerialize() { + JingleIBBTransportPayloadSerializer testling = new JingleIBBTransportPayloadSerializer(); + JingleIBBTransportPayload jingleIBBTransportPayload = new JingleIBBTransportPayload(); + jingleIBBTransportPayload.setBlockSize(4); + jingleIBBTransportPayload.setSessionID("546-45"); + String expectedResult = "<transport block-size=\"4\" sid=\"546-45\" xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>"; + assertEquals(expectedResult, testling.serialize(jingleIBBTransportPayload)); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java new file mode 100644 index 0000000..6a76c8c --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/JingleS5BTransportPayloadSerializerTest.java @@ -0,0 +1,55 @@ +/* + * 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.JingleS5BTransportPayloadSerializer; +import com.isode.stroke.elements.JingleS5BTransportPayload; +import com.isode.stroke.jid.JID; +import com.isode.stroke.network.HostAddressPort; +import com.isode.stroke.network.HostAddress; +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class JingleS5BTransportPayloadSerializerTest { + + /** + * Default Constructor. + */ + public JingleS5BTransportPayloadSerializerTest() { + + } + + @Test + public void testSerialize() { + JingleS5BTransportPayloadSerializer testling = new JingleS5BTransportPayloadSerializer(); + JingleS5BTransportPayload jingleS5BTransportPayload = new JingleS5BTransportPayload(); + jingleS5BTransportPayload.setMode(JingleS5BTransportPayload.Mode.TCPMode); + JingleS5BTransportPayload.Candidate candidate = new JingleS5BTransportPayload.Candidate(); + candidate.cid = "cid"; + candidate.jid = new JID("blas@nal.vx"); + try { + candidate.hostPort = new HostAddressPort(new HostAddress(InetAddress.getByName("173.194.36.112"))); + } catch (UnknownHostException e) { + + } + candidate.priority = 4; + candidate.type = JingleS5BTransportPayload.Candidate.Type.AssistedType; + jingleS5BTransportPayload.addCandidate(candidate); + jingleS5BTransportPayload.setCandidateUsed("Candidate"); + jingleS5BTransportPayload.setActivated("Activity"); + jingleS5BTransportPayload.setDstAddr("UK"); + jingleS5BTransportPayload.setCandidateError(false); + jingleS5BTransportPayload.setProxyError(true); + + String expectedResult = "<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>"; + assertEquals(expectedResult, testling.serialize(jingleS5BTransportPayload)); + } +}
\ No newline at end of file |