+ getAlicePhone().format(), getAlicePhone());
getBobPhone().register(null, 600);
assertLastOperationSuccess(getBobPhone());
SipCall a = getAlicePhone().createSipCall();
SipCall b = getBobPhone().createSipCall();
b.listenForIncomingCall();
Thread.sleep(10);
// another way to invoke the operation and check the result
// separately:
boolean status_ok = a.initiateOutgoingCall(getBobUri(), null);
assertTrue("Initiate outgoing call failed - " + a.format(), status_ok);
// invoke the Sip operation and check positive result in one step,
// no operation error details if the test fails:
assertTrue("Wait incoming call error or timeout", b
.waitForIncomingCall(5000));
// invoke the Sip operation and result check in one step,
// only standard JUnit output if the test fails:
assertTrue(b.sendIncomingCallResponse(Response.RINGING, "Ringing", 0));
Thread.sleep(1000);
// although the 2-step method is not as compact, it's easier
// to follow what a test is doing since the Sip operations are not
// buried as parameters in assert statements:
b.sendIncomingCallResponse(Response.OK, "Answer - Hello world", 0);
assertLastOperationSuccess("Sending answer response failed - "
+ b.format(), b);
// note with the single step method, you cannot include operation
// error details for when the test fails: ' + a.format()' wouldn't
// work in the first parameter here:
assertTrue("Wait response error", a.waitOutgoingCallResponse(10000));
SipResponse resp = a.getLastReceivedResponse(); // watch for TRYING
int status_code = resp.getStatusCode();
while (status_code != Response.RINGING)
{
assertFalse("Unexpected final response, status = " + status_code,
status_code > 200);
assertFalse("Got OK but no RINGING", status_code == Response.OK);
a.waitOutgoingCallResponse(10000);
assertLastOperationSuccess("Subsequent response never received - "
+ a.format(), a);
resp = a.getLastReceivedResponse();
status_code = resp.getStatusCode();
}
// if you want operation error details in your test fail output,
// you have to invoke and complete the operation first:
a.waitOutgoingCallResponse(10000);
assertLastOperationSuccess("Wait response error - " + a.format(), a);
// throw out any 'TRYING' responses
// Note, you can also get the response status code from the SipCall
// class itself (in addition to getting it from the response as
// above)
while (a.getReturnCode() == Response.TRYING)
{
a.waitOutgoingCallResponse(10000);
assertLastOperationSuccess("Subsequent response never received - "
+ a.format(), a);
}
resp = a.getLastReceivedResponse();
// check for OK response.
assertEquals("Unexpected response received", Response.OK, a
.getReturnCode());
// continue with the test call
a.sendInviteOkAck();
assertLastOperationSuccess("Failure sending ACK - " + a.format(), a);
Thread.sleep(1000);
b.listenForDisconnect();
assertLastOperationSuccess("b listen disc - " + b.format(), b);
a.disconnect();
assertLastOperationSuccess("a disc - " + a.format(), a);
b.waitForDisconnect(10000);
assertLastOperationSuccess("b wait disc - " + b.format(), b);
b.respondToDisconnect();
assertLastOperationSuccess("b disc - " + b.format(), b);
getBobPhone().unregister(null, 10000);
}