1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

More tests

This commit is contained in:
vanitasvitae 2017-07-08 00:23:18 +02:00
parent e271532804
commit 63d71230cc
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 71 additions and 17 deletions

View file

@ -249,7 +249,7 @@ public class JingleUtil {
JingleContent.Creator contentCreator, String contentName) { JingleContent.Creator contentCreator, String contentName) {
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_terminate) jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId); .setSessionId(sessionId).setReason(JingleReason.Reason.cancel);
JingleContent.Builder cb = JingleContent.getBuilder(); JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName); cb.setCreator(contentCreator).setName(contentName);
@ -497,8 +497,16 @@ public class JingleUtil {
connection.sendStanza(createErrorOutOfOrder(request)); connection.sendStanza(createErrorOutOfOrder(request));
} }
/**
* XEP-0166 Ex. 16
* @param request
* @return
*/
public IQ createErrorMalformedRequest(Jingle request) { public IQ createErrorMalformedRequest(Jingle request) {
return IQ.createErrorResponse(request, XMPPError.Condition.bad_request); XMPPError.Builder error = XMPPError.getBuilder();
error.setType(XMPPError.Type.CANCEL);
error.setCondition(XMPPError.Condition.bad_request);
return IQ.createErrorResponse(request, error);
} }
public void sendErrorMalformedRequest(Jingle request) public void sendErrorMalformedRequest(Jingle request)

View file

@ -28,6 +28,7 @@ import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.test.util.TestUtils; 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.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleReason; import org.jivesoftware.smackx.jingle.element.JingleReason;
import org.jivesoftware.smackx.jingle.provider.JingleProvider; import org.jivesoftware.smackx.jingle.provider.JingleProvider;
@ -221,10 +222,55 @@ public class JingleUtilTest extends SmackTestSuite {
assertEquals(JingleAction.session_info, jingle.getAction()); assertEquals(JingleAction.session_info, jingle.getAction());
} }
@Test
public void createSessionTerminateContentCancelTest() throws Exception {
Jingle cancel = jutil.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContent.Creator.initiator, "content123");
String jingleXML =
"<jingle xmlns='urn:xmpp:jingle:1' " +
"action='session-terminate' " +
"sid='thisismumbo#5'>" +
"<content creator='initiator' name='content123'/>" +
"<reason>" +
"<cancel/>" +
"</reason>" +
"</jingle>";
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
assertXMLEqual(xml, cancel.toXML().toString());
Jingle jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
assertNotNull(jingle);
assertEquals(JingleAction.session_terminate, jingle.getAction());
assertEquals(JingleReason.Reason.cancel, jingle.getReason().asEnum());
assertEquals("thisismumbo#5", jingle.getSid());
JingleContent content = jingle.getContents().get(0);
assertNotNull(content);
assertEquals("content123", content.getName());
assertEquals(JingleContent.Creator.initiator, content.getCreator());
}
@Test
public void createErrorMalformedRequestTest() throws Exception {
Jingle j = defaultJingle(romeo, "error123");
IQ error = jutil.createErrorMalformedRequest(j);
String xml =
"<iq " +
"to='" + romeo + "' " +
"from='" + romeo +"' " +
"id='" + j.getStanzaId() + "' " +
"type='error'>" +
"<error type='cancel'>" +
"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
assertXMLEqual(xml, error.toXML().toString());
}
private String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) { private String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) {
return return "<iq from='" + from + "' id='" + stanzaId + "' to='" + to + "' type='set'>" +
"<iq from='" + from + "' id='" + stanzaId + "' to='" + to + "' type='set'>" +
jingleXML + jingleXML +
"</iq>"; "</iq>";
} }
private Jingle defaultJingle(FullJid recipient, String sessionId) {
return jutil.createSessionPing(recipient, sessionId);
}
} }