1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-14 19:49:38 +02:00

Add support for XEP-0166, XEP-0260, XEP-0261

This commit is contained in:
vanitasvitae 2017-08-17 12:18:33 +02:00
parent 9bb0ed150b
commit d7f974dc69
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
113 changed files with 6016 additions and 3725 deletions

View file

@ -0,0 +1,48 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.util.FullJidAndSessionId;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
public class FullJidAndSessionIdTest extends SmackTestSuite {
@Test
public void equalityTest() throws XmppStringprepException {
FullJid albert = JidCreate.fullFrom("albert@einstein.emc/squared");
String albertId = "10121922";
FullJidAndSessionId fns = new FullJidAndSessionId(albert, albertId);
assertEquals("10121922", fns.getSessionId());
assertEquals(JidCreate.fullFrom("albert@einstein.emc/squared"), fns.getFullJid());
FullJidAndSessionId fns2 = new FullJidAndSessionId(JidCreate.fullFrom("albert@einstein.emc/squared"), "10121922");
assertTrue(fns.equals(fns2));
assertEquals(fns.hashCode(), fns2.hashCode());
assertNotSame(fns, new FullJidAndSessionId(JidCreate.fullFrom("albert@einstein.emc/squared"), "11111111"));
}
}

View file

@ -0,0 +1,160 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.util.Date;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.TestIQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.component.JingleContent;
import org.jivesoftware.smackx.jingle.component.JingleSession;
import org.jivesoftware.smackx.jingle.component.JingleTransport;
import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.util.Role;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* Test the JingleContent class.
*/
public class JingleContentElementTest extends SmackTestSuite {
@Test(expected = NullPointerException.class)
public void emptyBuilderThrowsTest() {
JingleContentElement.Builder builder = JingleContentElement.getBuilder();
builder.build();
}
@Test(expected = IllegalArgumentException.class)
public void onlyCreatorBuilderThrowsTest() {
JingleContentElement.Builder builder = JingleContentElement.getBuilder();
builder.setCreator(JingleContentElement.Creator.initiator);
builder.build();
}
@Test
public void parserTest() throws Exception {
JingleContentElement.Builder builder = JingleContentElement.getBuilder();
builder.setCreator(JingleContentElement.Creator.initiator);
builder.setName("A name");
JingleContentElement content = builder.build();
assertNotNull(content);
assertNull(content.getDescription());
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
assertEquals("A name", content.getName());
builder.setSenders(JingleContentElement.Senders.both);
content = builder.build();
assertEquals(JingleContentElement.Senders.both, content.getSenders());
builder.setDisposition("session");
JingleContentElement content1 = builder.build();
assertEquals("session", content1.getDisposition());
assertNotSame(content.toXML().toString(), content1.toXML().toString());
assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
String xml =
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
"</content>";
assertEquals(xml, content1.toXML().toString());
JingleContent fromElement = JingleContent.fromElement(content1);
assertEquals("A name", fromElement.getName());
assertEquals(content1.getCreator(), fromElement.getCreator());
assertEquals(content1.getSenders(), fromElement.getSenders());
assertNull(fromElement.getTransport());
assertNull(fromElement.getDescription());
assertNull(fromElement.getSecurity());
assertXMLEqual(xml, fromElement.getElement().toXML().toString());
}
@Test
public void handleJingleRequestTest() {
XMPPConnection connection = mock(XMPPConnection.class);
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
IQ descriptionInfoResult = new TestIQ("description_info", "test");
IQ securityInfoResult = new TestIQ("description_info", "test");
IQ sessionInfoResult = new TestIQ("session_info", "test");
IQ transportAcceptResult = new TestIQ("transport_accept", "test");
IQ transportInfoResult = new TestIQ("transport_info", "test");
IQ transportRejectResult = new TestIQ("transport_reject", "test");
IQ transportReplaceResult = new TestIQ("transport_replace", "test");
JingleElement contentModify = JingleElement.getBuilder().setAction(JingleAction.content_modify).setSessionId("session").build();
assertTrue(content.handleJingleRequest(contentModify, connection).getError().getCondition() == XMPPError.Condition.feature_not_implemented);
JingleElement descriptionInfo = JingleElement.getBuilder().setAction(JingleAction.description_info).setSessionId("session").build();
assertTrue(content.handleJingleRequest(descriptionInfo, connection).getError().getCondition() == XMPPError.Condition.feature_not_implemented);
}
@Test
public void startTest() throws XmppStringprepException, SmackException.NotConnectedException, InterruptedException {
XMPPConnection connection = new DummyConnection();
JingleSession session = new JingleSession(JingleManager.getInstanceFor(connection), connection.getUser().asFullJidOrThrow(), JidCreate.fullFrom("bob@baumeister.de/buddl"), Role.initiator, "session");
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
JingleTransport<?> transport = mock(JingleTransport.class);
content.setTransport(transport);
session.addContent(content);
final boolean[] sync = new boolean[1];
content.start(connection);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
sync[0] = true;
return null;
}
}).when(transport).establishOutgoingBytestreamSession(connection, content, session);
Date start = new Date();
while (!sync[0]) {
Date now = new Date();
if (now.getTime() - start.getTime() > 2000) {
break;
}
//Unfortunately there are no ResultSyncPoints available, so we have to cheat a little bit.
}
verify(transport).establishOutgoingBytestreamSession(connection, content, session);
}
}

View file

@ -1,76 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertNull;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.junit.Test;
/**
* Test the JingleContent class.
*/
public class JingleContentTest extends SmackTestSuite {
@Test(expected = NullPointerException.class)
public void emptyBuilderThrowsTest() {
JingleContent.Builder builder = JingleContent.getBuilder();
builder.build();
}
@Test(expected = IllegalArgumentException.class)
public void onlyCreatorBuilderThrowsTest() {
JingleContent.Builder builder = JingleContent.getBuilder();
builder.setCreator(JingleContent.Creator.initiator);
builder.build();
}
@Test
public void parserTest() throws Exception {
JingleContent.Builder builder = JingleContent.getBuilder();
builder.setCreator(JingleContent.Creator.initiator);
builder.setName("A name");
JingleContent content = builder.build();
assertNotNull(content);
assertNull(content.getDescription());
assertEquals(JingleContent.Creator.initiator, content.getCreator());
assertEquals("A name", content.getName());
builder.setSenders(JingleContent.Senders.both);
content = builder.build();
assertEquals(JingleContent.Senders.both, content.getSenders());
builder.setDisposition("session");
JingleContent content1 = builder.build();
assertEquals("session", content1.getDisposition());
assertNotSame(content.toXML().toString(), content1.toXML().toString());
assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
String xml =
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
"</content>";
assertEquals(xml, content1.toXML().toString());
}
}

View file

