mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
More changes to the Jingle package:
- Change visibility of some Socks5Bytestreams code. - Add central ThreadPool - Move FullJidAndSessionId in own class - More complete JingleSession class - More complete JingleUtil class - Improved tests
This commit is contained in:
parent
5bd01b7385
commit
7e76bc1ae5
33 changed files with 1859 additions and 160 deletions
|
@ -102,10 +102,15 @@ public class Socks5ProxyTest {
|
|||
@Test
|
||||
public void shouldPreserveAddressOrderOnInsertions() {
|
||||
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
|
||||
List<String> addresses = new ArrayList<String>(proxy.getLocalAddresses());
|
||||
addresses.add("1");
|
||||
addresses.add("2");
|
||||
addresses.add("3");
|
||||
List<String> addresses = new ArrayList<>(proxy.getLocalAddresses());
|
||||
|
||||
for (int i = 1 ; i <= 3; i++) {
|
||||
String addr = Integer.toString(i);
|
||||
if (!addresses.contains(addr)) {
|
||||
addresses.add(addr);
|
||||
}
|
||||
}
|
||||
|
||||
for (String address : addresses) {
|
||||
proxy.addLocalAddress(address);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
*
|
||||
* 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.assertNull;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
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.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the JingleContentProviderManager.
|
||||
*/
|
||||
public class JingleContentProviderManagerTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void transportProviderTest() {
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
|
||||
JingleIBBTransportProvider ibbProvider = new JingleIBBTransportProvider();
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1, ibbProvider);
|
||||
assertEquals(ibbProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1));
|
||||
|
||||
assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
JingleS5BTransportProvider s5bProvider = new JingleS5BTransportProvider();
|
||||
JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1, s5bProvider);
|
||||
assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1));
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
@ -46,7 +45,7 @@ public class JingleContentTest extends SmackTestSuite {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void parserTest() {
|
||||
public void parserTest() throws Exception {
|
||||
|
||||
JingleContent.Builder builder = JingleContent.getBuilder();
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ package org.jivesoftware.smackx.jingle;
|
|||
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.provider.JingleErrorProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -30,20 +31,37 @@ import org.junit.Test;
|
|||
public class JingleErrorTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void parserTest() {
|
||||
assertEquals("<out-of-order xmlns='urn:xmpp:jingle:errors:1'/>",
|
||||
JingleError.fromString("out-of-order").toXML().toString());
|
||||
assertEquals("<tie-break xmlns='urn:xmpp:jingle:errors:1'/>",
|
||||
JingleError.fromString("tie-break").toXML().toString());
|
||||
assertEquals("<unknown-session xmlns='urn:xmpp:jingle:errors:1'/>",
|
||||
JingleError.fromString("unknown-session").toXML().toString());
|
||||
assertEquals("<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>",
|
||||
JingleError.fromString("unsupported-info").toXML().toString());
|
||||
assertEquals("unknown-session", JingleError.fromString("unknown-session").getMessage());
|
||||
public void tieBreakTest() throws Exception {
|
||||
String xml = "<tie-break xmlns='urn:xmpp:jingle:errors:1'/>";
|
||||
JingleError 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));
|
||||
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));
|
||||
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));
|
||||
assertEquals(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void illegalArgumentTest() {
|
||||
JingleError.fromString("inexistent-error");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,52 +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.assertNotSame;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
* Test JingleSession class.
|
||||
*/
|
||||
public class JingleSessionTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void sessionTest() throws XmppStringprepException {
|
||||
Jid romeo = JidCreate.from("romeo@montague.lit");
|
||||
Jid juliet = JidCreate.from("juliet@capulet.lit");
|
||||
String sid = StringUtils.randomString(24);
|
||||
|
||||
JingleSession s1 = new JingleSession(romeo, juliet, sid);
|
||||
JingleSession s2 = new JingleSession(juliet, romeo, sid);
|
||||
JingleSession s3 = new JingleSession(romeo, juliet, StringUtils.randomString(23));
|
||||
JingleSession s4 = new JingleSession(juliet, romeo, sid);
|
||||
|
||||
assertNotSame(s1, s2);
|
||||
assertNotSame(s1, s3);
|
||||
assertNotSame(s2, s3);
|
||||
assertEquals(s2, s4);
|
||||
assertEquals(s2.hashCode(), s4.hashCode());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
*
|
||||
* 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>";
|
||||
}
|
||||
}
|
|
@ -69,5 +69,8 @@ public class JingleIBBTransportTest extends SmackTestSuite {
|
|||
|
||||
assertEquals(transport3.getNamespace(), JingleIBBTransport.NAMESPACE_V1);
|
||||
assertEquals(transport3.getElementName(), "transport");
|
||||
|
||||
JingleIBBTransport transport4 = new JingleIBBTransport("session-id");
|
||||
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport4.getBlockSize());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
*/
|
||||
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 org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
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;
|
||||
|
@ -29,7 +32,9 @@ import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTr
|
|||
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.
|
||||
|
@ -76,8 +81,13 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
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());
|
||||
|
@ -128,6 +138,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(proxyError));
|
||||
assertNull(proxyErrorTransport.getDestinationAddress());
|
||||
assertNotNull(proxyErrorTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||
assertEquals(JingleS5BTransportInfo.ProxyError(),
|
||||
|
@ -140,7 +151,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"</transport>";
|
||||
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateUsed));
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertNotNull(candidateUsedTransport.getInfo());
|
||||
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
|
||||
candidateUsedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
|
@ -154,7 +165,9 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"</transport>";
|
||||
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateActivated));
|
||||
assertNotNull(candidateActivatedTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
|
||||
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
|
||||
candidateActivatedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
|
@ -162,4 +175,50 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
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");
|
||||
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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue