Skip to content

Commit de954ab

Browse files
committed
Test case for Restcomm act as Proxy feature with Answer Delay
This refer to #2286
1 parent 4c7567c commit de954ab

2 files changed

Lines changed: 929 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
package org.restcomm.connect.testsuite.telephony;
2+
3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
4+
import org.apache.log4j.Logger;
5+
import org.cafesip.sipunit.SipCall;
6+
import org.cafesip.sipunit.SipPhone;
7+
import org.cafesip.sipunit.SipStack;
8+
import org.jboss.arquillian.container.mss.extension.SipStackTool;
9+
import org.jboss.arquillian.container.test.api.Deployer;
10+
import org.jboss.arquillian.container.test.api.Deployment;
11+
import org.jboss.arquillian.junit.Arquillian;
12+
import org.jboss.arquillian.test.api.ArquillianResource;
13+
import org.jboss.shrinkwrap.api.ShrinkWrap;
14+
import org.jboss.shrinkwrap.api.spec.WebArchive;
15+
import org.jboss.shrinkwrap.resolver.api.maven.archive.ShrinkWrapMaven;
16+
import org.junit.After;
17+
import org.junit.Before;
18+
import org.junit.BeforeClass;
19+
import org.junit.Rule;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.restcomm.connect.commons.Version;
23+
import org.restcomm.connect.testsuite.tools.MonitoringServiceTool;
24+
25+
import javax.sip.message.Response;
26+
import java.net.MalformedURLException;
27+
import java.net.URL;
28+
import java.text.ParseException;
29+
30+
import static org.cafesip.sipunit.SipAssert.assertLastOperationSuccess;
31+
import static org.junit.Assert.assertEquals;
32+
import static org.junit.Assert.assertTrue;
33+
34+
/**
35+
* Created by gvagenas on 26/06/2017.
36+
*/
37+
@RunWith(Arquillian.class)
38+
public class RestcommActingAsProxyAnswerDelayTest {
39+
40+
private final static Logger logger = Logger.getLogger(RestcommActingAsProxyAnswerDelayTest.class.getName());
41+
42+
@Deployment(name = "RestcommActingAsProxyTest", managed = true, testable = false)
43+
public static WebArchive createWebArchiveNoGw() {
44+
logger.info("Packaging Test App");
45+
WebArchive archive = ShrinkWrap.create(WebArchive.class, "restcomm.war");
46+
final WebArchive restcommArchive = ShrinkWrapMaven.resolver()
47+
.resolve("org.restcomm:restcomm-connect.application:war:" + version).withoutTransitivity()
48+
.asSingle(WebArchive.class);
49+
archive = archive.merge(restcommArchive);
50+
archive.delete("/WEB-INF/sip.xml");
51+
archive.delete("/WEB-INF/conf/restcomm.xml");
52+
archive.delete("/WEB-INF/data/hsql/restcomm.script");
53+
archive.delete("/WEB-INF/classes/application.conf");
54+
archive.addAsWebInfResource("sip.xml");
55+
archive.addAsWebInfResource("restcomm_acting_as_proxy_answer_delay.xml", "conf/restcomm.xml");
56+
archive.addAsWebInfResource("restcomm.script_acting_as_proxy", "data/hsql/restcomm.script");
57+
archive.addAsWebInfResource("akka_application.conf", "classes/application.conf");
58+
logger.info("Packaged Test App");
59+
return archive;
60+
}
61+
62+
private static final String version = Version.getVersion();
63+
private static final byte[] bytes = new byte[] { 118, 61, 48, 13, 10, 111, 61, 117, 115, 101, 114, 49, 32, 53, 51, 54, 53,
64+
53, 55, 54, 53, 32, 50, 51, 53, 51, 54, 56, 55, 54, 51, 55, 32, 73, 78, 32, 73, 80, 52, 32, 49, 50, 55, 46, 48, 46,
65+
48, 46, 49, 13, 10, 115, 61, 45, 13, 10, 99, 61, 73, 78, 32, 73, 80, 52, 32, 49, 50, 55, 46, 48, 46, 48, 46, 49,
66+
13, 10, 116, 61, 48, 32, 48, 13, 10, 109, 61, 97, 117, 100, 105, 111, 32, 54, 48, 48, 48, 32, 82, 84, 80, 47, 65,
67+
86, 80, 32, 48, 13, 10, 97, 61, 114, 116, 112, 109, 97, 112, 58, 48, 32, 80, 67, 77, 85, 47, 56, 48, 48, 48, 13, 10 };
68+
private static final String body = new String(bytes);
69+
70+
@ArquillianResource
71+
private Deployer deployer;
72+
@ArquillianResource
73+
URL deploymentUrl;
74+
75+
@Rule
76+
public WireMockRule wireMockRule = new WireMockRule(8090); // No-args constructor defaults to port 8080
77+
78+
private static SipStackTool tool1;
79+
private static SipStackTool tool2;
80+
private static SipStackTool tool3;
81+
private static SipStackTool tool4;
82+
// private static SipStackTool tool5;
83+
84+
// Bob is a simple SIP Client. Will not register with Restcomm
85+
private SipStack bobSipStack;
86+
private SipPhone bobPhone;
87+
private String bobContact = "sip:bob@127.0.0.1:5090";
88+
89+
// Alice is a Restcomm Client with VoiceURL. This Restcomm Client can register with Restcomm and whatever will dial the RCML
90+
// of the VoiceURL will be executed.
91+
private SipStack otherRestcommSipStack;
92+
private SipPhone otherRestcommPhone;
93+
private String otherRestcommContact = "sip:+15126008888@127.0.0.1:5091";
94+
95+
// Henrique is a simple SIP Client. Will not register with Restcomm
96+
private SipStack henriqueSipStack;
97+
private SipPhone henriquePhone;
98+
private String henriqueContact = "sip:henrique@127.0.0.1:5092";
99+
100+
// George is a simple SIP Client. Will not register with Restcomm
101+
private SipStack georgeSipStack;
102+
private SipPhone georgePhone;
103+
private String georgeContact = "sip:+15126008888@127.0.0.1:5070";
104+
105+
// subaccountclient is a simple SIP Client. Will register with Restcomm
106+
// private SipStack subAccountClientSipStack;
107+
// private SipPhone subAccountClientPhone;
108+
// private String subAccountClientContact = "sip:subaccountclient@127.0.0.1:5093";
109+
110+
private String adminAccountSid = "ACae6e420f425248d6a26948c17a9e2acf";
111+
private String adminAuthToken = "77f8c12cc7b8f8423e5c38b035249166";
112+
113+
// private String subAccountSid = "ACae6e420f425248d6a26948c17a9e2acg";
114+
// private String subAuthToken = "77f8c12cc7b8f8423e5c38b035249166";
115+
116+
@BeforeClass
117+
public static void beforeClass() throws Exception {
118+
tool1 = new SipStackTool("RestcommActingAsProxyTest1");
119+
tool2 = new SipStackTool("RestcommActingAsProxyTest2");
120+
tool3 = new SipStackTool("RestcommActingAsProxyTest3");
121+
tool4 = new SipStackTool("RestcommActingAsProxyTest4");
122+
// tool5 = new SipStackTool("DialActionTest5");
123+
}
124+
125+
@Before
126+
public void before() throws Exception {
127+
bobSipStack = tool1.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5090", "127.0.0.1:5080");
128+
bobPhone = bobSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, bobContact);
129+
130+
otherRestcommSipStack = tool2.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5091", "127.0.0.1:5080");
131+
otherRestcommPhone = otherRestcommSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, otherRestcommContact);
132+
133+
henriqueSipStack = tool3.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5092", "127.0.0.1:5080");
134+
henriquePhone = henriqueSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, henriqueContact);
135+
//
136+
georgeSipStack = tool4.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5070", "127.0.0.1:5080");
137+
georgePhone = georgeSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, georgeContact);
138+
//
139+
// subAccountClientSipStack = tool5.initializeSipStack(SipStack.PROTOCOL_UDP, "127.0.0.1", "5093", "127.0.0.1:5080");
140+
// subAccountClientPhone = subAccountClientSipStack.createSipPhone("127.0.0.1", SipStack.PROTOCOL_UDP, 5080, subAccountClientContact);
141+
}
142+
143+
@After
144+
public void after() throws Exception {
145+
if (bobPhone != null) {
146+
bobPhone.dispose();
147+
}
148+
if (bobSipStack != null) {
149+
bobSipStack.dispose();
150+
}
151+
152+
if (otherRestcommSipStack != null) {
153+
otherRestcommSipStack.dispose();
154+
}
155+
if (otherRestcommPhone != null) {
156+
otherRestcommPhone.dispose();
157+
}
158+
159+
if (henriqueSipStack != null) {
160+
henriqueSipStack.dispose();
161+
}
162+
if (henriquePhone != null) {
163+
henriquePhone.dispose();
164+
}
165+
166+
// if (georgePhone != null) {
167+
// georgePhone.dispose();
168+
// }
169+
// if (georgeSipStack != null) {
170+
// georgeSipStack.dispose();
171+
// }
172+
//
173+
// if (subAccountClientPhone != null) {
174+
// subAccountClientPhone.dispose();
175+
// }
176+
// if (subAccountClientSipStack != null) {
177+
// subAccountClientSipStack.dispose();
178+
// }
179+
Thread.sleep(1000);
180+
wireMockRule.resetRequests();
181+
Thread.sleep(4000);
182+
}
183+
184+
185+
@Test
186+
public void testDialNumberToProxyFromClient() throws ParseException, InterruptedException, MalformedURLException {
187+
SipCall otherRestcommCall = otherRestcommPhone.createSipCall();
188+
otherRestcommCall.listenForIncomingCall();
189+
190+
// Create outgoing call with first phone
191+
final SipCall bobCall = bobPhone.createSipCall();
192+
bobCall.initiateOutgoingCall(bobContact, "sip:+15126008888@127.0.0.1:5080", null, body, "application", "sdp", null, null);
193+
assertLastOperationSuccess(bobCall);
194+
195+
assertTrue(otherRestcommCall.waitForIncomingCall(10000));
196+
assertTrue(otherRestcommCall.sendIncomingCallResponse(Response.TRYING, "George-Trying", 3600));
197+
assertTrue(otherRestcommCall.sendIncomingCallResponse(Response.RINGING, "George-Ringing", 3600));
198+
String receivedBody = new String(otherRestcommCall.getLastReceivedRequest().getRawContent());
199+
assertTrue(otherRestcommCall.sendIncomingCallResponse(Response.OK, "George-OK", 3600, receivedBody, "application", "sdp",
200+
null, null));
201+
202+
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
203+
int response = bobCall.getLastReceivedResponse().getStatusCode();
204+
while (response != Response.OK) {
205+
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
206+
response = bobCall.getLastReceivedResponse().getStatusCode();
207+
}
208+
assertTrue(bobCall.sendInviteOkAck());
209+
210+
assertTrue(otherRestcommCall.waitForAck(50000));
211+
212+
assertEquals(2, MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
213+
assertEquals(1, MonitoringServiceTool.getInstance().getLiveIncomingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
214+
assertEquals(1, MonitoringServiceTool.getInstance().getLiveOutgoingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
215+
assertEquals(2, MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
216+
217+
Thread.sleep(1000);
218+
219+
otherRestcommCall.listenForDisconnect();
220+
assertTrue(bobCall.disconnect());
221+
assertTrue(otherRestcommCall.waitForDisconnect(5000));
222+
otherRestcommCall.respondToDisconnect();
223+
224+
Thread.sleep(10000);
225+
226+
// logger.info("About to check the Requests");
227+
// List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
228+
// assertTrue(requests.size() == 1);
229+
// // requests.get(0).g;
230+
// String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();// .getQuery();// .getBodyAsString();
231+
// List<String> params = Arrays.asList(requestBody.split("&"));
232+
// String callSid = "";
233+
// for (String param : params) {
234+
// if (param.contains("CallSid")) {
235+
// callSid = param.split("=")[1];
236+
// }
237+
// }
238+
// JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
239+
// JsonObject jsonObj = cdr.getAsJsonObject();
240+
// String status = jsonObj.get("status").getAsString();
241+
// logger.info("Status: "+status);
242+
// assertTrue(status.equalsIgnoreCase("completed"));
243+
assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);
244+
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);
245+
}
246+
247+
@Test
248+
public void testDialNumberToProxyFromNonClient() throws ParseException, InterruptedException, MalformedURLException {
249+
SipCall georgeCall = georgePhone.createSipCall();
250+
georgeCall.listenForIncomingCall();
251+
252+
// Create outgoing call with first phone
253+
final SipCall henriqueCall = henriquePhone.createSipCall();
254+
henriqueCall.initiateOutgoingCall(henriqueContact, "sip:+15126008888@127.0.0.1:5080", null, body, "application", "sdp", null, null);
255+
assertLastOperationSuccess(henriqueCall);
256+
257+
assertTrue(georgeCall.waitForIncomingCall(10000));
258+
assertTrue(georgeCall.sendIncomingCallResponse(Response.TRYING, "George-Trying", 3600));
259+
assertTrue(georgeCall.sendIncomingCallResponse(Response.RINGING, "George-Ringing", 3600));
260+
String receivedBody = new String(georgeCall.getLastReceivedRequest().getRawContent());
261+
assertTrue(georgeCall.sendIncomingCallResponse(Response.OK, "George-OK", 3600, receivedBody, "application", "sdp",
262+
null, null));
263+
264+
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
265+
int response = henriqueCall.getLastReceivedResponse().getStatusCode();
266+
while (response != Response.OK) {
267+
assertTrue(henriqueCall.waitOutgoingCallResponse(5 * 1000));
268+
response = henriqueCall.getLastReceivedResponse().getStatusCode();
269+
}
270+
271+
assertTrue(henriqueCall.sendInviteOkAck());
272+
273+
assertTrue(georgeCall.waitForAck(50000));
274+
275+
assertEquals(2, MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
276+
assertEquals(1, MonitoringServiceTool.getInstance().getLiveIncomingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
277+
assertEquals(1, MonitoringServiceTool.getInstance().getLiveOutgoingCallStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
278+
assertEquals(2, MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken));
279+
280+
Thread.sleep(1000);
281+
282+
georgeCall.listenForDisconnect();
283+
assertTrue(henriqueCall.disconnect());
284+
assertTrue(georgeCall.waitForDisconnect(5000));
285+
georgeCall.respondToDisconnect();
286+
287+
Thread.sleep(10000);
288+
289+
// logger.info("About to check the Requests");
290+
// List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
291+
// assertTrue(requests.size() == 1);
292+
// // requests.get(0).g;
293+
// String requestBody = new URL(requests.get(0).getAbsoluteUrl()).getQuery();// .getQuery();// .getBodyAsString();
294+
// List<String> params = Arrays.asList(requestBody.split("&"));
295+
// String callSid = "";
296+
// for (String param : params) {
297+
// if (param.contains("CallSid")) {
298+
// callSid = param.split("=")[1];
299+
// }
300+
// }
301+
// JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
302+
// JsonObject jsonObj = cdr.getAsJsonObject();
303+
// String status = jsonObj.get("status").getAsString();
304+
// logger.info("Status: "+status);
305+
// assertTrue(status.equalsIgnoreCase("completed"));
306+
assertTrue(MonitoringServiceTool.getInstance().getStatistics(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);
307+
assertTrue(MonitoringServiceTool.getInstance().getLiveCallsArraySize(deploymentUrl.toString(),adminAccountSid, adminAuthToken)==0);
308+
}
309+
310+
}

0 commit comments

Comments
 (0)