@ -0,0 +1,447 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import java.io.IOException;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
import org.jivesoftware.smackx.jingle.provider.JingleProvider;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.xml.sax.SAXException;
/**
* Test the JingleUtil class.
*/
public class JingleElementTest extends SmackTestSuite {
private FullJid romeo;
private FullJid juliet;
@Before
public void setup() throws XmppStringprepException {
XMPPConnection connection = new DummyConnection(
DummyConnection.getDummyConfigurationBuilder()
.setUsernameAndPassword("romeo@montague.lit",
"iluvJulibabe13").build());
JingleManager jm = JingleManager.getInstanceFor(connection);
romeo = connection.getUser().asFullJidOrThrow();
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
}
@Test
public void createSessionTerminateDeclineTest() throws Exception {
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "thisismadness", JingleReasonElement.Reason.decline);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisismadness'>" +
"<reason>" +
"<decline/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
assertXMLEqual(xml, terminate.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.decline);
}
@Test
public void createSessionTerminateSuccessTest() throws Exception {
JingleElement success = JingleElement.createSessionTerminate(juliet, "thisissparta", JingleReasonElement.Reason.success);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisissparta'>" +
"<reason>" +
"<success/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, success.getStanzaId(), jingleXML);
assertXMLEqual(xml, success.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.success);
}
@Test
public void createSessionTerminateBusyTest() throws Exception {
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisispatrick", JingleReasonElement.Reason.busy);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisispatrick'>" +
"<reason>" +
"<busy/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
assertXMLEqual(xml, busy.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.busy);
}
@Test
public void createSessionTerminateAlternativeSessionTest() throws Exception {
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisistherhythm", JingleReasonElement.AlternativeSession("ofthenight"));
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisistherhythm'>" +
"<reason>" +
"<alternative-session>" +
"<sid>ofthenight</sid>" +
"</alternative-session>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
assertXMLEqual(xml, busy.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.alternative_session);
JingleReasonElement.AlternativeSession alt = (JingleReasonElement.AlternativeSession) jingle.getReason();
assertEquals("ofthenight", alt.getAlternativeSessionId());
}
@Test
public void createSessionTerminateCancelTest() throws Exception {
JingleElement cancel = JingleElement.createSessionTerminate(juliet, "thisistheend", JingleReasonElement.Reason.cancel);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisistheend'>" +
"<reason>" +
"<cancel/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
assertXMLEqual(xml, cancel.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.cancel);
}
@Test
public void createSessionTerminateUnsupportedTransportsTest() throws Exception {
JingleElement unsupportedTransports = JingleElement.createSessionTerminate(juliet, "thisisus", JingleReasonElement.Reason.unsupported_transports);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisisus'>" +
"<reason>" +
"<unsupported-transports/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, unsupportedTransports.getStanzaId(), jingleXML);
assertXMLEqual(xml, unsupportedTransports.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_transports);
}
@Test
public void createSessionTerminateUnsupportedApplicationsTest() throws Exception {
JingleElement unsupportedApplications = JingleElement.createSessionTerminate(juliet, "thisiswar", JingleReasonElement.Reason.unsupported_applications);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisiswar'>" +
"<reason>" +
"<unsupported-applications/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, unsupportedApplications.getStanzaId(), jingleXML);
assertXMLEqual(xml, unsupportedApplications.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(jingle.getAction(), JingleAction.session_terminate);
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_applications);
}
@Test
public void createSessionTerminateFailedTransportTest() throws IOException, SAXException {
JingleElement failedTransport = JingleElement.createSessionTerminate(juliet, "derailed", JingleReasonElement.Reason.failed_transport);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='derailed'>" +
"<reason>" +
"<failed-transport/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, failedTransport.getStanzaId(), jingleXML);
assertXMLEqual(xml, failedTransport.toXML().toString());
assertEquals(JingleAction.session_terminate, failedTransport.getAction());
assertEquals(JingleReasonElement.Reason.failed_transport, failedTransport.getReason().asEnum());
}
@Test
public void createSessionTerminateFailedApplicationTest() throws IOException, SAXException {
JingleElement failedApplication = JingleElement.createSessionTerminate(juliet, "crashed", JingleReasonElement.Reason.failed_application);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='crashed'>" +
"<reason>" +
"<failed-application/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, failedApplication.getStanzaId(), jingleXML);
assertXMLEqual(xml, failedApplication.toXML().toString());
assertEquals(JingleAction.session_terminate, failedApplication.getAction());
assertEquals(JingleReasonElement.Reason.failed_application, failedApplication.getReason().asEnum());
}
@Test
public void createSessionPingTest() throws Exception {
JingleElement ping = JingleElement.createSessionPing(juliet, "thisisit");
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-info' " +
"sid='thisisit'/>";
String xml = getIQXML(romeo, juliet, ping.getStanzaId(), jingleXML);
assertXMLEqual(xml, ping.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(JingleAction.session_info, jingle.getAction());
}
@Test
public void createSessionTerminateContentCancelTest() throws Exception {
JingleElement cancel = JingleElement.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContentElement.Creator.initiator, "content123");
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisismumbo#5'>" +
"<content creator='initiator' name='content123'/>" +
"<reason>" +
"<cancel/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
assertXMLEqual(xml, cancel.toXML().toString());
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(JingleAction.session_terminate, jingle.getAction());
assertEquals(JingleReasonElement.Reason.cancel, jingle.getReason().asEnum());
assertEquals("thisismumbo#5", jingle.getSid());
JingleContentElement content = jingle.getContents().get(0);
assertNotNull(content);
assertEquals("content123", content.getName());
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
}
@Test
public void createSessionTerminateIncompatibleParameters() throws IOException, SAXException {
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "incompatibleSID", JingleReasonElement.Reason.incompatible_parameters);
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='incompatibleSID'>" +
"<reason>" +
"<incompatible-parameters/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
assertXMLEqual(xml, terminate.toXML().toString());
assertEquals(JingleReasonElement.Reason.incompatible_parameters, terminate.getReason().asEnum());
assertEquals("incompatibleSID", terminate.getSid());
}
@Test
public void createTransportAcceptTest() throws IOException, SAXException {
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransport.DEFAULT_BLOCK_SIZE));
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='transport-accept' " +
"initiator='" + juliet + "' " +
"sid='transAcc'>" +
"<content creator='initiator' name='cname'>" +
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
"sid='transid'/>" +
"</content>" +
"</jingle>";
String xml = getIQXML(juliet, romeo, transportAccept.getStanzaId(), jingleXML);
assertXMLEqual(xml, transportAccept.toXML().toString());
assertEquals(JingleAction.transport_accept, transportAccept.getAction());
assertEquals("transAcc", transportAccept.getSid());
}
@Test
public void createTransportRejectTest() {
//TODO: Find example
}
@Test
public void createTransportReplaceTest() throws IOException, SAXException {
JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransport.DEFAULT_BLOCK_SIZE));
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='transport-replace' " +
"initiator='" + juliet + "' " +
"sid='transAcc'>" +
"<content creator='initiator' name='cname'>" +
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
"sid='transid'/>" +
"</content>" +
"</jingle>";
String xml = getIQXML(juliet, romeo, transportReplace.getStanzaId(), jingleXML);
assertXMLEqual(xml, transportReplace.toXML().toString());
assertEquals(JingleAction.transport_replace, transportReplace.getAction());
assertEquals("transAcc", transportReplace.getSid());
}
@Test
public void createErrorMalformedRequestTest() throws Exception {
JingleElement j = defaultJingle(romeo, "error123");
IQ error = JingleElement.createJingleErrorMalformedRequest(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='cancel'>" +
"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
@Test
public void createErrorTieBreakTest() throws IOException, SAXException {
JingleElement j = defaultJingle(romeo, "thisistie");
IQ error = JingleElement.createJingleErrorTieBreak(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='cancel'>" +
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<tie-break xmlns='urn:xmpp:jingle:errors:1'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
@Test
public void createErrorUnknownSessionTest() throws IOException, SAXException {
JingleElement j = defaultJingle(romeo, "youknownothingjohnsnow");
IQ error = JingleElement.createJingleErrorUnknownSession(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='cancel'>" +
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<unknown-session xmlns='urn:xmpp:jingle:errors:1'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
@Test
public void createErrorUnknownInitiatorTest() throws IOException, SAXException {
JingleElement j = defaultJingle(romeo, "iamyourfather");
IQ error = JingleElement.createJingleErrorUnknownInitiator(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='cancel'>" +
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
@Test
public void createErrorOutOfOrderTest() throws IOException, SAXException {
JingleElement j = defaultJingle(romeo, "yourfatheriam");
IQ error = JingleElement.createJingleErrorOutOfOrder(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
//"<error type='cancel'>" +
"<error type='modify'>" + //TODO: Why?
"<unexpected-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<out-of-order xmlns='urn:xmpp:jingle:errors:1'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
@Test
public void createErrorUnsupportedInfoTest() throws IOException, SAXException {
JingleElement j = defaultJingle(romeo, "thisstatementiswrong");
IQ error = JingleElement.createJingleErrorUnsupportedInfo(j);
String xml =
"<iq " +
"from='" + romeo + "' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='modify'>" +
"<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
public static String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) {
return "<iq id='" + stanzaId + "' to='" + to + "' type='set'>" +
jingleXML +
"</iq>";
}
private JingleElement defaultJingle(FullJid recipient, String sessionId) {
return JingleElement.createSessionPing(recipient, sessionId);
}
}

View file

@ -20,7 +20,7 @@ import static junit.framework.TestCase.assertEquals;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.jingle.element.JingleError;
import org.jivesoftware.smackx.jingle.element.JingleErrorElement;
import org.jivesoftware.smackx.jingle.provider.JingleErrorProvider;
import org.junit.Test;
@ -28,39 +28,39 @@ import org.junit.Test;
/**
* Test the JingleError class.
*/
public class JingleErrorTest extends SmackTestSuite {
public class JingleErrorElementTest extends SmackTestSuite {
@Test
public void tieBreakTest() throws Exception {
String xml = "<tie-break xmlns='urn:xmpp:jingle:errors:1'/>";
JingleError error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
JingleErrorElement error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
assertEquals(xml, error.toXML().toString());
}
@Test
public void unknownSessionTest() throws Exception {
String xml = "<unknown-session xmlns='urn:xmpp:jingle:errors:1'/>";
JingleError error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
JingleErrorElement error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
assertEquals(xml, error.toXML().toString());
}
@Test
public void unsupportedInfoTest() throws Exception {
String xml = "<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>";
JingleError error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
JingleErrorElement error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
assertEquals(xml, error.toXML().toString());
}
@Test
public void outOfOrderTest() throws Exception {
String xml = "<out-of-order xmlns='urn:xmpp:jingle:errors:1'/>";
JingleError error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
JingleErrorElement error = new JingleErrorProvider().parse(TestUtils.getParser(xml));
assertEquals(xml, error.toXML().toString());
}
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentTest() {
JingleError.fromString("inexistent-error");
JingleErrorElement.fromString("inexistent-error");
}

View file

@ -20,67 +20,67 @@ import static junit.framework.TestCase.assertEquals;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.element.JingleReason;
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
import org.junit.Test;
/**
* Test JingleReason functionality.
*/
public class JingleReasonTest extends SmackTestSuite {
public class JingleReasonElementTest extends SmackTestSuite {
@Test
public void parserTest() {
assertEquals("<reason><success/></reason>",
JingleReason.Success.toXML().toString());
JingleReasonElement.Success.toXML().toString());
assertEquals("<reason><busy/></reason>",
JingleReason.Busy.toXML().toString());
JingleReasonElement.Busy.toXML().toString());
assertEquals("<reason><cancel/></reason>",
JingleReason.Cancel.toXML().toString());
JingleReasonElement.Cancel.toXML().toString());
assertEquals("<reason><connectivity-error/></reason>",
JingleReason.ConnectivityError.toXML().toString());
JingleReasonElement.ConnectivityError.toXML().toString());
assertEquals("<reason><decline/></reason>",
JingleReason.Decline.toXML().toString());
JingleReasonElement.Decline.toXML().toString());
assertEquals("<reason><expired/></reason>",
JingleReason.Expired.toXML().toString());
JingleReasonElement.Expired.toXML().toString());
assertEquals("<reason><unsupported-transports/></reason>",
JingleReason.UnsupportedTransports.toXML().toString());
JingleReasonElement.UnsupportedTransports.toXML().toString());
assertEquals("<reason><failed-transport/></reason>",
JingleReason.FailedTransport.toXML().toString());
JingleReasonElement.FailedTransport.toXML().toString());
assertEquals("<reason><general-error/></reason>",
JingleReason.GeneralError.toXML().toString());
JingleReasonElement.GeneralError.toXML().toString());
assertEquals("<reason><gone/></reason>",
JingleReason.Gone.toXML().toString());
JingleReasonElement.Gone.toXML().toString());
assertEquals("<reason><media-error/></reason>",
JingleReason.MediaError.toXML().toString());
JingleReasonElement.MediaError.toXML().toString());
assertEquals("<reason><security-error/></reason>",
JingleReason.SecurityError.toXML().toString());
JingleReasonElement.SecurityError.toXML().toString());
assertEquals("<reason><unsupported-applications/></reason>",
JingleReason.UnsupportedApplications.toXML().toString());
JingleReasonElement.UnsupportedApplications.toXML().toString());
assertEquals("<reason><timeout/></reason>",
JingleReason.Timeout.toXML().toString());
JingleReasonElement.Timeout.toXML().toString());
assertEquals("<reason><failed-application/></reason>",
JingleReason.FailedApplication.toXML().toString());
JingleReasonElement.FailedApplication.toXML().toString());
assertEquals("<reason><incompatible-parameters/></reason>",
JingleReason.IncompatibleParameters.toXML().toString());
JingleReasonElement.IncompatibleParameters.toXML().toString());
assertEquals("<reason><alternative-session><sid>1234</sid></alternative-session></reason>",
JingleReason.AlternativeSession("1234").toXML().toString());
JingleReasonElement.AlternativeSession("1234").toXML().toString());
}
@Test(expected = NullPointerException.class)
public void alternativeSessionEmptyStringTest() {
// Alternative sessionID must not be empty
JingleReason.AlternativeSession("");
JingleReasonElement.AlternativeSession("");
}
@Test(expected = NullPointerException.class)
public void alternativeSessionNullStringTest() {
// Alternative sessionID must not be null
JingleReason.AlternativeSession(null);
JingleReasonElement.AlternativeSession(null);
}
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentTest() {
JingleReason.Reason.fromString("illegal-reason");
JingleReasonElement.Reason.fromString("illegal-reason");
}
}

