mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-15 16:52:07 +01:00
Add Jingle Tests
This commit is contained in:
parent
1c337cb3c5
commit
306a7bc0ff
9 changed files with 342 additions and 8 deletions
|
@ -33,6 +33,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Test the JingleContentDescriptionFileTransfer element and provider.
|
||||
|
@ -71,7 +72,6 @@ public class JingleContentDescriptionFileTransferTest extends SmackTestSuite {
|
|||
|
||||
JingleContentDescriptionFileTransfer descriptionFileTransfer =
|
||||
new JingleContentDescriptionFileTransfer(payloads);
|
||||
|
||||
assertEquals(xml, descriptionFileTransfer.toXML().toString());
|
||||
|
||||
JingleContentDescription parsed = new JingleContentDescriptionFileTransferProvider()
|
||||
|
@ -86,6 +86,9 @@ public class JingleContentDescriptionFileTransferTest extends SmackTestSuite {
|
|||
assertEquals(sizeInt, payload.getSize());
|
||||
assertEquals(range, payload.getRange());
|
||||
assertEquals(hashElement, payload.getHash());
|
||||
|
||||
JingleContentDescriptionFileTransfer descriptionFileTransfer1 = new JingleContentDescriptionFileTransfer(null);
|
||||
assertNotNull(descriptionFileTransfer1.getJinglePayloadTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class JingleError implements ExtensionElement {
|
||||
|
||||
public static String NAMESPACE = "urn:xmpp:jingle:errors:1";
|
||||
|
@ -39,7 +39,7 @@ public final class JingleError implements ExtensionElement {
|
|||
/**
|
||||
* Creates a new error with the specified code and errorName.
|
||||
*
|
||||
* @param message a message describing the error.
|
||||
* @param errorName name describing the error.
|
||||
*/
|
||||
private JingleError(final String errorName) {
|
||||
this.errorName = errorName;
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Jingle 'reason' element.
|
||||
*
|
||||
|
@ -96,7 +96,7 @@ public class JingleReason implements NamedElement {
|
|||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.rightAngleBracket();
|
||||
|
||||
xml.emptyElement(reason);
|
||||
xml.emptyElement(reason.asString);
|
||||
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
* 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.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
/**
|
||||
* Test the JingleAction class.
|
||||
*/
|
||||
public class JingleActionTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void enumTest() {
|
||||
assertEquals("content-accept", JingleAction.content_accept.toString());
|
||||
assertEquals(JingleAction.content_accept, JingleAction.fromString("content-accept"));
|
||||
|
||||
for (JingleAction a : JingleAction.values()) {
|
||||
assertEquals(a, JingleAction.fromString(a.toString()));
|
||||
}
|
||||
|
||||
try {
|
||||
JingleAction inexistentAction = JingleAction.fromString("inexistent-action");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.junit.Test;
|
||||
|
||||
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.fail;
|
||||
|
||||
/**
|
||||
* Test the JingleContent class.
|
||||
*/
|
||||
public class JingleContentTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void parserTest() {
|
||||
|
||||
JingleContent.Builder builder = JingleContent.getBuilder();
|
||||
|
||||
try {
|
||||
builder.build();
|
||||
fail();
|
||||
} catch (NullPointerException e) {
|
||||
// Expected
|
||||
}
|
||||
builder.setCreator(JingleContent.Creator.initiator);
|
||||
|
||||
try {
|
||||
builder.build();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
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());
|
||||
|
||||
assertEquals(0, content.getJingleTransportsCount());
|
||||
assertNotNull(content.getJingleTransports());
|
||||
|
||||
String xml =
|
||||
"<content creator='initiator' disposition='session' name='A name' senders='both'>" +
|
||||
"</content>";
|
||||
assertEquals(xml, content1.toXML().toString());
|
||||
}
|
||||
}
|
|
@ -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 org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleError;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
/**
|
||||
* Test the JingleError class. TODO: Uncomment missing tests once implemented.
|
||||
*/
|
||||
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());
|
||||
|
||||
try {
|
||||
JingleError.fromString("inexistent-error");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
*
|
||||
* 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.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
/**
|
||||
* Test JingleReason functionality.
|
||||
*/
|
||||
public class JingleReasonTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void parserTest() {
|
||||
assertEquals("<reason><success/></reason>",
|
||||
new JingleReason(JingleReason.Reason.success).toXML().toString());
|
||||
assertEquals("<reason><busy/></reason>",
|
||||
new JingleReason(JingleReason.Reason.busy).toXML().toString());
|
||||
assertEquals("<reason><cancel/></reason>",
|
||||
new JingleReason(JingleReason.Reason.cancel).toXML().toString());
|
||||
assertEquals("<reason><connectivity-error/></reason>",
|
||||
new JingleReason(JingleReason.Reason.connectivity_error).toXML().toString());
|
||||
assertEquals("<reason><decline/></reason>",
|
||||
new JingleReason(JingleReason.Reason.decline).toXML().toString());
|
||||
assertEquals("<reason><expired/></reason>",
|
||||
new JingleReason(JingleReason.Reason.expired).toXML().toString());
|
||||
assertEquals("<reason><unsupported-transports/></reason>",
|
||||
new JingleReason(JingleReason.Reason.unsupported_transports).toXML().toString());
|
||||
assertEquals("<reason><failed-transport/></reason>",
|
||||
new JingleReason(JingleReason.Reason.failed_transport).toXML().toString());
|
||||
assertEquals("<reason><general-error/></reason>",
|
||||
new JingleReason(JingleReason.Reason.general_error).toXML().toString());
|
||||
assertEquals("<reason><gone/></reason>",
|
||||
new JingleReason(JingleReason.Reason.gone).toXML().toString());
|
||||
assertEquals("<reason><media-error/></reason>",
|
||||
new JingleReason(JingleReason.Reason.media_error).toXML().toString());
|
||||
assertEquals("<reason><security-error/></reason>",
|
||||
new JingleReason(JingleReason.Reason.security_error).toXML().toString());
|
||||
assertEquals("<reason><unsupported-applications/></reason>",
|
||||
new JingleReason(JingleReason.Reason.unsupported_applications).toXML().toString());
|
||||
assertEquals("<reason><timeout/></reason>",
|
||||
new JingleReason(JingleReason.Reason.timeout).toXML().toString());
|
||||
assertEquals("<reason><failed-application/></reason>",
|
||||
new JingleReason(JingleReason.Reason.failed_application).toXML().toString());
|
||||
assertEquals("<reason><incompatible-parameters/></reason>",
|
||||
new JingleReason(JingleReason.Reason.incompatible_parameters).toXML().toString());
|
||||
assertEquals(JingleReason.Reason.alternative_session, JingleReason.Reason.fromString("alternative-session"));
|
||||
try {
|
||||
JingleReason.Reason nonExistent = JingleReason.Reason.fromString("illegal-reason");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
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;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
/**
|
||||
* Test the Jingle class.
|
||||
*/
|
||||
public class JingleTest extends SmackTestSuite {
|
||||
|
||||
@Test
|
||||
public void parserTest() throws XmppStringprepException {
|
||||
String sessionId = StringUtils.randomString(24);
|
||||
|
||||
Jingle.Builder builder = Jingle.getBuilder();
|
||||
try {
|
||||
builder.build();
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Expected
|
||||
}
|
||||
builder.setSessionId(sessionId);
|
||||
|
||||
try {
|
||||
builder.build();
|
||||
fail();
|
||||
} catch (NullPointerException e) {
|
||||
// Expected
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
|
@ -63,5 +63,8 @@ public class JingleInBandByteStreamTransportTest extends SmackTestSuite {
|
|||
|
||||
JingleInBandByteStreamTransport transport3 = new JingleInBandByteStreamTransport((short) -1024);
|
||||
assertEquals(JingleInBandByteStreamTransport.DEFAULT_BLOCK_SIZE, transport3.getBlockSize());
|
||||
|
||||
assertEquals(transport3.getNamespace(), JingleInBandByteStreamManager.NAMESPACE_V1);
|
||||
assertEquals(transport3.getElementName(), "transport");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue