From b91a9c120f2807d3eebf1eeb127c33aa4c45ed40 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sun, 18 Jun 2017 16:47:49 +0200 Subject: [PATCH] More ground work --- .../jingle_filetransfer/JingleFileOffer.java | 30 ++++++ .../JingleFileRequest.java | 31 ++++++ .../JingleFileTransferManager.java | 22 ++++- .../JingleFileTransferSession.java | 61 ++++++++++++ .../JingleFileTransferSessionHandler.java | 56 +++++++++++ .../IncomingFileTransferListener.java | 27 ++++++ .../listener/package-info.java | 22 +++++ .../smackx/jingle/FullJidAndSessionId.java | 49 ++++++++++ .../smackx/jingle/JingleManager.java | 94 +++++++------------ .../smackx/jingle/JingleSession.java | 58 +++++++++--- .../smackx/jingle/JingleUtil.java | 2 - .../smackx/jingle/JingleSessionTest.java | 16 ++-- 12 files changed, 385 insertions(+), 83 deletions(-) create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileOffer.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSessionHandler.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/IncomingFileTransferListener.java create mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/package-info.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileOffer.java new file mode 100644 index 000000000..54d4cf23c --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileOffer.java @@ -0,0 +1,30 @@ +/** + * + * 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_filetransfer; + +import org.jivesoftware.smackx.jingle.Role; + +import org.jxmpp.jid.FullJid; + +/** + * Offer. + */ +public class JingleFileOffer extends JingleFileTransferSession { + public JingleFileOffer(FullJid initiator, FullJid responder, Role role, String sid) { + super(initiator, responder, role, sid, Type.offer); + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java new file mode 100644 index 000000000..57c247a27 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileRequest.java @@ -0,0 +1,31 @@ +/** + * + * 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_filetransfer; + +import org.jivesoftware.smackx.jingle.Role; + +import org.jxmpp.jid.FullJid; + +/** + * Request. + */ +public class JingleFileRequest extends JingleFileTransferSession { + + public JingleFileRequest(FullJid initiator, FullJid responder, Role role, String sid) { + super(initiator, responder, role, sid, Type.request); + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java index 7b96cdbd4..81540edeb 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferManager.java @@ -20,16 +20,27 @@ import java.util.WeakHashMap; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; +import org.jivesoftware.smackx.jingle.JingleHandler; +import org.jivesoftware.smackx.jingle.JingleManager; +import org.jivesoftware.smackx.jingle.element.Jingle; +import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer; + +import org.jxmpp.jid.FullJid; /** * Manager for JingleFileTransfer (XEP-0234). */ -public final class JingleFileTransferManager extends Manager { +public final class JingleFileTransferManager extends Manager implements JingleHandler { private static final WeakHashMap INSTANCES = new WeakHashMap<>(); private JingleFileTransferManager(XMPPConnection connection) { super(connection); + ServiceDiscoveryManager.getInstanceFor(connection).addFeature(JingleFileTransfer.NAMESPACE_V5); + JingleManager jingleManager = JingleManager.getInstanceFor(connection); + jingleManager.registerDescriptionHandler(JingleFileTransfer.NAMESPACE_V5, this); } public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) { @@ -40,4 +51,13 @@ public final class JingleFileTransferManager extends Manager { } return manager; } + + @Override + public IQ handleJingleRequest(Jingle jingle) { + FullJid fullJid = jingle.getFrom().asFullJidOrThrow(); + String sid = jingle.getSid(); + JingleFileTransferSessionHandler handler = JingleFileTransferSessionHandler.getInstanceFor(connection()); + JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(fullJid, sid, handler); + return handler.handleJingleSessionRequest(jingle, jingle.getSid()); + } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java new file mode 100644 index 000000000..70947c856 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java @@ -0,0 +1,61 @@ +/** + * + * 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_filetransfer; + +import org.jivesoftware.smackx.jingle.JingleSession; +import org.jivesoftware.smackx.jingle.Role; + +import org.jxmpp.jid.FullJid; + +/** + * Class representing a Jingle session in the context of Jingle File Transfer (XEP-0234). + */ +public abstract class JingleFileTransferSession extends JingleSession { + + public enum Type { + offer, + request, + ; + } + + private final Type type; + + public JingleFileTransferSession(FullJid initiator, FullJid responder, Role role, String sid, Type type) { + super(initiator, responder, role, sid); + this.type = type; + } + + public Type getType() { + return type; + } + + public boolean isOffer() { + return this.type == Type.offer; + } + + public boolean isRequest() { + return this.type == Type.request; + } + + public boolean isSender() { + return (isOffer() && isInitiator()) || (isRequest() && isResponder()); + } + + public boolean isReceiver() { + return (isRequest() && isInitiator()) || (isOffer() && isResponder()); + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSessionHandler.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSessionHandler.java new file mode 100644 index 000000000..f5ec151a9 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSessionHandler.java @@ -0,0 +1,56 @@ +/** + * + * 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_filetransfer; + +import java.util.WeakHashMap; + +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smackx.jingle.JingleSessionHandler; +import org.jivesoftware.smackx.jingle.JingleUtil; +import org.jivesoftware.smackx.jingle.element.Jingle; + +/** + * Handler for JingleFileTransfer sessions. + */ +public final class JingleFileTransferSessionHandler implements JingleSessionHandler { + + private static final WeakHashMap INSTANCES = new WeakHashMap<>(); + + private final XMPPConnection connection; + private final JingleUtil jutil; + + private JingleFileTransferSessionHandler(XMPPConnection connection) { + this.connection = connection; + jutil = new JingleUtil(connection); + } + + public static JingleFileTransferSessionHandler getInstanceFor(XMPPConnection connection) { + JingleFileTransferSessionHandler handler = INSTANCES.get(connection); + if (handler == null) { + handler = new JingleFileTransferSessionHandler(connection); + INSTANCES.put(connection, handler); + } + return handler; + } + + @Override + public IQ handleJingleSessionRequest(Jingle jingle, String sessionId) { + + return null; + } +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/IncomingFileTransferListener.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/IncomingFileTransferListener.java new file mode 100644 index 000000000..dff6e0dff --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/IncomingFileTransferListener.java @@ -0,0 +1,27 @@ +/** + * + * 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_filetransfer.listener; + +import org.jivesoftware.smackx.jingle.element.Jingle; + +/** + * Created by vanitas on 18.06.17. + */ +public interface IncomingFileTransferListener { + + void onIncomingJingleFileTransfer(Jingle request); +} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/package-info.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/package-info.java new file mode 100644 index 000000000..438b31b61 --- /dev/null +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/listener/package-info.java @@ -0,0 +1,22 @@ +/** + * + * 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. + */ + +/** + * Smack's API for XEP-0234: Jingle File Transfer. + * Listeners. + */ +package org.jivesoftware.smackx.jingle_filetransfer.listener; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java new file mode 100644 index 000000000..5d7a0d883 --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/FullJidAndSessionId.java @@ -0,0 +1,49 @@ +/** + * + * Copyright 2017 Florian Schmaus, 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.jxmpp.jid.FullJid; + +/** + * Pair of jid and sessionId. + */ +public class FullJidAndSessionId { + private final FullJid fullJid; + private final String sessionId; + + public FullJidAndSessionId(FullJid fullJid, String sessionId) { + this.fullJid = fullJid; + this.sessionId = sessionId; + } + + @Override + public int hashCode() { + int hashCode = 31 * fullJid.hashCode(); + hashCode = 31 * hashCode + sessionId.hashCode(); + return hashCode; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof FullJidAndSessionId)) { + return false; + } + FullJidAndSessionId otherFullJidAndSessionId = (FullJidAndSessionId) other; + return fullJid.equals(otherFullJidAndSessionId.fullJid) + && sessionId.equals(otherFullJidAndSessionId.sessionId); + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java index 8282af33a..a14917774 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java @@ -27,13 +27,12 @@ import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler; import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ.Type; - import org.jivesoftware.smackx.jingle.element.Jingle; +import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle.element.JingleContentDescription; import org.jxmpp.jid.FullJid; -import org.jxmpp.jid.Jid; public final class JingleManager extends Manager { @@ -54,45 +53,47 @@ public final class JingleManager extends Manager { private final Map jingleSessionHandlers = new ConcurrentHashMap<>(); + private final JingleUtil jutil; + private JingleManager(XMPPConnection connection) { super(connection); + jutil = new JingleUtil(connection); + connection.registerIQRequestHandler( - new AbstractIqRequestHandler(Jingle.ELEMENT, Jingle.NAMESPACE, Type.set, Mode.async) { - @Override - public IQ handleIQRequest(IQ iqRequest) { - final Jingle jingle = (Jingle) iqRequest; + new AbstractIqRequestHandler(Jingle.ELEMENT, Jingle.NAMESPACE, Type.set, Mode.async) { + @Override + public IQ handleIQRequest(IQ iqRequest) { + final Jingle jingle = (Jingle) iqRequest; - if (jingle.getContents().isEmpty()) { - Jid from = jingle.getFrom(); - assert (from != null); - FullJid fullFrom = from.asFullJidOrThrow(); - String sid = jingle.getSid(); - FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(fullFrom, sid); - JingleSessionHandler jingleSessionHandler = jingleSessionHandlers.get(fullJidAndSessionId); - if (jingleSessionHandler == null) { - // TODO handle non existing jingle session handler. - return null; - } - return jingleSessionHandler.handleJingleSessionRequest(jingle, sid); - } + FullJid fullFrom = jingle.getFrom().asFullJidOrThrow(); + String sid = jingle.getSid(); + FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(fullFrom, sid); - if (jingle.getContents().size() > 1) { - LOGGER.severe("Jingle IQs with more then one content element are currently not supported by Smack"); - return null; - } + JingleSessionHandler sessionHandler = jingleSessionHandlers.get(fullJidAndSessionId); + if (sessionHandler != null) { + //Handle existing session + return sessionHandler.handleJingleSessionRequest(jingle, jingle.getSid()); + } - JingleContent content = jingle.getContents().get(0); - JingleContentDescription description = content.getDescription(); - JingleHandler jingleDescriptionHandler = descriptionHandlers.get( - description.getNamespace()); - if (jingleDescriptionHandler == null) { - // TODO handle non existing content description handler. - return null; - } - return jingleDescriptionHandler.handleJingleRequest(jingle); + if (jingle.getAction() == JingleAction.session_initiate) { + + JingleContent content = jingle.getContents().get(0); + JingleContentDescription description = content.getDescription(); + JingleHandler jingleDescriptionHandler = descriptionHandlers.get( + description.getNamespace()); + + if (jingleDescriptionHandler == null) { + //Unsupported Application + return jutil.createSessionTerminateUnsupportedApplications(fullFrom, sid); } - }); + return jingleDescriptionHandler.handleJingleRequest(jingle); + } + + //Unknown session + return jutil.createErrorUnknownSession(jingle); + } + }); } public JingleHandler registerDescriptionHandler(String namespace, JingleHandler handler) { @@ -108,31 +109,4 @@ public final class JingleManager extends Manager { FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(otherJid, sessionId); return jingleSessionHandlers.remove(fullJidAndSessionId); } - - private static final class FullJidAndSessionId { - final FullJid fullJid; - final String sessionId; - - private FullJidAndSessionId(FullJid fullJid, String sessionId) { - this.fullJid = fullJid; - this.sessionId = sessionId; - } - - @Override - public int hashCode() { - int hashCode = 31 * fullJid.hashCode(); - hashCode = 31 * hashCode + sessionId.hashCode(); - return hashCode; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof FullJidAndSessionId)) { - return false; - } - FullJidAndSessionId otherFullJidAndSessionId = (FullJidAndSessionId) other; - return fullJid.equals(otherFullJidAndSessionId.fullJid) - && sessionId.equals(otherFullJidAndSessionId.sessionId); - } - } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java index e86223371..f6c817cff 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java @@ -16,28 +16,59 @@ */ package org.jivesoftware.smackx.jingle; -import org.jxmpp.jid.Jid; +import org.jxmpp.jid.FullJid; -// TODO: Is this class still required? If not, then remove it. public class JingleSession { - private final Jid initiator; + protected final FullJid local; - private final Jid responder; + protected final FullJid remote; - private final String sid; + protected final Role role; - public JingleSession(Jid initiator, Jid responder, String sid) { - this.initiator = initiator; - this.responder = responder; + protected final String sid; + + public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) { + if (role == Role.initiator) { + this.local = initiator; + this.remote = responder; + } else { + this.local = responder; + this.remote = initiator; + } this.sid = sid; + this.role = role; + } + + public FullJid getInitiator() { + return isInitiator() ? local : remote; + } + + public boolean isInitiator() { + return role == Role.initiator; + } + + public FullJid getResponder() { + return isResponder() ? local : remote; + } + + public boolean isResponder() { + return role == Role.responder; + } + + public String getSessionId() { + return sid; + } + + public FullJidAndSessionId getFullJidAndSessionId() { + return new FullJidAndSessionId(remote, sid); } @Override public int hashCode() { - int hashCode = 31 + initiator.hashCode(); - hashCode = 31 * hashCode + responder.hashCode(); - hashCode = 31 * hashCode + sid.hashCode(); + int hashCode = 31 + getInitiator().hashCode(); + hashCode = 31 * hashCode + getResponder().hashCode(); + hashCode = 31 * hashCode + getSessionId().hashCode(); return hashCode; } @@ -48,7 +79,8 @@ public class JingleSession { } JingleSession otherJingleSession = (JingleSession) other; - return initiator.equals(otherJingleSession.initiator) && responder.equals(otherJingleSession.responder) - && sid.equals(otherJingleSession.sid); + return getInitiator().equals(otherJingleSession.getInitiator()) + && getResponder().equals(otherJingleSession.getResponder()) + && sid.equals(otherJingleSession.sid); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java index 009f3fe8e..6fb23d4e6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleUtil.java @@ -345,7 +345,6 @@ public class JingleUtil { XMPPError.Builder error = XMPPError.getBuilder(); error.setCondition(XMPPError.Condition.feature_not_implemented) .addExtension(JingleError.UNSUPPORTED_INFO); - return IQ.createErrorResponse(request, error); } @@ -354,7 +353,6 @@ public class JingleUtil { connection.sendStanza(createErrorUnsupportedInfo(request)); } - public IQ createErrorTieBreak(Jingle request) { XMPPError.Builder error = XMPPError.getBuilder(); error.setCondition(XMPPError.Condition.conflict) 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 index 02acf9b5e..d9868b1d1 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleSessionTest.java @@ -23,7 +23,7 @@ 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.FullJid; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.stringprep.XmppStringprepException; @@ -34,18 +34,20 @@ 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"); + FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/r"); + FullJid juliet = JidCreate.fullFrom("juliet@capulet.lit/j"); 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); + JingleSession s1 = new JingleSession(romeo, juliet, Role.initiator, sid); + JingleSession s2 = new JingleSession(juliet, romeo, Role.responder, sid); + JingleSession s3 = new JingleSession(romeo, juliet, Role.responder, StringUtils.randomString(23)); + JingleSession s4 = new JingleSession(juliet, romeo, Role.responder, sid); + JingleSession s5 = new JingleSession(juliet, romeo, Role.initiator, sid); assertNotSame(s1, s2); assertNotSame(s1, s3); assertNotSame(s2, s3); + assertNotSame(s4, s5); assertEquals(s2, s4); assertEquals(s2.hashCode(), s4.hashCode()); }