View file

@ -1,81 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test the Jingle class.
*/
public class JingleTest extends SmackTestSuite {
@Test(expected = IllegalArgumentException.class)
public void emptyBuilderTest() {
Jingle.Builder builder = Jingle.getBuilder();
builder.build();
}
@Test(expected = NullPointerException.class)
public void onlySessionIdBuilderTest() {
String sessionId = "testSessionId";
Jingle.Builder builder = Jingle.getBuilder();
builder.setSessionId(sessionId);
builder.build();
}
@Test
public void parserTest() throws XmppStringprepException {
String sessionId = "testSessionId";
Jingle.Builder builder = Jingle.getBuilder();
builder.setSessionId(sessionId);
builder.setAction(JingleAction.session_initiate);
FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/orchard");
FullJid juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
builder.setInitiator(romeo);
builder.setResponder(juliet);
Jingle jingle = builder.build();
assertNotNull(jingle);
assertEquals(romeo, jingle.getInitiator());
assertEquals(juliet, jingle.getResponder());
assertEquals(jingle.getAction(), JingleAction.session_initiate);
assertEquals(sessionId, jingle.getSid());
String xml = "<jingle xmlns='urn:xmpp:jingle:1' " +
"initiator='romeo@montague.lit/orchard' " +
"responder='juliet@capulet.lit/balcony' " +
"action='session-initiate' " +
"sid='" + sessionId + "'>" +
"</jingle>";
assertTrue(jingle.toXML().toString().contains(xml));
}
}

