mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Rename getSid -> getSession/StreamId
add junit tests for JingleSession
This commit is contained in:
parent
a23eb6aeea
commit
f930c1bdc5
10 changed files with 182 additions and 20 deletions
|
@ -63,7 +63,7 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
|
|||
return blockSize;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
public String getStreamId() {
|
||||
return streamId;
|
||||
}
|
||||
|
||||
|
@ -86,13 +86,13 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
|
|||
@Override
|
||||
public void establishIncomingBytestreamSession(final XMPPConnection connection, final JingleTransportCallback callback, final JingleSession session) {
|
||||
final InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||
LOGGER.log(Level.INFO, "Listen for incoming IBB transports from " + session.getPeer() + ":" + getSid());
|
||||
LOGGER.log(Level.INFO, "Listen for incoming IBB transports from " + session.getPeer() + ":" + getStreamId());
|
||||
InBandBytestreamListener bytestreamListener = new InBandBytestreamListener() {
|
||||
@Override
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
LOGGER.log(Level.INFO, "Incoming IBB stream: " + request.getFrom().asFullJidIfPossible() + ":" + request.getSessionID());
|
||||
if (request.getFrom().asFullJidIfPossible().equals(session.getPeer())
|
||||
&& request.getSessionID().equals(getSid())) {
|
||||
&& request.getSessionID().equals(getStreamId())) {
|
||||
|
||||
inBandBytestreamManager.removeIncomingBytestreamListener(this);
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
|
|||
InBandBytestreamManager inBandBytestreamManager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||
inBandBytestreamManager.setDefaultBlockSize(blockSize);
|
||||
try {
|
||||
JingleIBBTransport.this.bytestreamSession = inBandBytestreamManager.establishSession(session.getPeer(), getSid());
|
||||
JingleIBBTransport.this.bytestreamSession = inBandBytestreamManager.establishSession(session.getPeer(), getStreamId());
|
||||
callback.onTransportReady(this.bytestreamSession);
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException e) {
|
||||
callback.onTransportFailed(e);
|
||||
|
|
|
@ -27,7 +27,7 @@ public class JingleIBBTransportAdapter implements JingleTransportAdapter<JingleI
|
|||
@Override
|
||||
public JingleIBBTransport transportFromElement(JingleContentTransportElement element) {
|
||||
JingleIBBTransportElement transport = (JingleIBBTransportElement) element;
|
||||
return new JingleIBBTransport(transport.getSid(), transport.getBlockSize());
|
||||
return new JingleIBBTransport(transport.getStreamId(), transport.getBlockSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,7 +73,7 @@ public final class JingleIBBTransportManager extends Manager implements JingleTr
|
|||
@Override
|
||||
public JingleTransport<?> createTransportForResponder(JingleContent content, JingleTransport<?> peersTransport) {
|
||||
JingleIBBTransport other = (JingleIBBTransport) peersTransport;
|
||||
return new JingleIBBTransport(other.getSid(), (short) Math.min(other.getBlockSize(), MAX_BLOCKSIZE));
|
||||
return new JingleIBBTransport(other.getStreamId(), (short) Math.min(other.getBlockSize(), MAX_BLOCKSIZE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,7 @@ public class JingleIBBTransportElement extends JingleContentTransportElement {
|
|||
public static final short DEFAULT_BLOCK_SIZE = 4096;
|
||||
|
||||
private final String sid;
|
||||
private final short blockSize;
|
||||
private final Short blockSize;
|
||||
|
||||
public JingleIBBTransportElement(String streamId, Short blockSize) {
|
||||
super(null);
|
||||
|
@ -38,11 +38,11 @@ public class JingleIBBTransportElement extends JingleContentTransportElement {
|
|||
this.blockSize = blockSize != null ? blockSize : DEFAULT_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
public short getBlockSize() {
|
||||
public Short getBlockSize() {
|
||||
return blockSize;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
public String getStreamId() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,21 @@ package org.jivesoftware.smackx.jingle.component;
|
|||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.util.Role;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -82,4 +90,158 @@ public class JingleSessionTest extends SmackTestSuite {
|
|||
|
||||
assertEquals(c1, session.getSoleContentOrThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionAcceptTest() throws XmppStringprepException {
|
||||
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
|
||||
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
|
||||
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
|
||||
JingleSession session = new JingleSession(manager, initiator, responder, Role.initiator, "sessionId");
|
||||
|
||||
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
|
||||
JingleIBBTransport transport = new JingleIBBTransport("streamId", (short) 1024);
|
||||
content.setTransport(transport);
|
||||
|
||||
JingleDescription<?> description = new JingleDescription<JingleContentDescriptionElement>() {
|
||||
public static final String NAMESPACE = "urn:xmpp:jingle:apps:stub:0";
|
||||
|
||||
@Override
|
||||
public JingleContentDescriptionElement getElement() {
|
||||
return new JingleContentDescriptionElement(null) {
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBytestreamReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
};
|
||||
content.setDescription(description);
|
||||
|
||||
session.addContent(content);
|
||||
|
||||
JingleElement sessionElement = session.createSessionInitiate();
|
||||
assertNotNull(sessionElement);
|
||||
assertEquals("sessionId", sessionElement.getSid());
|
||||
assertEquals(initiator, sessionElement.getInitiator());
|
||||
assertNull(sessionElement.getResponder());
|
||||
assertEquals(JingleAction.session_initiate, sessionElement.getAction());
|
||||
JingleContentElement contentElement = sessionElement.getSoleContentOrThrow();
|
||||
assertNotNull(contentElement);
|
||||
assertEquals(content.getName(), contentElement.getName());
|
||||
assertEquals(content.getCreator(), contentElement.getCreator());
|
||||
assertEquals(content.getSenders(), contentElement.getSenders());
|
||||
assertEquals(0, content.getTransportBlacklist().size());
|
||||
assertEquals(content.getElement().toXML().toString(), contentElement.toXML().toString());
|
||||
|
||||
JingleIBBTransportElement transportElement = (JingleIBBTransportElement) contentElement.getTransport();
|
||||
assertNotNull(transportElement);
|
||||
assertEquals(transport.getBlockSize(), transportElement.getBlockSize());
|
||||
assertEquals(transport.getStreamId(), transportElement.getStreamId());
|
||||
assertEquals(transport.getNamespace(), transportElement.getNamespace());
|
||||
assertEquals(transport.getElement().toXML().toString(), transportElement.toXML().toString());
|
||||
|
||||
JingleContentDescriptionElement descriptionElement = contentElement.getDescription();
|
||||
assertNotNull(descriptionElement);
|
||||
assertEquals(description.getNamespace(), descriptionElement.getNamespace());
|
||||
assertEquals(description.getElement().toXML().toString(), descriptionElement.toXML().toString());
|
||||
|
||||
assertNull(contentElement.getSecurity());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void duplicateContentAddTest() throws XmppStringprepException {
|
||||
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
|
||||
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
|
||||
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
|
||||
JingleSession session = new JingleSession(manager, initiator, responder, Role.initiator, "sessionId");
|
||||
|
||||
JingleContent content1 = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
JingleContent content2 = new JingleContent(null, null, null, content1.getName(), null, JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
|
||||
session.addContent(content1);
|
||||
session.addContent(content2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void sessionInitiateThrowsAsResponderTest() {
|
||||
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()),
|
||||
null, null, Role.responder, "session");
|
||||
session.createSessionInitiate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionAcceptTest() throws XmppStringprepException {
|
||||
FullJid initiator = JidCreate.fullFrom("initiator@server.tld/res");
|
||||
FullJid responder = JidCreate.fullFrom("responder@server.tld/res");
|
||||
JingleManager manager = JingleManager.getInstanceFor(new DummyConnection());
|
||||
JingleSession session = new JingleSession(manager, initiator, responder, Role.responder, "sessionId");
|
||||
|
||||
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
|
||||
JingleIBBTransport transport = new JingleIBBTransport("streamId", (short) 1024);
|
||||
content.setTransport(transport);
|
||||
|
||||
JingleDescription<?> description = new JingleDescription<JingleContentDescriptionElement>() {
|
||||
public static final String NAMESPACE = "urn:xmpp:jingle:apps:stub:0";
|
||||
|
||||
@Override
|
||||
public JingleContentDescriptionElement getElement() {
|
||||
return new JingleContentDescriptionElement(null) {
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBytestreamReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
};
|
||||
content.setDescription(description);
|
||||
|
||||
session.addContent(content);
|
||||
|
||||
JingleElement accept = session.createSessionAccept();
|
||||
assertNotNull(accept);
|
||||
assertEquals(JingleAction.session_accept, accept.getAction());
|
||||
assertNull(accept.getInitiator());
|
||||
assertEquals(session.getResponder(), accept.getResponder());
|
||||
assertEquals(1, accept.getContents().size());
|
||||
assertEquals(content.getName(), accept.getSoleContentOrThrow().getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void sessionAcceptThrowsAsInitiatorTest() {
|
||||
JingleSession session = new JingleSession(JingleManager.getInstanceFor(new DummyConnection()),
|
||||
null, null, Role.initiator, "session");
|
||||
session.createSessionAccept();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class JingleIBBTransportTest extends SmackTestSuite {
|
|||
JingleIBBTransport transport = new JingleIBBTransport(sid, size);
|
||||
assertEquals(xml, transport.getElement().toXML().toString());
|
||||
assertEquals(size, (short) transport.getBlockSize());
|
||||
assertEquals(sid, transport.getSid());
|
||||
assertEquals(sid, transport.getStreamId());
|
||||
|
||||
JingleIBBTransportElement parsed = new JingleIBBTransportProvider()
|
||||
.parse(TestUtils.getParser(xml));
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jet;
|
||||
|
||||
import static org.jivesoftware.smackx.jft.JingleFileTransferTest.prepareNewTestFile;
|
||||
import static org.jivesoftware.smackx.jft.JingleFileTransferIntegrationTest.prepareNewTestFile;
|
||||
import static org.jivesoftware.smackx.omemo.OmemoIntegrationTestHelper.cleanServerSideTraces;
|
||||
import static org.jivesoftware.smackx.omemo.OmemoIntegrationTestHelper.setUpOmemoManager;
|
||||
import static org.jivesoftware.smackx.omemo.OmemoIntegrationTestHelper.subscribe;
|
||||
|
@ -46,7 +46,7 @@ import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|||
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
||||
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||
|
||||
public class JetTest extends AbstractOmemoIntegrationTest {
|
||||
public class JetIntegrationTestTest extends AbstractOmemoIntegrationTest {
|
||||
|
||||
private OmemoManager oa, ob;
|
||||
private JetManager ja, jb;
|
||||
|
@ -65,7 +65,7 @@ public class JetTest extends AbstractOmemoIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public JetTest(SmackIntegrationTestEnvironment environment)
|
||||
public JetIntegrationTestTest(SmackIntegrationTestEnvironment environment)
|
||||
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException, TestNotPossibleException {
|
||||
super(environment);
|
|
@ -46,7 +46,7 @@ import org.jxmpp.jid.FullJid;
|
|||
/**
|
||||
* Created by vanitas on 29.06.17.
|
||||
*/
|
||||
public class JingleFileTransferTest extends AbstractSmackIntegrationTest {
|
||||
public class JingleFileTransferIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
private static final File tempDir;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class JingleFileTransferTest extends AbstractSmackIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public JingleFileTransferTest(SmackIntegrationTestEnvironment environment) {
|
||||
public JingleFileTransferIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ import org.junit.AfterClass;
|
|||
import org.junit.Before;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
public class JingleFileTransferTransportFallbackTest extends AbstractSmackIntegrationTest {
|
||||
public class JingleFileTransferTransportFallbackIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
private static final File tempDir;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class JingleFileTransferTransportFallbackTest extends AbstractSmackIntegr
|
|||
}
|
||||
}
|
||||
|
||||
public JingleFileTransferTransportFallbackTest(SmackIntegrationTestEnvironment environment) {
|
||||
public JingleFileTransferTransportFallbackIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
|
@ -49,9 +49,9 @@ import org.junit.Assert;
|
|||
/**
|
||||
* Test the JingleIBBTransport in a very basic case.
|
||||
*/
|
||||
public class JingleTransportTest extends AbstractSmackIntegrationTest {
|
||||
public class JingleTransportIntegrationTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
public JingleTransportTest(SmackIntegrationTestEnvironment environment) {
|
||||
public JingleTransportIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class JingleTransportTest extends AbstractSmackIntegrationTest {
|
|||
XMPPConnection receiver = conTwo;
|
||||
|
||||
JingleIBBTransport sTransport = new JingleIBBTransport();
|
||||
JingleIBBTransport rTransport = new JingleIBBTransport(sTransport.getSid(), sTransport.getBlockSize());
|
||||
JingleIBBTransport rTransport = new JingleIBBTransport(sTransport.getStreamId(), sTransport.getBlockSize());
|
||||
|
||||
JingleSession sSession = new JingleSession(JingleManager.getInstanceFor(sender), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.initiator, "session");
|
||||
JingleSession rSession = new JingleSession(JingleManager.getInstanceFor(receiver), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.responder, "session");
|
Loading…
Reference in a new issue