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/JingleSessionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java new file mode 100644 index 000000000..cd12c08ac --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java @@ -0,0 +1,51 @@ +/** + * + * 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.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotSame; + +/** + * 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()); + } +} 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)); + } +}