View file

@ -1,102 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test the JingleUtil class.
*/
public class JingleUtilTest extends SmackTestSuite {
private XMPPConnection connection;
private JingleUtil jutil;
@Before
public void setup() {
connection = new DummyConnection(
DummyConnection.getDummyConfigurationBuilder()
.setUsernameAndPassword("romeo@montague.lit",
"iluvJulibabe13").build());
jutil = new JingleUtil(connection);
}
@Test
public void sessionInitiateTest() throws XmppStringprepException {
FullJid romeo = connection.getUser().asFullJidOrThrow();
FullJid juliet = JidCreate.fullFrom("juliet@capulet.example/yn0cl4bnw0yr3vym");
String sid = "851ba2";
String contentName = "a-file-offer";
Jingle jingle = jutil.createSessionInitiate(juliet, sid,
JingleContent.Creator.initiator, contentName, JingleContent.Senders.initiator, null, null);
String expected =
"<iq from='" + romeo.toString() + "' " +
"id='nzu25s8' " +
"to='juliet@capulet.example/yn0cl4bnw0yr3vym' " +
"type='set'>" +
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-initiate' " +
"initiator='romeo@montague.example/dr4hcr0st3lup4c' " +
"sid='851ba2'>" +
"<content creator='initiator' name='a-file-offer' senders='initiator'>" +
"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>" +
"<file>" +
"<date>1969-07-21T02:56:15Z</date>" +
"<desc>This is a test. If this were a real file...</desc>" +
"<media-type>text/plain</media-type>" +
"<name>test.txt</name>" +
"<range/>" +
"<size>6144</size>" +
"<hash xmlns='urn:xmpp:hashes:2' " +
"algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>" +
"</file>" +
"</description>" +
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' " +
"mode='tcp' " +
"sid='vj3hs98y'> " +
"<candidate cid='hft54dqy' " +
"host='192.168.4.1' " +
"jid='romeo@montague.example/dr4hcr0st3lup4c' " +
"port='5086' " +
"priority='8257636' " +
"type='direct'/>" +
"<candidate cid='hutr46fe' " +
"host='24.24.24.1' " +
"jid='romeo@montague.example/dr4hcr0st3lup4c' " +
"port='5087' " +
"priority='8258636' " +
"type='direct'/>" +
"</transport>" +
"</content>" +
"</jingle>" +
"</iq>";
}
}

View file

@ -0,0 +1,43 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.component;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.junit.Test;
public class JingleContentTest extends SmackTestSuite {
@Test
public void jingleContentTest() {
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.responder);
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
assertEquals(JingleContentElement.Senders.responder, content.getSenders());
assertNull(content.getDescription());
assertNull(content.getTransport());
assertNull(content.getSecurity());
assertNotNull(content.getName()); //MUST NOT BE NULL!
assertEquals(0, content.getTransportBlacklist().size());
}
}

View file

