1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 14:32:06 +01:00

More Jingle IBB tests

This commit is contained in:
vanitasvitae 2017-08-09 19:44:31 +02:00
parent efaa3c27a9
commit 4b8ac5a1ab
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
5 changed files with 32 additions and 12 deletions

View file

@ -47,6 +47,9 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
public static final String NAMESPACE_V1 = "urn:xmpp:jingle:transports:ibb:1";
public static final String NAMESPACE = NAMESPACE_V1;
public static final Short DEFAULT_BLOCK_SIZE = 4096;
public static final Short MAX_BLOCKSIZE = 8192;
private final String streamId;
private Short blockSize;
@ -56,7 +59,7 @@ public class JingleIBBTransport extends JingleTransport<JingleIBBTransportElemen
}
public JingleIBBTransport() {
this(StringUtils.randomString(10), JingleIBBTransportElement.DEFAULT_BLOCK_SIZE);
this(StringUtils.randomString(10), DEFAULT_BLOCK_SIZE);
}
public Short getBlockSize() {

View file

@ -33,8 +33,6 @@ import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTra
*/
public final class JingleIBBTransportManager extends Manager implements JingleTransportManager {
public static final short MAX_BLOCKSIZE = 8192;
private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
static {
@ -73,7 +71,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.getStreamId(), (short) Math.min(other.getBlockSize(), MAX_BLOCKSIZE));
return new JingleIBBTransport(other.getStreamId(), (short) Math.min(other.getBlockSize(), JingleIBBTransport.MAX_BLOCKSIZE));
}
@Override

View file

@ -27,15 +27,13 @@ public class JingleIBBTransportElement extends JingleContentTransportElement {
public static final String ATTR_BLOCK_SIZE = "block-size";
public static final String ATTR_SID = "sid";
public static final Short DEFAULT_BLOCK_SIZE = 4096;
private final String sid;
private final Short blockSize;
public JingleIBBTransportElement(String streamId, Short blockSize) {
super(null);
this.sid = streamId;
this.blockSize = blockSize != null ? blockSize : DEFAULT_BLOCK_SIZE;
this.blockSize = blockSize != null ? blockSize : JingleIBBTransport.DEFAULT_BLOCK_SIZE;
}
public Short getBlockSize() {

View file

@ -32,6 +32,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
import org.jivesoftware.smackx.jingle.provider.JingleProvider;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
import org.junit.Before;
@ -290,7 +291,7 @@ public class JingleElementTest extends SmackTestSuite {
@Test
public void createTransportAcceptTest() throws IOException, SAXException {
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransport.DEFAULT_BLOCK_SIZE));
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='transport-accept' " +
@ -298,7 +299,7 @@ public class JingleElementTest extends SmackTestSuite {
"sid='transAcc'>" +
"<content creator='initiator' name='cname'>" +
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
"sid='transid'/>" +
"</content>" +
"</jingle>";
@ -315,7 +316,7 @@ public class JingleElementTest extends SmackTestSuite {
@Test
public void createTransportReplaceTest() throws IOException, SAXException {
JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransport.DEFAULT_BLOCK_SIZE));
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='transport-replace' " +
@ -323,7 +324,7 @@ public class JingleElementTest extends SmackTestSuite {
"sid='transAcc'>" +
"<content creator='initiator' name='cname'>" +
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
"block-size='" + JingleIBBTransport.DEFAULT_BLOCK_SIZE + "' " +
"sid='transid'/>" +
"</content>" +
"</jingle>";

View file

@ -20,6 +20,7 @@ import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.StringUtils;
@ -52,7 +53,7 @@ public class JingleIBBTransportTest extends SmackTestSuite {
assertEquals(xml, parsed.toXML().toString());
JingleIBBTransport transport1 = new JingleIBBTransport();
assertEquals(JingleIBBTransportElement.DEFAULT_BLOCK_SIZE, transport1.getBlockSize());
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport1.getBlockSize());
assertFalse(transport.equals(null));
@ -63,4 +64,23 @@ public class JingleIBBTransportTest extends SmackTestSuite {
transport1.handleSessionAccept(transport2.getElement(), null);
assertEquals(transport2.getBlockSize(), transport1.getBlockSize());
}
@Test
public void jingleIBBTransportManagerTest() {
JingleIBBTransportManager manager = JingleIBBTransportManager.getInstanceFor(new DummyConnection());
JingleIBBTransport transport1 = (JingleIBBTransport) manager.createTransportForInitiator(null);
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport1.getBlockSize());
JingleIBBTransport transport2 = new JingleIBBTransport("sid", (short) 256);
JingleIBBTransport transport3 = (JingleIBBTransport) manager.createTransportForResponder(null, transport2);
assertEquals((Short) (short) 256, transport3.getBlockSize());
JingleIBBTransport transport4 = new JingleIBBTransport("sod", Short.MAX_VALUE);
assertEquals((Short) Short.MAX_VALUE, transport4.getBlockSize());
JingleIBBTransport transport5 = (JingleIBBTransport) manager.createTransportForResponder(null, transport4);
assertEquals(JingleIBBTransport.MAX_BLOCKSIZE, transport5.getBlockSize());
}
}