From 306a7bc0ff90825005ac224bf59c3c351a415bf2 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Thu, 1 Jun 2017 01:25:39 +0200 Subject: [PATCH] Add Jingle Tests --- ...gleContentDescriptionFileTransferTest.java | 5 +- .../smackx/jingle/element/JingleError.java | 6 +- .../smackx/jingle/element/JingleReason.java | 8 +- .../smackx/jingle/JingleActionTest.java | 47 +++++++++++ .../smackx/jingle/JingleContentTest.java | 79 +++++++++++++++++++ .../smackx/jingle/JingleErrorTest.java | 50 ++++++++++++ .../smackx/jingle/JingleReasonTest.java | 73 +++++++++++++++++ .../smackx/jingle/JingleTest.java | 79 +++++++++++++++++++ .../JingleInBandByteStreamTransportTest.java | 3 + 9 files changed, 342 insertions(+), 8 deletions(-) create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleActionTest.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentTest.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleErrorTest.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleReasonTest.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTest.java diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleContentDescriptionFileTransferTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleContentDescriptionFileTransferTest.java index 523c9e660..746b1bc08 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleContentDescriptionFileTransferTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/jingle_filetransfer/JingleContentDescriptionFileTransferTest.java @@ -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 diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java index 6fa132893..f4000bf3a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleError.java @@ -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; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java index b150832d3..8488b052d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/element/JingleReason.java @@ -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; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleActionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleActionTest.java new file mode 100644 index 000000000..c73358a0b --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleActionTest.java @@ -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 + } + } +} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentTest.java new file mode 100644 index 000000000..728e227e6 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentTest.java @@ -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 = + "" + + ""; + assertEquals(xml, content1.toXML().toString()); + } +} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleErrorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleErrorTest.java new file mode 100644 index 000000000..7344fac6a --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleErrorTest.java @@ -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("", + JingleError.fromString("out-of-order").toXML().toString()); + //assertEquals("", + // JingleError.fromString("tie-break").toXML().toString()); + assertEquals("", + JingleError.fromString("unknown-session").toXML().toString()); + //assertEquals("", + // JingleError.fromString("unsupported-info").toXML().toString()); + assertEquals("unknown-session", JingleError.fromString("unknown-session").getMessage()); + + try { + JingleError.fromString("inexistent-error"); + fail(); + } catch (IllegalArgumentException e) { + // Expected + } + } +} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleReasonTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleReasonTest.java new file mode 100644 index 000000000..ffd93ab6d --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleReasonTest.java @@ -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("", + new JingleReason(JingleReason.Reason.success).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.busy).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.cancel).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.connectivity_error).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.decline).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.expired).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.unsupported_transports).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.failed_transport).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.general_error).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.gone).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.media_error).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.security_error).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.unsupported_applications).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.timeout).toXML().toString()); + assertEquals("", + new JingleReason(JingleReason.Reason.failed_application).toXML().toString()); + assertEquals("", + 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 + } + } +} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTest.java new file mode 100644 index 000000000..21ba31804 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleTest.java @@ -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 = "" + + ""; + assertTrue(jingle.toXML().toString().contains(xml)); + } +} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle_ibb/JingleInBandByteStreamTransportTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle_ibb/JingleInBandByteStreamTransportTest.java index 96db3e26f..dd470bb95 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle_ibb/JingleInBandByteStreamTransportTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle_ibb/JingleInBandByteStreamTransportTest.java @@ -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"); } }