@ -0,0 +1,251 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.component;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
import org.jivesoftware.smackx.jingle.util.Role;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
public class JingleSessionTest extends SmackTestSuite {
@Test
public void jingleSessionTest() throws XmppStringprepException {
DummyConnection dummyConnection = new DummyConnection();
FullJid alice = JidCreate.fullFrom("alice@wonderland.lit/test123");
FullJid madHatter = JidCreate.fullFrom("mad@hat.net/cat");
JingleManager jingleManager = JingleManager.getInstanceFor(dummyConnection);
JingleSession session = new JingleSession(jingleManager, alice, madHatter, Role.initiator, "WeReAlLmAdHeRe");
assertEquals(alice, session.getInitiator());
assertEquals(madHatter, session.getResponder());
assertEquals(alice, session.getOurJid());
assertEquals(madHatter, session.getPeer());
assertEquals(0, session.getContents().size());
assertEquals("WeReAlLmAdHeRe", session.getSessionId());
assertEquals(jingleManager, session.getJingleManager());
}
@Test(expected = IllegalStateException.class)
public void getSoleContentThrowingTest() {
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()), null, null, Role.initiator, null);
assertTrue(session.isInitiator());
assertFalse(session.isResponder());
JingleContent c1 = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
JingleContent c2 = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
session.addContent(c1);
assertEquals(c1, session.getContent(c1.getName()));
session.addContent(c2);
assertEquals(c2, session.getContent(c2.getName()));
session.getSoleContentOrThrow();
}
@Test
public void getSoleContentTest() {
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()), null, null, Role.responder, null);
assertTrue(session.isResponder());
assertFalse(session.isInitiator());
assertNull(session.getSoleContentOrThrow());
JingleContent c1 = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
assertNull(c1.getParent());
session.addContent(c1);
assertEquals(session, c1.getParent());
assertEquals(c1, session.getSoleContentOrThrow());
}
@Test
public void createSessionAcceptTest() throws XmppStringprepException {
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
JingleSession session = new JingleSession(manager, initiator, responder, Role.initiator, "sessionId");
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
JingleIBBTransport transport = new JingleIBBTransport("streamId", (short) 1024);
content.setTransport(transport);
JingleDescription<?> description = new JingleDescription<JingleContentDescriptionElement>() {
public static final String NAMESPACE = "urn:xmpp:jingle:apps:stub:0";
@Override
public JingleContentDescriptionElement getElement() {
return new JingleContentDescriptionElement(null) {
@Override
public String getNamespace() {
return NAMESPACE;
}
};
}
@Override
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null;
}
@Override
public void onBytestreamReady(BytestreamSession bytestreamSession) {
}
@Override
public String getNamespace() {
return NAMESPACE;
}
};
content.setDescription(description);
session.addContent(content);
JingleElement sessionElement = session.createSessionInitiate();
assertNotNull(sessionElement);
assertEquals("sessionId", sessionElement.getSid());
assertEquals(initiator, sessionElement.getInitiator());
assertNull(sessionElement.getResponder());
assertEquals(JingleAction.session_initiate, sessionElement.getAction());
JingleContentElement contentElement = sessionElement.getSoleContentOrThrow();
assertNotNull(contentElement);
assertEquals(content.getName(), contentElement.getName());
assertEquals(content.getCreator(), contentElement.getCreator());
assertEquals(content.getSenders(), contentElement.getSenders());
assertEquals(0, content.getTransportBlacklist().size());
assertEquals(content.getElement().toXML().toString(), contentElement.toXML().toString());
JingleIBBTransportElement transportElement = (JingleIBBTransportElement) contentElement.getTransport();
assertNotNull(transportElement);
assertEquals(transport.getBlockSize(), transportElement.getBlockSize());
assertEquals(transport.getStreamId(), transportElement.getStreamId());
assertEquals(transport.getNamespace(), transportElement.getNamespace());
assertEquals(transport.getElement().toXML().toString(), transportElement.toXML().toString());
JingleContentDescriptionElement descriptionElement = contentElement.getDescription();
assertNotNull(descriptionElement);
assertEquals(description.getNamespace(), descriptionElement.getNamespace());
assertEquals(description.getElement().toXML().toString(), descriptionElement.toXML().toString());
assertNull(contentElement.getSecurity());
assertTrue(content.isSending());
assertFalse(content.isReceiving());
}
@Test(expected = IllegalArgumentException.class)
public void duplicateContentAddTest() throws XmppStringprepException {
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
JingleSession session = new JingleSession(manager, initiator, responder, Role.initiator, "sessionId");
JingleContent content1 = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
JingleContent content2 = new JingleContent(null, null, null, content1.getName(), null, JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
session.addContent(content1);
session.addContent(content2);
}
@Test(expected = IllegalStateException.class)
public void sessionInitiateThrowsAsResponderTest() {
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()),
null, null, Role.responder, "session");
session.createSessionInitiate();
}
@Test
public void sessionAcceptTest() throws XmppStringprepException {
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
JingleSession session = new JingleSession(manager, initiator, responder, Role.responder, "sessionId");
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
JingleIBBTransport transport = new JingleIBBTransport("streamId", (short) 1024);
content.setTransport(transport);
JingleDescription<?> description = new JingleDescription<JingleContentDescriptionElement>() {
public static final String NAMESPACE = "urn:xmpp:jingle:apps:stub:0";
@Override
public JingleContentDescriptionElement getElement() {
return new JingleContentDescriptionElement(null) {
@Override
public String getNamespace() {
return NAMESPACE;
}
};
}
@Override
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
return null;
}
@Override
public void onBytestreamReady(BytestreamSession bytestreamSession) {
}
@Override
public String getNamespace() {
return NAMESPACE;
}
};
content.setDescription(description);
session.addContent(content);
JingleElement accept = session.createSessionAccept();
assertNotNull(accept);
assertEquals(JingleAction.session_accept, accept.getAction());
assertNull(accept.getInitiator());
assertEquals(session.getResponder(), accept.getResponder());
assertEquals(1, accept.getContents().size());
assertEquals(content.getName(), accept.getSoleContentOrThrow().getName());
assertFalse(content.isSending());
assertTrue(content.isReceiving());
}
@Test(expected = IllegalStateException.class)
public void sessionAcceptThrowsAsInitiatorTest() {
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()),
null, null, Role.initiator, "session");
session.createSessionAccept();
}
}

View file

@ -20,10 +20,11 @@ import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNull;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.provider.JingleIBBTransportProvider;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransport;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.provider.JingleS5BTransportProvider;
import org.junit.Test;
@ -34,16 +35,19 @@ public class JingleContentProviderManagerTest extends SmackTestSuite {
@Test
public void transportProviderTest() {
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
JingleManager.removeJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1);
JingleManager.removeJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1);
assertNull(JingleManager.getJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1));
assertNull(JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1));
JingleIBBTransportProvider ibbProvider = new JingleIBBTransportProvider();
JingleContentProviderManager.addJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1, ibbProvider);
assertEquals(ibbProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
JingleManager.addJingleTransportProvider(ibbProvider);
assertEquals(ibbProvider, JingleManager.getJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1));
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
assertNull(JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1));
JingleS5BTransportProvider s5bProvider = new JingleS5BTransportProvider();
JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1, s5bProvider);
assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
JingleManager.addJingleTransportProvider(s5bProvider);
assertEquals(s5bProvider, JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1));
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Florian Schmaus
* Copyright 2017 Florian Schmaus, Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,10 +21,9 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
@ -51,9 +50,9 @@ public class JingleProviderTest {
"</description>";
// @formatter:on
XmlPullParser parser = createTestJingle(unknownJingleContentDescription);
Jingle jingle = (Jingle) PacketParserUtils.parseIQ(parser);
JingleElement jingle = (JingleElement) PacketParserUtils.parseIQ(parser);
JingleContentDescription jingleContentDescription = jingle.getSoleContentOrThrow().getDescription();
JingleContentDescriptionElement jingleContentDescription = jingle.getSoleContentOrThrow().getDescription();
String parsedUnknownJingleContentDescrptionNamespace = jingleContentDescription.getNamespace();
assertEquals(unknownJingleContentDescriptionNamespace, parsedUnknownJingleContentDescrptionNamespace);
@ -82,9 +81,9 @@ public class JingleProviderTest {
"</transport>";
// @formatter:on
XmlPullParser parser = createTestJingle(unknownJingleContentTransport);
Jingle jingle = (Jingle) PacketParserUtils.parseIQ(parser);
JingleElement jingle = (JingleElement) PacketParserUtils.parseIQ(parser);
JingleContentTransport jingleContentTransport = jingle.getSoleContentOrThrow().getTransport();
JingleContentTransportElement jingleContentTransport = jingle.getSoleContentOrThrow().getTransport();
String parsedUnknownJingleContentTransportNamespace = jingleContentTransport.getNamespace();
assertEquals(unknownJingleContentTransportNamespace, parsedUnknownJingleContentTransportNamespace);

View file

@ -0,0 +1,40 @@
/**
*
* Copyright © 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transport;
import static junit.framework.TestCase.assertEquals;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransportManager;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransportManager;
import org.junit.Test;
public class JingleTransportComparatorTest extends SmackTestSuite {
@Test
public void comparisonTest() {
DummyConnection dummyConnection = new DummyConnection();
JingleIBBTransportManager loser = JingleIBBTransportManager.getInstanceFor(dummyConnection);
JingleS5BTransportManager winner = JingleS5BTransportManager.getInstanceFor(dummyConnection);
assertEquals(-1, loser.compareTo(winner));
assertEquals(1, winner.compareTo(loser));
assertEquals(-1, loser.getPriority()); // IBB should always be last resort.
}
}

View file

@ -0,0 +1,90 @@
/**
*
* Copyright © 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transport.jingle_ibb;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;
import org.junit.Test;
/**
* Test JingleIBBTransport provider and element.
*/
public class JingleIBBTransportTest extends SmackTestSuite {
@Test
public void parserTest() throws Exception {
String sid = StringUtils.randomString(24);
short size = 8192;
String xml = "<transport xmlns='urn:xmpp:jingle:transports:ibb:1' block-size='8192' sid='" + sid + "'/>";
JingleIBBTransport transport = new JingleIBBTransport(sid, size);
assertEquals(xml, transport.getElement().toXML().toString());
assertEquals(size, (short) transport.getBlockSize());
assertEquals(sid, transport.getStreamId());
JingleIBBTransportElement parsed = new JingleIBBTransportProvider()
.parse(TestUtils.getParser(xml));
assertEquals(transport.getElement(), parsed);
assertTrue(transport.getElement().equals(parsed));
assertEquals(xml, parsed.toXML().toString());
JingleIBBTransport transport1 = new JingleIBBTransport();
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport1.getBlockSize());
assertFalse(transport.equals(null));
JingleIBBTransport transport2 = new JingleIBBTransport(transport1.getStreamId(), (short) 256);
assertEquals((Short) (short) 256, transport2.getBlockSize());
assertFalse(transport1.equals(transport2));
transport1.handleSessionAccept(transport2.getElement(), null);
assertEquals(transport2.getBlockSize(), transport1.getBlockSize());
JingleIBBTransport transport3 = new JingleIBBTransportAdapter().transportFromElement(transport2.getElement());
assertEquals(transport2.getBlockSize(), transport3.getBlockSize());
assertEquals(transport2.getStreamId(), transport3.getStreamId());
}
@Test
public void jingleIBBTransportManagerTest() {
JingleIBBTransportManager manager = JingleIBBTransportManager.getInstanceFor(new DummyConnection());
JingleIBBTransport transport1 = (JingleIBBTransport) manager.createTransportForInitiator(null);
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport1.getBlockSize());
JingleIBBTransport transport2 = new JingleIBBTransport("sid", (short) 256);
JingleIBBTransport transport3 = (JingleIBBTransport) manager.createTransportForResponder(null, transport2);
assertEquals((Short) (short) 256, transport3.getBlockSize());
JingleIBBTransport transport4 = new JingleIBBTransport("sod", Short.MAX_VALUE);
assertEquals((Short) Short.MAX_VALUE, transport4.getBlockSize());
JingleIBBTransport transport5 = (JingleIBBTransport) manager.createTransportForResponder(null, transport4);
assertEquals(JingleIBBTransport.MAX_BLOCKSIZE, transport5.getBlockSize());
}
}

View file

@ -0,0 +1,311 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transport.jingle_s5b;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.jingle.component.JingleContent;
import org.jivesoftware.smackx.jingle.component.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportInfoElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.provider.JingleS5BTransportProvider;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test Provider and serialization.
*/
public class JingleS5BTransportTest extends SmackTestSuite {
@Test
public void candidatesProviderTest() throws Exception {
String xml =
"<transport " +
"xmlns='urn:xmpp:jingle:transports:s5b:1' " +
"dstaddr='972b7bf47291ca609517f67f86b5081086052dad' " +
"mode='tcp' " +
"sid='vj3hs98y'>" +
"<candidate " +
"cid='hft54dqy' " +
"host='192.168.4.1' " +
"jid='romeo@montague.lit/orchard' " +
"port='5086' " +
"priority='8257636' " +
"type='direct'/>" +
"<candidate " +
"cid='hutr46fe' " +
"host='24.24.24.1' " +
"jid='romeo@montague.lit/orchard' " +
"port='5087' " +
"priority='8258636' " +
"type='direct'/>" +
"<candidate " +
"cid='xmdh4b7i' " +
"host='123.456.7.8' " +
"jid='streamer.shakespeare.lit' " +
"port='7625' " +
"priority='7878787' " +
"type='proxy'/>" +
"</transport>";
JingleS5BTransportElement transportElement = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transportElement.getDestinationAddress());
assertEquals("vj3hs98y", transportElement.getStreamId());
assertEquals(Bytestream.Mode.tcp, transportElement.getMode());
assertEquals(3, transportElement.getCandidates().size());
assertTrue(transportElement.hasCandidate("hft54dqy"));
assertFalse(transportElement.hasCandidate("invalidId"));
JingleS5BTransportCandidateElement candidate1 =
(JingleS5BTransportCandidateElement) transportElement.getCandidates().get(0);
assertEquals(candidate1, transportElement.getCandidate("hft54dqy"));
assertNotNull(candidate1.getStreamHost());
assertEquals(JingleS5BTransportCandidateElement.Type.direct.getWeight(), candidate1.getType().getWeight());
assertEquals("hft54dqy", candidate1.getCandidateId());
assertEquals("192.168.4.1", candidate1.getHost());
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
assertEquals(5086, candidate1.getPort());
assertEquals(8257636, candidate1.getPriority());
assertEquals(JingleS5BTransportCandidateElement.Type.direct, candidate1.getType());
JingleS5BTransportCandidateElement candidate2 =
(JingleS5BTransportCandidateElement) transportElement.getCandidates().get(1);
assertEquals("hutr46fe", candidate2.getCandidateId());
assertEquals("24.24.24.1", candidate2.getHost());
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
assertEquals(5087, candidate2.getPort());
assertEquals(8258636, candidate2.getPriority());
assertEquals(JingleS5BTransportCandidateElement.Type.direct, candidate2.getType());
JingleS5BTransportCandidateElement candidate3 =
(JingleS5BTransportCandidateElement) transportElement.getCandidates().get(2);
assertEquals("xmdh4b7i", candidate3.getCandidateId());
assertEquals("123.456.7.8", candidate3.getHost());
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
assertEquals(7625, candidate3.getPort());
assertEquals(7878787, candidate3.getPriority());
assertEquals(JingleS5BTransportCandidateElement.Type.proxy, candidate3.getType());
assertEquals(xml, transportElement.toXML().toString());
JingleS5BTransport transport = new JingleS5BTransportAdapter().transportFromElement(transportElement);
assertNotNull(transport);
assertEquals(transportElement.getStreamId(), transport.getStreamId());
assertEquals(transportElement.getMode(), transport.getMode());
assertEquals(transportElement.getDestinationAddress(), transport.getTheirDstAddr());
assertNull(transport.getOurDstAddr());
assertNotNull(transport.getOurCandidates());
assertEquals(0, transport.getOurCandidates().size());
assertNotNull(transport.getTheirCandidates());
assertEquals(3, transport.getTheirCandidates().size());
for (int i = 0; i < transport.getTheirCandidates().size() - 1; i++) {
assertTrue(transport.getTheirCandidates().get(i).getPriority() >= transport.getTheirCandidates().get(i + 1).getPriority());
}
JingleTransportCandidate<?> c = transport.getTheirCandidates().get(1);
transport.addTheirCandidate(c);
assertEquals(3, transport.getTheirCandidates().size());
assertTrue(c.getParent() == transport);
assertNull(transport.getParent());
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
assertNull(content.getTransport());
content.setTransport(transport);
assertEquals(transport, content.getTransport());
assertEquals(content, transport.getParent());
}
@Test
public void infoProviderTest() throws Exception {
String candidateError =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<candidate-error/>" +
"</transport>";
JingleS5BTransportElement candidateErrorTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateError));
assertNull(candidateErrorTransport.getDestinationAddress());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
assertEquals(JingleS5BTransportInfoElement.CandidateError.INSTANCE,
candidateErrorTransport.getInfo());
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
String proxyError =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<proxy-error/>" +
"</transport>";
JingleS5BTransportElement proxyErrorTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(proxyError));
assertNull(proxyErrorTransport.getDestinationAddress());
assertNotNull(proxyErrorTransport.getInfo());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
assertEquals(JingleS5BTransportInfoElement.ProxyError.INSTANCE,
proxyErrorTransport.getInfo());
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
String candidateUsed =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<candidate-used cid='hr65dqyd'/>" +
"</transport>";
JingleS5BTransportElement candidateUsedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateUsed));
assertNotNull(candidateUsedTransport.getInfo());
assertEquals(new JingleS5BTransportInfoElement.CandidateUsed("hr65dqyd"),
candidateUsedTransport.getInfo());
assertEquals("hr65dqyd",
((JingleS5BTransportInfoElement.CandidateUsed)
candidateUsedTransport.getInfo()).getCandidateId());
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
String candidateActivated =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<activated cid='hr65dqyd'/>" +
"</transport>";
JingleS5BTransportElement candidateActivatedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateActivated));
assertNotNull(candidateActivatedTransport.getInfo());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals(new JingleS5BTransportInfoElement.CandidateActivated("hr65dqyd"),
candidateActivatedTransport.getInfo());
assertEquals("hr65dqyd",
((JingleS5BTransportInfoElement.CandidateActivated)
candidateActivatedTransport.getInfo()).getCandidateId());
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
}
@Test(expected = IllegalArgumentException.class)
public void candidateBuilderInvalidPortTest() {
JingleS5BTransportCandidateElement.getBuilder().setPort(-5);
}
@Test(expected = IllegalArgumentException.class)
public void candidateBuilderInvalidPriorityTest() {
JingleS5BTransportCandidateElement.getBuilder().setPriority(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void transportCandidateIllegalPriorityTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(
"cid", "host", jid, 5555, -30, JingleS5BTransportCandidateElement.Type.proxy);
}
@Test(expected = IllegalArgumentException.class)
public void transportCandidateIllegalPortTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(
"cid", "host", jid, -5555, 30, JingleS5BTransportCandidateElement.Type.proxy);
}
@Test
public void candidateFromStreamHostTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
String host = "host.address";
int port = 1234;
Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port);
JingleS5BTransportCandidateElement candidate = new JingleS5BTransportCandidateElement(streamHost, 2000, JingleS5BTransportCandidateElement.Type.direct);
assertEquals(2000, candidate.getPriority());
assertEquals(jid, candidate.getJid());
assertEquals(host, candidate.getHost());
assertEquals(port, candidate.getPort());
assertEquals(streamHost.toXML().toString(), candidate.getStreamHost().toXML().toString());
}
@Test
public void constructorsTest() throws XmppStringprepException {
FullJid initiator = JidCreate.fullFrom("in@it.ia/tor");
FullJid responder = JidCreate.fullFrom("re@sp.on/der");
List<JingleTransportCandidate<?>> c1 = new ArrayList<>();
JingleS5BTransportCandidate c11 = new JingleS5BTransportCandidate("1234", new Bytestream.StreamHost(JidCreate.from("p.b.c"), "p.b.c", 9999), 100, JingleS5BTransportCandidateElement.Type.proxy);
c1.add(c11);
List<JingleTransportCandidate<?>> c2 = new ArrayList<>();
JingleS5BTransportCandidate c21 = new JingleS5BTransportCandidate("1337", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 1000), 101, JingleS5BTransportCandidateElement.Type.proxy);
JingleS5BTransportCandidate c22 = new JingleS5BTransportCandidate("1009", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 2000), 10, JingleS5BTransportCandidateElement.Type.proxy);
c2.add(c21);
c2.add(c22);
JingleS5BTransport t1 = new JingleS5BTransport(initiator, responder, "tSes", Bytestream.Mode.tcp, c1);
assertEquals("tSes", t1.getStreamId());
assertEquals(Bytestream.Mode.tcp, t1.getMode());
assertEquals(Socks5Utils.createDigest("tSes", initiator, responder), t1.getOurDstAddr());
assertNull(t1.getTheirDstAddr());
assertEquals(1, t1.getOurCandidates().size());
assertEquals(c11, t1.getOurCandidates().get(0));
assertEquals(0, t1.getTheirCandidates().size());
JingleS5BTransport t1parsed = new JingleS5BTransportAdapter().transportFromElement(t1.getElement());
assertEquals(t1.getOurDstAddr(), t1parsed.getTheirDstAddr());
assertNull(t1parsed.getOurDstAddr());
assertEquals(0, t1parsed.getOurCandidates().size());
assertEquals(t1.getStreamId(), t1parsed.getStreamId());
assertEquals(t1.getMode(), t1parsed.getMode());
assertEquals(t1.getOurCandidates().size(), t1parsed.getTheirCandidates().size());
JingleS5BTransport t2 = new JingleS5BTransport(initiator, responder, c2, t1parsed);
assertEquals("tSes", t2.getStreamId());
assertEquals(Bytestream.Mode.tcp, t2.getMode());
assertEquals(Socks5Utils.createDigest("tSes", responder, initiator), t2.getOurDstAddr());
assertEquals(t1.getOurDstAddr(), t2.getTheirDstAddr());
assertEquals(2, t2.getOurCandidates().size());
assertEquals(c2, t2.getOurCandidates());
assertEquals(t1.getOurCandidates().size(), t2.getTheirCandidates().size());
}
@Test(expected = IllegalArgumentException.class)
public void typeFromIllegalStringTest() {
JingleS5BTransportCandidateElement.Type.fromString("illegal-type");
}
}

