mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Better test
This commit is contained in:
parent
92117ec00b
commit
bbaa367dfb
1 changed files with 93 additions and 0 deletions
|
@ -17,14 +17,19 @@
|
||||||
package org.jivesoftware.smackx.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static junit.framework.TestCase.assertEquals;
|
||||||
|
import static junit.framework.TestCase.assertNotNull;
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||||
|
|
||||||
import org.jivesoftware.smack.DummyConnection;
|
import org.jivesoftware.smack.DummyConnection;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||||
|
import org.jivesoftware.smack.test.util.TestUtils;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||||
|
import org.jivesoftware.smackx.jingle.provider.JingleProvider;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -51,6 +56,7 @@ public class JingleUtilTest extends SmackTestSuite {
|
||||||
DummyConnection.getDummyConfigurationBuilder()
|
DummyConnection.getDummyConfigurationBuilder()
|
||||||
.setUsernameAndPassword("romeo@montague.lit",
|
.setUsernameAndPassword("romeo@montague.lit",
|
||||||
"iluvJulibabe13").build());
|
"iluvJulibabe13").build());
|
||||||
|
JingleManager jm = JingleManager.getInstanceFor(connection);
|
||||||
jutil = new JingleUtil(connection);
|
jutil = new JingleUtil(connection);
|
||||||
romeo = connection.getUser().asFullJidOrThrow();
|
romeo = connection.getUser().asFullJidOrThrow();
|
||||||
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
||||||
|
@ -63,4 +69,91 @@ public class JingleUtilTest extends SmackTestSuite {
|
||||||
assertEquals(jingle.getStanzaId(), result.getStanzaId());
|
assertEquals(jingle.getStanzaId(), result.getStanzaId());
|
||||||
assertTrue(result.getType() == IQ.Type.result);
|
assertTrue(result.getType() == IQ.Type.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createSessionTerminateDeclineTest() throws Exception {
|
||||||
|
Jingle terminate = jutil.createSessionTerminateDecline(juliet, "thisismadness");
|
||||||
|
String jingleXML =
|
||||||
|
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||||
|
"action='session-terminate' " +
|
||||||
|
"sid='thisismadness'>" +
|
||||||
|
"<reason>" +
|
||||||
|
"<decline/>" +
|
||||||
|
"</reason>" +
|
||||||
|
"</jingle>";
|
||||||
|
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
|
||||||
|
assertXMLEqual(xml, terminate.toXML().toString());
|
||||||
|
Jingle jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||||
|
assertNotNull(jingle);
|
||||||
|
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||||
|
assertEquals(jingle.getReason().asEnum(), JingleReason.Reason.decline);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createSessionTerminateSuccessTest() throws Exception {
|
||||||
|
Jingle success = jutil.createSessionTerminateSuccess(juliet, "thisissparta");
|
||||||
|
String jingleXML =
|
||||||
|
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||||
|
"action='session-terminate' " +
|
||||||
|
"sid='thisissparta'>" +
|
||||||
|
"<reason>" +
|
||||||
|
"<success/>" +
|
||||||
|
"</reason>" +
|
||||||
|
"</jingle>";
|
||||||
|
String xml = getIQXML(romeo, juliet, success.getStanzaId(), jingleXML);
|
||||||
|
assertXMLEqual(xml, success.toXML().toString());
|
||||||
|
Jingle jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||||
|
assertNotNull(jingle);
|
||||||
|
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||||
|
assertEquals(jingle.getReason().asEnum(), JingleReason.Reason.success);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createSessionTerminateBusyTest() throws Exception {
|
||||||
|
Jingle busy = jutil.createSessionTerminateBusy(juliet, "thisispatrick");
|
||||||
|
String jingleXML =
|
||||||
|
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||||
|
"action='session-terminate' " +
|
||||||
|
"sid='thisispatrick'>" +
|
||||||
|
"<reason>" +
|
||||||
|
"<busy/>" +
|
||||||
|
"</reason>" +
|
||||||
|
"</jingle>";
|
||||||
|
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||||
|
assertXMLEqual(xml, busy.toXML().toString());
|
||||||
|
Jingle jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||||
|
assertNotNull(jingle);
|
||||||
|
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||||
|
assertEquals(jingle.getReason().asEnum(), JingleReason.Reason.busy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createSessionTerminateAlternativeSessionTest() throws Exception {
|
||||||
|
Jingle busy = jutil.createSessionTerminateAlternativeSession(juliet, "thisistherhythm", "ofthenight");
|
||||||
|
String jingleXML =
|
||||||
|
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||||
|
"action='session-terminate' " +
|
||||||
|
"sid='thisistherhythm'>" +
|
||||||
|
"<reason>" +
|
||||||
|
"<alternative-session>" +
|
||||||
|
"<sid>ofthenight</sid>" +
|
||||||
|
"</alternative-session>" +
|
||||||
|
"</reason>" +
|
||||||
|
"</jingle>";
|
||||||
|
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||||
|
assertXMLEqual(xml, busy.toXML().toString());
|
||||||
|
Jingle jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||||
|
assertNotNull(jingle);
|
||||||
|
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||||
|
assertEquals(jingle.getReason().asEnum(), JingleReason.Reason.alternative_session);
|
||||||
|
JingleReason.AlternativeSession alt = (JingleReason.AlternativeSession) jingle.getReason();
|
||||||
|
assertEquals("ofthenight", alt.getAlternativeSessionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) {
|
||||||
|
return
|
||||||
|
"<iq from='" + from + "' id='" + stanzaId + "' to='" + to + "' type='set'>" +
|
||||||
|
jingleXML +
|
||||||
|
"</iq>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue