2828import org .restcomm .connect .testsuite .http .RestcommCallsTool ;
2929
3030import javax .sip .Dialog ;
31+ import javax .sip .DialogState ;
3132import javax .sip .SipException ;
3233import javax .sip .address .SipURI ;
3334import javax .sip .header .FromHeader ;
5556import static org .junit .Assert .assertTrue ;
5657import org .junit .experimental .categories .Category ;
5758import org .restcomm .connect .commons .annotations .ParallelClassTests ;
58- import org .restcomm .connect .commons .annotations .WithInMinsTests ;
59- import org .restcomm .connect .testsuite .NetworkPortAssigner ;
6059import org .restcomm .connect .commons .annotations .UnstableTests ;
60+ import org .restcomm .connect .testsuite .NetworkPortAssigner ;
6161import org .restcomm .connect .testsuite .WebArchiveUtil ;
6262
6363/**
@@ -91,7 +91,7 @@ public class TestDialVerbPartTwo {
9191 @ Rule
9292 public WireMockRule wireMockRule = new WireMockRule (mockPort ); // No-args constructor defaults to port 8080
9393 private String dialClientWithRecordingRcml = "<Response><Dial timeLimit=\" 10\" timeout=\" 10\" record=\" true\" action=\" http://127.0.0.1:" + mockPort + "/action\" method=\" GET\" ><Client>alice</Client></Dial></Response>" ;
94- private String dialConferenceWithDialActionRcml = "<Response><Dial action=\" http://127.0.0.1:" + mockPort + "/action\" method=\" GET\" ><Conference>test </Conference></Dial></Response>" ;
94+ private String dialConferenceWithDialActionRcml = "<Response><Dial action=\" http://127.0.0.1:" + mockPort + "/action\" method=\" GET\" ><Conference>test9876 </Conference></Dial></Response>" ;
9595 private String dialClientWithRecordingRcml2 = "<Response><Dial timeLimit=\" 10\" timeout=\" 10\" record=\" true\" action=\" http://127.0.0.1:" + mockPort + "/action&sticky_numToDial=00306986971731\" method=\" GET\" ><Client>alice</Client></Dial></Response>" ;
9696 private String dialRecordWithActionRcml = "<Response><Record action=\" http://127.0.0.1:" + mockPort + "/recordAction\" method=\" GET\" finishOnKey=\" *\" maxLength=\" 10\" playBeep=\" true\" /></Response>" ;
9797 private String dialClientWithActionRcml = "<Response><Dial action=\" http://127.0.0.1:" + mockPort + "/action\" method=\" GET\" ><Client>alice</Client></Dial></Response>" ;
@@ -166,20 +166,23 @@ public void before() throws Exception {
166166 @ After
167167 public void after () throws Exception {
168168 if (bobPhone != null ) {
169+ bobPhone .unregister (bobContact , 3600 );
169170 bobPhone .dispose ();
170171 }
171172 if (bobSipStack != null ) {
172173 bobSipStack .dispose ();
173174 }
174175
175- if (aliceSipStack != null ) {
176- aliceSipStack .dispose ();
177- }
178176 if (alicePhone != null ) {
177+ alicePhone .unregister (aliceContact , 3600 );
179178 alicePhone .dispose ();
180179 }
180+ if (aliceSipStack != null ) {
181+ aliceSipStack .dispose ();
182+ }
181183
182184 if (georgePhone != null ) {
185+ georgePhone .unregister (georgeContact , 3600 );
183186 georgePhone .dispose ();
184187 }
185188 if (georgeSipStack != null ) {
@@ -503,17 +506,20 @@ public synchronized void testDialConferenceWithDialActionNoRcml() throws Interru
503506 assertTrue (bobCall .waitForAnswer (5000 ));
504507 }
505508
506- private String dialConferenceNoDialActionSendSMSRcml = "<Response><Dial><Conference>test </Conference></Dial>" +
509+ private String dialConferenceNoDialActionSendSMSRcml = "<Response><Dial><Conference>test12345 </Conference></Dial>" +
507510 "<Sms to=\" bob\" from=\" +12223334499\" >Hello World!</Sms></Response>" ;
508511 private String dialConferenceNoDialActionRcml = "<Response><Dial><Conference>test</Conference></Dial></Response>" ;
509512 @ Test
510- @ Category ({UnstableTests . class , FeatureAltTests .class })
513+ @ Category ({FeatureAltTests .class })
511514 public synchronized void testDialConferenceNoDialAction_SendSms () throws InterruptedException , ParseException {
515+ // wireMockRule.resetMappings();
512516 stubFor (get (urlPathEqualTo ("/1111" ))
513517 .willReturn (aResponse ()
514518 .withStatus (200 )
515519 .withHeader ("Content-Type" , "text/xml" )
516- .withBody (dialConferenceNoDialActionSendSMSRcml )));
520+ // .withBody(dialConferenceNoDialActionSendSMSRcml)));
521+ .withBody ("<Response><Dial><Conference>test12345</Conference></Dial>" +
522+ "<Sms to=\" bob\" from=\" +12223334499\" >Hello World!</Sms></Response>" )));
517523
518524 // Phone2 register as alice
519525 SipURI uri = aliceSipStack .getAddressFactory ().createSipURI (null , restcommContact );
@@ -543,15 +549,16 @@ public synchronized void testDialConferenceNoDialAction_SendSms() throws Interru
543549 assertTrue (!(bobCall .getLastReceivedResponse ().getStatusCode () >= 400 ));
544550
545551 //Now bob is connected to the conference room
552+ bobCall .listenForMessage ();
546553
547554 Thread .sleep (7000 );
548555
549556 // hangup.
550557 bobCall .disconnect ();
551558 assertTrue (bobCall .waitForAnswer (5000 ));
552559
553- bobCall . listenForMessage ();
554- assertTrue (bobCall .waitForMessage (60 * 1000 ));
560+
561+ assertTrue (bobCall .waitForMessage (90 * 1000 ));
555562 assertTrue (bobCall .sendMessageResponse (200 , "OK-Message Received" , 3600 ));
556563 Request messageReceived = bobCall .getLastReceivedMessageRequest ();
557564 assertTrue (new String (messageReceived .getRawContent ()).equalsIgnoreCase ("Hello World!" ));
@@ -706,7 +713,7 @@ public synchronized void testDialClientAliceWithRecordAndStatusCallbackForApp()
706713 }
707714
708715 @ Test //Test case for issue 320
709- @ Category ({UnstableTests . class , FeatureAltTests .class })
716+ @ Category ({FeatureAltTests .class })
710717 public synchronized void testDialClientAliceWithRecordAndStatusCallbackForAppForThreeCalls () throws InterruptedException , ParseException , MalformedURLException {
711718 stubFor (get (urlPathEqualTo ("/1111" ))
712719 .willReturn (aResponse ()
@@ -726,12 +733,14 @@ public synchronized void testDialClientAliceWithRecordAndStatusCallbackForAppFor
726733
727734 // Phone2 register as alice
728735 SipURI uri = aliceSipStack .getAddressFactory ().createSipURI (null , restcommContact );
729- assertTrue (alicePhone .register (uri , "alice" , "1234" , aliceContact , 3600 , 3600 ));
736+ assertTrue (alicePhone .register (uri , "alice" , "1234" , aliceContact , 600 , 600 ));
730737
731738 // Prepare second phone to receive call
732739 SipCall aliceCall = alicePhone .createSipCall ();
740+ alicePhone .setLoopback (true );
733741 aliceCall .listenForIncomingCall ();
734742
743+
735744 // Create outgoing call with first phone
736745 final SipCall bobCall = bobPhone .createSipCall ();
737746 bobCall .initiateOutgoingCall (bobContact , dialRestcommWithStatusCallback , null , body , "application" , "sdp" , null , null );
@@ -838,11 +847,13 @@ public synchronized void testDialClientAliceWithRecordAndStatusCallbackForAppFor
838847
839848 Thread .sleep (3000 );
840849
850+ assertTrue (alicePhone .register (uri , "alice" , "1234" , aliceContact , 600 , 600 ));
851+
841852 recordings = RestcommCallsTool .getInstance ().getRecordings (deploymentUrl .toString (), adminAccountSid , adminAuthToken );
842853 assertNotNull (recordings );
843854 assertTrue (recordings .size () >= 2 );
844855 double duration = recordings .get (1 ).getAsJsonObject ().get ("duration" ).getAsDouble ();
845- assertEquals (3 .0 , duration , 0.5 );
856+ assertEquals (7 .0 , duration , 1.0 );
846857 assertNotNull (((JsonObject )recordings .get (1 )).get ("uri" ).getAsString ());
847858
848859 /*
@@ -900,7 +911,7 @@ public synchronized void testDialClientAliceWithRecordAndStatusCallbackForAppFor
900911 recordings = RestcommCallsTool .getInstance ().getRecordings (deploymentUrl .toString (), adminAccountSid , adminAuthToken );
901912 assertNotNull (recordings );
902913 assertTrue (recordings .size () >= 3 );
903- assertTrue ( " 7.0" . equalsIgnoreCase ((( JsonObject )recordings .get (2 )).get ("duration" ).getAsString ()) );
914+ assertEquals ( 7.0 , (( JsonObject )recordings .get (2 )).get ("duration" ).getAsDouble (), 1.0 );
904915 assertNotNull (((JsonObject )recordings .get (2 )).get ("uri" ).getAsString ());
905916
906917 logger .info ("About to check the Status Callback Requests" );
@@ -1002,7 +1013,6 @@ public synchronized void testRecordWithActionAndStatusCallbackForAppWithDisconne
10021013 }
10031014
10041015 @ Test
1005- @ Category (UnstableTests .class )
10061016 //Test case for github issue 859
10071017 public synchronized void testRecordWithActionAndStatusCallbackForAppWithBobSendsFinishKey () throws InterruptedException , ParseException {
10081018 stubFor (get (urlPathEqualTo ("/1111" ))
@@ -1048,10 +1058,14 @@ public synchronized void testRecordWithActionAndStatusCallbackForAppWithBobSends
10481058 bobCall .sendInviteOkAck ();
10491059 assertTrue (!(bobCall .getLastReceivedResponse ().getStatusCode () >= 400 ));
10501060
1061+ bobCall .listenForDisconnect ();
1062+
10511063 //Here we have Restcomm voice mail app for 10 sec
10521064 Thread .sleep (5000 );
10531065
10541066 Dialog dialog = bobCall .getDialog ();
1067+ assertNotNull (dialog );
1068+ assertEquals (DialogState .CONFIRMED , dialog .getState ());
10551069 String infoBody = "\n " +
10561070 "Signal=*\n " +
10571071 "Duration=28" ;
@@ -1070,7 +1084,7 @@ public synchronized void testRecordWithActionAndStatusCallbackForAppWithBobSends
10701084 SipTransaction infoTransaction = bobPhone .sendRequestWithTransaction (info , false , dialog );
10711085 assertNotNull (infoTransaction );
10721086
1073- bobCall . listenForDisconnect ();
1087+
10741088 assertTrue (bobCall .waitForDisconnect (5000 ));
10751089 assertTrue (bobCall .respondToDisconnect ());
10761090
@@ -1537,7 +1551,6 @@ public synchronized void testDialNumberRejectBusyRcml() throws InterruptedExcept
15371551
15381552 private String hangupActionRcml = "<Response><Hangup /></Response>" ;
15391553
1540- @ Category (UnstableTests .class )
15411554 @ Test // (customised from testDialClientAliceWithRecordAndStatusCallbackForApp)
15421555 public synchronized void testDialClientAliceWithActionAndStatusCallbackForApp () throws InterruptedException , ParseException {
15431556 stubFor (get (urlPathEqualTo ("/1111" ))
0 commit comments