View file

@ -1,76 +0,0 @@
/**
*
* Copyright © 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transports.jingle_ibb;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.provider.JingleIBBTransportProvider;
import org.junit.Test;
/**
* Test JingleIBBTransport provider and element.
*/
public class JingleIBBTransportTest extends SmackTestSuite {
@Test
public void parserTest() throws Exception {
String sid = StringUtils.randomString(24);
short size = 8192;
String xml = "<transport xmlns='urn:xmpp:jingle:transports:ibb:1' block-size='8192' sid='" + sid + "'/>";
JingleIBBTransport transport = new JingleIBBTransport(size, sid);
assertEquals(xml, transport.toXML().toString());
assertEquals(size, transport.getBlockSize());
assertEquals(sid, transport.getSessionId());
JingleIBBTransport parsed = new JingleIBBTransportProvider()
.parse(TestUtils.getParser(xml));
assertEquals(transport, parsed);
assertTrue(transport.equals(parsed));
assertEquals(xml, parsed.toXML().toString());
JingleIBBTransport transport1 = new JingleIBBTransport((short) 1024);
assertEquals((short) 1024, transport1.getBlockSize());
assertNotSame(transport, transport1);
assertNotSame(transport.getSessionId(), transport1.getSessionId());
assertFalse(transport.equals(null));
JingleIBBTransport transport2 = new JingleIBBTransport();
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport2.getBlockSize());
assertFalse(transport1.equals(transport2));
JingleIBBTransport transport3 = new JingleIBBTransport((short) -1024);
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport3.getBlockSize());
assertEquals(transport3.getNamespace(), JingleIBBTransport.NAMESPACE_V1);
assertEquals(transport3.getElementName(), "transport");
JingleIBBTransport transport4 = new JingleIBBTransport("session-id");
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport4.getBlockSize());
}
}

