Merge moreJingleTests

This commit is contained in:
vanitasvitae 2017-06-30 18:56:56 +02:00
commit 71486ab68e
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
6 changed files with 146 additions and 31 deletions

View File

@ -54,8 +54,12 @@ public final class JingleS5BTransportCandidate extends JingleContentTransportCan
Objects.requireNonNull(candidateId);
Objects.requireNonNull(host);
Objects.requireNonNull(jid);
if (priority < 0) {
throw new IllegalArgumentException("Priority MUST be present and NOT less than 0.");
throw new IllegalArgumentException("Priority MUST NOT be less than 0.");
}
if (port < 0) {
throw new IllegalArgumentException("Port MUST NOT be less than 0.");
}
this.cid = candidateId;

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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");
}
}

View File

@ -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());
}
}

View File

@ -16,17 +16,14 @@
*/
package org.jivesoftware.smackx.jingle.transports.jingle_s5b;
<<<<<<< HEAD
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 junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
>>>>>>> js5btbFixes
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;
@ -35,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.
@ -82,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());
@ -134,11 +138,8 @@ public class JingleS5BTransportTest extends SmackTestSuite {
JingleS5BTransport proxyErrorTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(proxyError));
assertNull(proxyErrorTransport.getDestinationAddress());
<<<<<<< HEAD
assertNotNull(proxyErrorTransport.getInfo());
=======
assertNotNull(candidateErrorTransport.getInfo());
>>>>>>> js5btbFixes
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
assertEquals(JingleS5BTransportInfo.ProxyError(),
proxyErrorTransport.getInfo());
@ -150,11 +151,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
"</transport>";
JingleS5BTransport candidateUsedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateUsed));
<<<<<<< HEAD
assertNotNull(candidateUsedTransport.getInfo());
=======
assertNotNull(candidateErrorTransport.getInfo());
>>>>>>> js5btbFixes
assertEquals(JingleS5BTransportInfo.CandidateUsed("hr65dqyd"),
candidateUsedTransport.getInfo());
assertEquals("hr65dqyd",
@ -168,11 +165,9 @@ public class JingleS5BTransportTest extends SmackTestSuite {
"</transport>";
JingleS5BTransport candidateActivatedTransport = new JingleS5BTransportProvider()
.parse(TestUtils.getParser(candidateActivated));
<<<<<<< HEAD
assertNotNull(candidateActivatedTransport.getInfo());
=======
assertNotNull(candidateErrorTransport.getInfo());
>>>>>>> js5btbFixes
assertEquals(JingleS5BTransportInfo.CandidateActivated("hr65dqyd"),
candidateActivatedTransport.getInfo());
assertEquals("hr65dqyd",
@ -180,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");
}
}