mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
More jingle related tests
This commit is contained in:
parent
541c9ecfdd
commit
322587c0b5
6 changed files with 143 additions and 14 deletions
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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,7 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.transports.jingle_s5b;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
@ -29,7 +31,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 +80,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());
|
||||
|
@ -162,4 +171,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);
|
||||
|
||||
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…
Reference in a new issue