From 4b8ac5a1abd1eb4a31fc70fcf0f666efb07da4a0 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Wed, 9 Aug 2017 19:44:31 +0200 Subject: [PATCH] More Jingle IBB tests --- .../jingle_ibb/JingleIBBTransport.java | 5 ++++- .../jingle_ibb/JingleIBBTransportManager.java | 4 +--- .../element/JingleIBBTransportElement.java | 4 +--- .../smackx/jingle/JingleElementTest.java | 9 ++++---- .../jingle_ibb/JingleIBBTransportTest.java | 22 ++++++++++++++++++- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java index 8f92400e4..62032841b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransport.java @@ -47,6 +47,9 @@ public class JingleIBBTransport extends JingleTransport 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 diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/element/JingleIBBTransportElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/element/JingleIBBTransportElement.java index a7156e5f8..d4c259f3d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/element/JingleIBBTransportElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/element/JingleIBBTransportElement.java @@ -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() { diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleElementTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleElementTest.java index eadb1f911..09a9a2d49 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleElementTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleElementTest.java @@ -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 = "" + "" + "" + "" + ""; @@ -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 = "" + "" + "" + "" + ""; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportTest.java index 0264a393e..422d1e934 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportTest.java @@ -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()); + } }