Skip to content

Commit

Permalink
Added test case for custom headers for Dial SIP
Browse files Browse the repository at this point in the history
This refer to #RESTCOMM-1794
  • Loading branch information
gvagenas committed Mar 8, 2018
1 parent af2118a commit 9585bcc
Showing 1 changed file with 90 additions and 0 deletions.
Expand Up @@ -1636,6 +1636,96 @@ public void testDialNumberPstnAbortCallWith569() throws ParseException, Interrup
assertEquals(0, mgcpConnections);
}

private String dialSipRcmlWithCustomHeaders = "<Response><Dial><Sip>sip:+131313@127.0.0.1:"+georgePort+"?X-Custom-Header1=1234&X-Custom-Header2=4321</Sip></Dial></Response>";
@Test @Category(FeatureAltTests.class)
public void testDialSipPstnWithCustomHeaders() throws InterruptedException, MalformedURLException {

stubFor(get(urlPathEqualTo("/1111"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody(dialSipRcmlWithCustomHeaders)));

SipCall georgeCall = georgePhone.createSipCall();
georgeCall.listenForIncomingCall();

// Create outgoing call with first phone
final SipCall bobCall = bobPhone.createSipCall();
bobCall.initiateOutgoingCall(bobContact, "sip:1111@" + restcommContact, null, body, "application", "sdp", null, null);
assertLastOperationSuccess(bobCall);
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
final int response = bobCall.getLastReceivedResponse().getStatusCode();
assertTrue(response == Response.TRYING || response == Response.RINGING);

if (response == Response.TRYING) {
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
}

assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());
assertTrue(bobCall.sendInviteOkAck());

assertTrue(georgeCall.waitForIncomingCall(5000));

//Check custom headers
SipRequest invite = georgeCall.getLastReceivedRequest();
assertEquals(SipRequest.INVITE, invite.getRequestEvent().getRequest().getMethod());

String customHeader1 = ((HeaderExt) invite.getRequestEvent().getRequest().getHeader("X-Custom-Header1")).getValue();
String customHeader2 = ((HeaderExt) invite.getRequestEvent().getRequest().getHeader("X-Custom-Header2")).getValue();
assertEquals("1234", customHeader1);
assertEquals("4321", customHeader2);

assertTrue(georgeCall.sendIncomingCallResponse(Response.TRYING, "George-Trying", 3600));
assertTrue(georgeCall.sendIncomingCallResponse(Response.RINGING, "George-Ringing", 3600));
String receivedBody = new String(georgeCall.getLastReceivedRequest().getRawContent());
assertTrue(georgeCall.sendIncomingCallResponse(Response.OK, "George-OK", 3600, receivedBody, "application", "sdp",
null, null));
assertTrue(georgeCall.waitForAck(5000));

assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==2);
assertTrue(MonitoringServiceTool.getInstance().getLiveIncomingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==1);
assertTrue(MonitoringServiceTool.getInstance().getLiveOutgoingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==1);
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==2);

Thread.sleep(3000);
bobCall.listenForDisconnect();

assertTrue(georgeCall.disconnect());
Thread.sleep(500);
assertTrue(bobCall.waitForDisconnect(5000));
assertTrue(bobCall.respondToDisconnect());

Thread.sleep(10000);

logger.info("About to check the Requests");
List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
assertTrue(requests.size() == 1);
// requests.get(0).g;
String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();// .getQuery();// .getBodyAsString();
List<String> params = Arrays.asList(requestBody.split("&"));
String callSid = "";
for (String param : params) {
if (param.contains("CallSid")) {
callSid = param.split("=")[1];
}
}
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
JsonObject jsonObj = cdr.getAsJsonObject();
assertTrue(jsonObj.get("status").getAsString().equalsIgnoreCase("completed"));
assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);

JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
Map<String, Integer> mgcpResources = MonitoringServiceTool.getInstance().getMgcpResources(metrics);
int mgcpEndpoints = mgcpResources.get("MgcpEndpoints");
int mgcpConnections = mgcpResources.get("MgcpConnections");

assertEquals(0, mgcpEndpoints);
assertEquals(0, mgcpConnections);
}

@Test
@Category(FeatureExpTests.class)
public void testDialNumberPstnRegisteredClientTimesOutCallDisconnects() throws ParseException, InterruptedException, MalformedURLException {
Expand Down

0 comments on commit 9585bcc

Please sign in to comment.