Skip to content

Commit

Permalink
Add-remove participant unit tests (#22025)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifsaikat-microsoft authored and chrwhit committed Jun 9, 2021
1 parent c447e4a commit 2990768
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.CreateCallResult;
import com.azure.communication.callingserver.models.EventSubscriptionType;
import com.azure.communication.callingserver.models.InviteParticipantsRequest;
import com.azure.communication.callingserver.models.PlayAudioResult;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
Expand All @@ -27,9 +28,10 @@
public class CallAsyncClientTests extends CallingServerTestBase {
private String from = "8:acs:016a7064-0581-40b9-be73-6dde64d69d72_0000000a-6198-4a66-02c3-593a0d00560d";
private String alternateId = "+18445764430";
private String to = "+15125189815";
private String to = "+15125189815";
private String callBackUri = "https://host.app/api/callback/calling";
private String audioFileUri = "https://acstestapp1.azurewebsites.net/audio/bot-callcenter-intro.wav";
private String audioFileUri = "https://host.app/audio/bot-callcenter-intro.wav";
private String invitedUser = "8:acs:016a7064-0581-40b9-be73-6dde64d69d72_0000000a-6d91-5555-b5bb-a43a0d00068c";;

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
Expand Down Expand Up @@ -114,7 +116,95 @@ public void runCreatePlayAudioHangupScenarioWithResponseAsync(HttpClient httpCli
System.out.println("Error: " + e.getMessage());
throw e;
}
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void inviteUserRemoveParticipantScenarioAsync(HttpClient httpClient) throws URISyntaxException, InterruptedException {
var builder = getCallClientUsingConnectionString(httpClient);
var callAsyncClient = setupAsyncClient(builder, "inviteUserRemoveParticipantScenarioAsync");

try {
// Establish a call
CreateCallOptions options = new CreateCallOptions(
callBackUri,
new LinkedList<CallModality>(Arrays.asList(CallModality.AUDIO)),
new LinkedList<EventSubscriptionType>(Arrays.asList(EventSubscriptionType.PARTICIPANTS_UPDATED)));

options.setAlternateCallerId(new PhoneNumberIdentifier(alternateId));

CreateCallResult createCallResult = callAsyncClient.createCall(
new CommunicationUserIdentifier(from),
new LinkedList<CommunicationIdentifier>(Arrays.asList(new PhoneNumberIdentifier(to))),
options).block();

CallingServerTestUtils.ValidateCreateCallResult(createCallResult);
var callId = createCallResult.getCallLegId();

// Invite User
var operationContext = "ac794123-3820-4979-8e2d-50c7d3e07b12";
InviteParticipantsRequest inviteParticipantsRequest = new InviteParticipantsRequest();
inviteParticipantsRequest.setParticipants(new LinkedList<CommunicationIdentifier>(Arrays.asList(new CommunicationUserIdentifier(invitedUser))));
inviteParticipantsRequest.setOperationContext(operationContext);
callAsyncClient.inviteParticipants(callId, inviteParticipantsRequest).block();

// Remove Participant
var participantId = "845156dc-15ad-4dec-883c-ee2e27cdb99e";
callAsyncClient.removeParticipant(callId, participantId).block();

// Hang up
callAsyncClient.hangupCall(callId).block();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
throw e;
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void inviteUserRemoveParticipantScenarioWithResponseAsync(HttpClient httpClient) throws URISyntaxException, InterruptedException {
var builder = getCallClientUsingConnectionString(httpClient);
var callAsyncClient = setupAsyncClient(builder, "inviteUserRemoveParticipantScenarioWithResponseAsync");

try {
// Establish a call
CreateCallOptions options = new CreateCallOptions(
callBackUri,
new LinkedList<CallModality>(Arrays.asList(CallModality.AUDIO)),
new LinkedList<EventSubscriptionType>(Arrays.asList(EventSubscriptionType.PARTICIPANTS_UPDATED)));

options.setAlternateCallerId(new PhoneNumberIdentifier(alternateId));

Response<CreateCallResult> createCallResponse = callAsyncClient.createCallWithResponse(
new CommunicationUserIdentifier(from),
new LinkedList<CommunicationIdentifier>(Arrays.asList(new PhoneNumberIdentifier(to))),
options,
Context.NONE).block();

CallingServerTestUtils.ValidateCreateCallResponse(createCallResponse);
var callId = createCallResponse.getValue().getCallLegId();

// Invite User
var operationContext = "ac794123-3820-4979-8e2d-50c7d3e07b12";
InviteParticipantsRequest inviteParticipantsRequest = new InviteParticipantsRequest();
inviteParticipantsRequest.setParticipants(new LinkedList<CommunicationIdentifier>(Arrays.asList(new CommunicationUserIdentifier(invitedUser))));
inviteParticipantsRequest.setOperationContext(operationContext);
Response<Void> inviteParticipantResponse = callAsyncClient.inviteParticipantsWithResponse(callId, inviteParticipantsRequest, Context.NONE).block();
CallingServerTestUtils.ValidateInviteParticipantResponse(inviteParticipantResponse);

// Remove Participant
var participantId = "8465d43d-3cf2-4e7f-96f6-e9824348c894";
Response<Void> removeParticipantResponse = callAsyncClient.removeParticipantWithResponse(callId, participantId, Context.NONE).block();
CallingServerTestUtils.ValidateRemoveParticipantResponse(removeParticipantResponse);

// Hang up
Response<Void> hangupResponse = callAsyncClient.hangupCallWithResponse(callId, Context.NONE).block();
CallingServerTestUtils.ValidateHangupResponse(hangupResponse);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
throw e;
}
}

private CallAsyncClient setupAsyncClient(CallClientBuilder builder, String testName) {
return addLoggingPolicy(builder, testName).buildAsyncClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.CreateCallResult;
import com.azure.communication.callingserver.models.EventSubscriptionType;
import com.azure.communication.callingserver.models.InviteParticipantsRequest;
import com.azure.communication.callingserver.models.PlayAudioResult;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
Expand All @@ -29,7 +30,8 @@ public class CallClientTests extends CallingServerTestBase {
private String alternateId = "+18445764430";
private String to = "+15125189815";
private String callBackUri = "https://host.app/api/callback/calling";
private String audioFileUri = "https://acstestapp1.azurewebsites.net/audio/bot-callcenter-intro.wav";
private String audioFileUri = "https://host.app/audio/bot-callcenter-intro.wav";
private String invitedUser = "8:acs:016a7064-0581-40b9-be73-6dde64d69d72_0000000a-6d91-5555-b5bb-a43a0d00068c";

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
Expand Down Expand Up @@ -114,7 +116,95 @@ public void runCreatePlayAudioHangupScenarioWithResponse(HttpClient httpClient)
System.out.println("Error: " + e.getMessage());
throw e;
}
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void inviteUserRemoveParticipantScenario(HttpClient httpClient) throws URISyntaxException, InterruptedException {
var builder = getCallClientUsingConnectionString(httpClient);
var callClient = setupClient(builder, "inviteUserRemoveParticipantScenario");

try {
// Establish a call
CreateCallOptions options = new CreateCallOptions(
callBackUri,
new LinkedList<CallModality>(Arrays.asList(CallModality.AUDIO)),
new LinkedList<EventSubscriptionType>(Arrays.asList(EventSubscriptionType.PARTICIPANTS_UPDATED)));

options.setAlternateCallerId(new PhoneNumberIdentifier(alternateId));

CreateCallResult createCallResult = callClient.createCall(
new CommunicationUserIdentifier(from),
new LinkedList<CommunicationIdentifier>(Arrays.asList(new PhoneNumberIdentifier(to))),
options);

CallingServerTestUtils.ValidateCreateCallResult(createCallResult);
var callId = createCallResult.getCallLegId();

// Invite User
var operationContext = "ac794123-3820-4979-8e2d-50c7d3e07b12";
InviteParticipantsRequest inviteParticipantsRequest = new InviteParticipantsRequest();
inviteParticipantsRequest.setParticipants(new LinkedList<CommunicationIdentifier>(Arrays.asList(new CommunicationUserIdentifier(invitedUser))));
inviteParticipantsRequest.setOperationContext(operationContext);
callClient.inviteParticipants(callId, inviteParticipantsRequest);

// Remove Participant
var participantId = "39659b2c-53a8-40a3-93d5-5da018967401";
callClient.removeParticipant(callId, participantId);

// Hang up
callClient.hangupCall(callId);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
throw e;
}
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void inviteUserRemoveParticipantScenarioWithResponse(HttpClient httpClient) throws URISyntaxException, InterruptedException {
var builder = getCallClientUsingConnectionString(httpClient);
var callClient = setupClient(builder, "inviteUserRemoveParticipantScenarioWithResponse");

try {
// Establish a call
CreateCallOptions options = new CreateCallOptions(
callBackUri,
new LinkedList<CallModality>(Arrays.asList(CallModality.AUDIO)),
new LinkedList<EventSubscriptionType>(Arrays.asList(EventSubscriptionType.PARTICIPANTS_UPDATED)));

options.setAlternateCallerId(new PhoneNumberIdentifier(alternateId));

Response<CreateCallResult> createCallResponse = callClient.createCallWithResponse(
new CommunicationUserIdentifier(from),
new LinkedList<CommunicationIdentifier>(Arrays.asList(new PhoneNumberIdentifier(to))),
options,
Context.NONE);

CallingServerTestUtils.ValidateCreateCallResponse(createCallResponse);
var callId = createCallResponse.getValue().getCallLegId();

// Invite User
var operationContext = "ac794123-3820-4979-8e2d-50c7d3e07b12";
InviteParticipantsRequest inviteParticipantsRequest = new InviteParticipantsRequest();
inviteParticipantsRequest.setParticipants(new LinkedList<CommunicationIdentifier>(Arrays.asList(new CommunicationUserIdentifier(invitedUser))));
inviteParticipantsRequest.setOperationContext(operationContext);
Response<Void> inviteParticipantResponse = callClient.inviteParticipantsWithResponse(callId, inviteParticipantsRequest, Context.NONE);
CallingServerTestUtils.ValidateInviteParticipantResponse(inviteParticipantResponse);

// Remove Participant
var participantId = "d702fa95-a3ee-4e2d-8101-8e100e7aaf8a";
Response<Void> removeParticipantResponse = callClient.removeParticipantWithResponse(callId, participantId, Context.NONE);
CallingServerTestUtils.ValidateRemoveParticipantResponse(removeParticipantResponse);

// Hang up
Response<Void> hangupResponse = callClient.hangupCallWithResponse(callId, Context.NONE);
CallingServerTestUtils.ValidateHangupResponse(hangupResponse);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
throw e;
}
}

private CallClient setupClient(CallClientBuilder builder, String testName) {
return addLoggingPolicy(builder, testName).buildClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ protected static void ValidateHangupResponse(Response<Void> hangupResponse)
assertNotNull(hangupResponse);
assertTrue(hangupResponse.getStatusCode() == 202);
}

protected static void ValidateInviteParticipantResponse(Response<Void> inviteParticipantResponse)
{
assertNotNull(inviteParticipantResponse);
assertTrue(inviteParticipantResponse.getStatusCode() == 202);
}

protected static void ValidateRemoveParticipantResponse(Response<Void> removeParticipantResponse)
{
assertNotNull(removeParticipantResponse);
assertTrue(removeParticipantResponse.getStatusCode() == 202);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://REDACTED.communication.azure.com/calling/calls?api-version=2021-04-15-preview1",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-callingserver/1.0.0-beta.1 (16.0.1; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"X-Cache" : "CONFIG_NOCACHE",
"content-length" : "52",
"retry-after" : "0",
"X-Azure-Ref" : "0oce3YAAAAABEMFt9C2aER4e2teZ85i2MQ0hHRURHRTE2MTIAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
"StatusCode" : "201",
"X-Microsoft-Skype-Chain-ID" : "bd3eb36e-6a3a-402c-bee2-f2b4af0562dd",
"Body" : "{\"callLegId\":\"b21f6a00-445f-4a23-8053-4c515c16d75f\"}",
"Date" : "Wed, 02 Jun 2021 18:02:09 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Client-Request-Id" : "36e9d9a6-0746-4af8-ad34-70358b635adb"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.communication.azure.com/calling/calls/b21f6a00-445f-4a23-8053-4c515c16d75f/participants?api-version=2021-04-15-preview1",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-callingserver/1.0.0-beta.1 (16.0.1; Windows 10; 10.0)",
"Content-Type" : "application/json"
},
"Response" : {
"X-Cache" : "CONFIG_NOCACHE",
"content-length" : "0",
"retry-after" : "0",
"X-Azure-Ref" : "0rse3YAAAAAAqsNRcd4WsSrw8rhzeEScDQ0hHRURHRTE2MTIAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
"StatusCode" : "202",
"X-Microsoft-Skype-Chain-ID" : "38b0581e-10ef-467f-ad7a-364e76bee477",
"Date" : "Wed, 02 Jun 2021 18:02:22 GMT",
"Client-Request-Id" : "b59edbe3-bf5e-4de7-97f5-fc486fa3b350"
},
"Exception" : null
}, {
"Method" : "DELETE",
"Uri" : "https://REDACTED.communication.azure.com/calling/calls/b21f6a00-445f-4a23-8053-4c515c16d75f/participants/845156dc-15ad-4dec-883c-ee2e27cdb99e?api-version=2021-04-15-preview1",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-callingserver/1.0.0-beta.1 (16.0.1; Windows 10; 10.0)"
},
"Response" : {
"X-Cache" : "CONFIG_NOCACHE",
"content-length" : "0",
"retry-after" : "0",
"X-Azure-Ref" : "00se3YAAAAAD6nVAM2InIQITLaA0PKmKmQ0hHRURHRTE2MTIAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
"StatusCode" : "202",
"X-Microsoft-Skype-Chain-ID" : "e62f5d57-2add-405c-8b56-79e8af31e221",
"Date" : "Wed, 02 Jun 2021 18:02:58 GMT",
"Client-Request-Id" : "73dd593d-ba48-4793-8809-1e753a4b67d3"
},
"Exception" : null
}, {
"Method" : "POST",
"Uri" : "https://REDACTED.communication.azure.com/calling/calls/b21f6a00-445f-4a23-8053-4c515c16d75f/Hangup?api-version=2021-04-15-preview1",
"Headers" : {
"User-Agent" : "azsdk-java-azure-communication-callingserver/1.0.0-beta.1 (16.0.1; Windows 10; 10.0)"
},
"Response" : {
"X-Cache" : "CONFIG_NOCACHE",
"content-length" : "0",
"retry-after" : "0",
"X-Azure-Ref" : "038e3YAAAAAB8rc6neSGjRbr5zrr6QK41Q0hHRURHRTE2MTIAOWZjN2I1MTktYThjYy00Zjg5LTkzNWUtYzkxNDhhZTA5ZTgx",
"StatusCode" : "202",
"X-Microsoft-Skype-Chain-ID" : "dca66ff8-1e41-4cef-a5f9-5a9dbd6d4481",
"Date" : "Wed, 02 Jun 2021 18:03:11 GMT",
"Client-Request-Id" : "aff6cbbd-492f-4bdc-b3ba-357d28ac7dfa"
},
"Exception" : null
} ],
"variables" : [ ]
}
Loading

0 comments on commit 2990768

Please sign in to comment.