View file

@ -1,226 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transports.jingle_s5b;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportInfo;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test Provider and serialization.
*/
public class JingleS5BTransportTest extends SmackTestSuite {
@Test
public void candidatesProviderTest() throws Exception {
String xml =
"<transport " +
"xmlns='urn:xmpp:jingle:transports:s5b:1' " +
"dstaddr='972b7bf47291ca609517f67f86b5081086052dad' " +
"mode='tcp' " +
"sid='vj3hs98y'>" +
"<candidate " +
"cid='hft54dqy' " +
"host='192.168.4.1' " +
"jid='romeo@montague.lit/orchard' " +
"port='5086' " +
"priority='8257636' " +
"type='direct'/>" +
"<candidate " +
"cid='hutr46fe' " +
"host='24.24.24.1' " +
"jid='romeo@montague.lit/orchard' " +
"port='5087' " +
"priority='8258636' " +
"type='direct'/>" +
"<candidate " +
"cid='xmdh4b7i' " +
"host='123.456.7.8' " +
"jid='streamer.shakespeare.lit' " +
"port='7625' " +
"priority='7878787' " +
"type='proxy'/>" +
"</transport>";
JingleS5BTransport transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
assertEquals("vj3hs98y", transport.getStreamId());
assertEquals(Bytestream.Mode.tcp, transport.getMode());
assertEquals(3, transport.getCandidates().size());
assertTrue(transport.hasCandidate("hft54dqy"));
assertFalse(transport.hasCandidate("invalidId"));
JingleS5BTransportCandidate candidate1 =
(JingleS5BTransportCandidate) transport.getCandidates().get(0);
assertEquals(candidate1, transport.getCandidate("hft54dqy"));
assertNotNull(candidate1.getStreamHost());
assertEquals(JingleS5BTransportCandidate.Type.direct.getWeight(), candidate1.getType().getWeight());
assertEquals("hft54dqy", candidate1.getCandidateId());
assertEquals("192.168.4.1", candidate1.getHost());
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
assertEquals(5086, candidate1.getPort());
assertEquals(8257636, candidate1.getPriority());
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate1.getType());
JingleS5BTransportCandidate candidate2 =
(JingleS5BTransportCandidate) transport.getCandidates().get(1);
assertEquals("hutr46fe", candidate2.getCandidateId());
assertEquals("24.24.24.1", candidate2.getHost());
assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
assertEquals(5087, candidate2.getPort());
assertEquals(8258636, candidate2.getPriority());
assertEquals(JingleS5BTransportCandidate.Type.direct, candidate2.getType());
JingleS5BTransportCandidate candidate3 =
(JingleS5BTransportCandidate) transport.getCandidates().get(2);
assertEquals("xmdh4b7i", candidate3.getCandidateId());
assertEquals("123.456.7.8", candidate3.getHost());
assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
assertEquals(7625, candidate3.getPort());
assertEquals(7878787, candidate3.getPriority());
assertEquals(JingleS5BTransportCandidate.Type.proxy, candidate3.getType());
assertEquals(xml, transport.toXML().toString());
}
@Test
public void infoProviderTest() throws Exception {
String candidateError =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<candidate-error/>" +
"</transport>";
JingleS5BTransport candidateErrorTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateError));
assertNull(candidateErrorTransport.getDestinationAddress());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
assertEquals(JingleS5BTransportInfo.CandidateError.INSTANCE,
candidateErrorTransport.getInfo());
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
String proxyError =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<proxy-error/>" +
"</transport>";
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(proxyError));
assertNull(proxyErrorTransport.getDestinationAddress());
assertNotNull(proxyErrorTransport.getInfo());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
assertEquals(JingleS5BTransportInfo.ProxyError.INSTANCE,
proxyErrorTransport.getInfo());
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
String candidateUsed =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<candidate-used cid='hr65dqyd'/>" +
"</transport>";
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateUsed));
assertNotNull(candidateUsedTransport.getInfo());
assertEquals(new JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
candidateUsedTransport.getInfo());
assertEquals("hr65dqyd",
((JingleS5BTransportInfo.CandidateUsed)
candidateUsedTransport.getInfo()).getCandidateId());
assertEquals(candidateUsed, candidateUsedTransport.toXML().toString());
String candidateActivated =
"<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='vj3hs98y'>" +
"<candidate-activated cid='hr65dqyd'/>" +
"</transport>";
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateActivated));
assertNotNull(candidateActivatedTransport.getInfo());
assertNotNull(candidateErrorTransport.getInfo());
assertEquals(new JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
candidateActivatedTransport.getInfo());
assertEquals("hr65dqyd",
((JingleS5BTransportInfo.CandidateActivated)
candidateActivatedTransport.getInfo()).getCandidateId());
assertEquals(candidateActivated, candidateActivatedTransport.toXML().toString());
}
@Test(expected = IllegalArgumentException.class)
public void candidateBuilderInvalidPortTest() {
JingleS5BTransportCandidate.getBuilder().setPort(-5);
}
@Test(expected = IllegalArgumentException.class)
public void candidateBuilderInvalidPriorityTest() {
JingleS5BTransportCandidate.getBuilder().setPriority(-1000);
}
@Test(expected = IllegalArgumentException.class)
public void transportCandidateIllegalPriorityTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
@SuppressWarnings("unused")
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(
"cid", "host", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy);
}
@Test(expected = IllegalArgumentException.class)
public void transportCandidateIllegalPortTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
@SuppressWarnings("unused")
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(
"cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy);
}
@Test
public void candidateFromStreamHostTest() throws XmppStringprepException {
FullJid jid = JidCreate.fullFrom("test@test.test/test");
String host = "host.address";
int port = 1234;
Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port);
JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(streamHost, 2000, JingleS5BTransportCandidate.Type.direct);
assertEquals(2000, candidate.getPriority());
assertEquals(jid, candidate.getJid());
assertEquals(host, candidate.getHost());
assertEquals(port, candidate.getPort());
assertEquals(streamHost.toXML().toString(), candidate.getStreamHost().toXML().toString());
}
@Test(expected = IllegalArgumentException.class)
public void typeFromIllegalStringTest() {
JingleS5BTransportCandidate.Type.fromString("illegal-type");
}
}