Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests to improve coverage and fix LiveTests #22435

Merged
merged 27 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ee56ac2
event related unit test to improve test coverage
arifsaikat-microsoft Jun 22, 2021
287bd85
fix(unit-test): add unit tests to improve code coverage
chrwhit Jun 22, 2021
7893b13
event related unit test
arifsaikat-microsoft Jun 22, 2021
924420f
Merge branch 'arifsaikat/feature-communication-calling-livetest' of h…
arifsaikat-microsoft Jun 22, 2021
4dcec1d
fix(unit-tests): remove var declarators
chrwhit Jun 22, 2021
9d38e7a
event related unit test
arifsaikat-microsoft Jun 22, 2021
bd7a500
event related unit test
arifsaikat-microsoft Jun 22, 2021
ef9be85
Merge branch 'arifsaikat/feature-communication-calling-livetest' of h…
arifsaikat-microsoft Jun 22, 2021
dff0ed5
fix(unit-tests): fix issue with List.to, increase coverage
chrwhit Jun 22, 2021
0250e40
fix(unit-tests): remove var declarations
chrwhit Jun 22, 2021
82ac2d7
fix(unit-tests): fix issue with infered generic in annonymous type
chrwhit Jun 22, 2021
3a0795a
fix(test-config): attempt to remove int
chrwhit Jun 22, 2021
04c84d9
fix(test-config): override communication test template to remove int
chrwhit Jun 22, 2021
21fe246
fix(test-config): override communication test template to remove int
chrwhit Jun 22, 2021
80c593c
fix(test-config): override communication test template to remove int
chrwhit Jun 22, 2021
1135083
fix(unit-tests): update random generation of groupIds
chrwhit Jun 22, 2021
b98886c
added newline at end of config file
arifsaikat-microsoft Jun 22, 2021
4902195
fix(tests): update test.yml to be parameterized, force live mode
chrwhit Jun 22, 2021
58e6e58
Merge branch 'arifsaikat/feature-communication-calling-livetest' of h…
chrwhit Jun 22, 2021
375df59
fix(unit-tests): update random generation of groupIds
chrwhit Jun 22, 2021
6d8feb8
Revert "fix(unit-tests): update yml files"
chrwhit Jun 22, 2021
96c3cc7
fix(tests): fix yaml
chrwhit Jun 22, 2021
1fb208d
fix(tests): fix yaml
chrwhit Jun 22, 2021
80a0f5a
fix(unit-tests): update random generation of groupIds
chrwhit Jun 22, 2021
9127cdf
fix(tests): fix yaml
chrwhit Jun 22, 2021
41733d6
fix(tests): more yml
chrwhit Jun 22, 2021
7dae968
fix(tests): fix yaml
chrwhit Jun 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,30 +162,6 @@ public Mono<Response<PlayAudioResult>> playAudioWithResponse(
return playAudioWithResponseInternal(audioFileUri, playAudioOptions, null);
}

Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
arifsaikat-microsoft marked this conversation as resolved.
Show resolved Hide resolved
String audioFileUri,
boolean loop,
String audioFileId,
String callbackUri,
String operationContext,
Context context) {
try {
Objects.requireNonNull(audioFileUri, "'audioFileUri' cannot be null.");
PlayAudioRequest playAudioRequest =
new PlayAudioRequest()
.setAudioFileUri(audioFileUri)
.setLoop(loop)
.setAudioFileId(audioFileId)
.setOperationContext(operationContext)
.setCallbackUri(callbackUri);
return playAudioWithResponseInternal(playAudioRequest, context);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}


}

Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
String audioFileUri,
PlayAudioOptions playAudioOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,31 +543,6 @@ public Mono<Response<PlayAudioResult>> playAudioWithResponse(
return playAudioWithResponseInternal(audioFileUri, playAudioOptions, null);
}

Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
String audioFileUri,
String audioFileId,
String callbackUri,
String operationContext,
Context context) {
try {
Objects.requireNonNull(audioFileUri, "'audioFileUri' cannot be null.");

//Currently we do not support loop on the audio media for out-call, thus setting the loop to false
PlayAudioRequest playAudioRequest =
new PlayAudioRequest()
.setAudioFileUri(audioFileUri)
.setLoop(false)
.setAudioFileId(audioFileId)
.setOperationContext(operationContext)
.setCallbackUri(callbackUri);
return playAudioWithResponse(playAudioRequest, context);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}


}

Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
String audioFileUri,
PlayAudioOptions playAudioOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callingserver;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.AbstractMap.SimpleEntry;

import com.azure.communication.callingserver.implementation.models.ResultInfoInternal;
import com.azure.communication.callingserver.models.AddParticipantResult;
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.EventSubscriptionType;
import com.azure.communication.callingserver.models.JoinCallOptions;
import com.azure.communication.callingserver.models.MediaType;
import com.azure.communication.callingserver.models.OperationStatus;
import com.azure.communication.callingserver.models.PlayAudioOptions;
import com.azure.communication.callingserver.models.PlayAudioResult;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;

import org.junit.jupiter.api.Test;

public class CallConnectionAsyncUnitTests {

static final String CALL_CONNECTION_ID = "callConnectionId";
static final String OPERATION_ID = "operationId";
static final String NEW_PARTICIPANT_ID = "newParticipantId";

@Test
public void createConnectionWithResponse() {
CallingServerAsyncClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CallingServerResponseMocker.CALL_CONNECTION_ID), 201)
)));

CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id");
List<CommunicationIdentifier> targetUsers = new ArrayList<CommunicationIdentifier>();
targetUsers.add(new CommunicationUserIdentifier("id2"));

CreateCallOptions options = new CreateCallOptions(
"serverCallId",
Collections.singletonList(MediaType.AUDIO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));

Response<CallConnectionAsync> callConnectionAsyncResponse = callingServerAsyncClient.createCallConnectionWithResponse(sourceUser, targetUsers, options).block();
assertEquals(201, callConnectionAsyncResponse.getStatusCode());
assertNotNull(callConnectionAsyncResponse.getValue());
}

@Test
public void getCallConnectionCallingServerAsyncClient() {
CallingServerAsyncClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList()));

CallConnectionAsync callConnection = callingServerAsyncClient.getCallConnection(CallingServerResponseMocker.CALL_CONNECTION_ID);
assertNotNull(callConnection);
}

@Test
public void playAudioWithResponse() {
CallConnectionAsync callConnectionAsync = getPlayAudioCallConnection();

PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri");
Response<PlayAudioResult> playAudioResultResponse = callConnectionAsync.playAudioWithResponse("audioFileUri", playAudioOptions).block();
assertEquals(202, playAudioResultResponse.getStatusCode());
}

@Test
public void playAudio() {
CallConnectionAsync callConnectionAsync = getPlayAudioCallConnection();

PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri");
PlayAudioResult playAudioResult = callConnectionAsync.playAudio("audioFileUri", playAudioOptions).block();
assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus());
}

@Test
public void playAudioWithoutPlayAudioOptions202() {
CallConnectionAsync callConnectionAsync = getPlayAudioCallConnection();

PlayAudioResult playAudioResult = callConnectionAsync.playAudio("audioFileUri", false, "audioFieldId", "callbackUri", "operationContext").block();
assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus());
}

@Test
public void appParticipantWithResponse() {
CallConnectionAsync callConnectionAsync = getAddParticipantCallConnection();

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
Response<AddParticipantResult> addParticipantResultResponse = callConnectionAsync.addParticipantWithResponse(user, "alternateCallerId", "operationContext", Context.NONE).block();
assertEquals(202, addParticipantResultResponse.getStatusCode());
AddParticipantResult addParticipantResult = addParticipantResultResponse.getValue();
assertEquals(user.getId(), addParticipantResult.getParticipantId());
}

@Test
public void appParticipant() {
CallConnectionAsync callConnectionAsync = getAddParticipantCallConnection();

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
AddParticipantResult addParticipantResult = callConnectionAsync.addParticipant(user, "alternateCallerId", "operationContext").block();
assertEquals(user.getId(), addParticipantResult.getParticipantId());
}

@Test
public void joinCallWithResponse() {
CallingServerAsyncClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202)
)));

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
JoinCallOptions options = new JoinCallOptions(
CallingServerResponseMocker.URI_CALLBACK,
Collections.singletonList(MediaType.VIDEO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));
Response<CallConnectionAsync> callConnectionAsyncResponse = callingServerAsyncClient.joinCallWithResponse(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options).block();
assertEquals(202, callConnectionAsyncResponse.getStatusCode());
assertNotNull(callConnectionAsyncResponse.getValue());
}

@Test
public void joinCall() {
CallingServerAsyncClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202)
)));

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
JoinCallOptions options = new JoinCallOptions(
CallingServerResponseMocker.URI_CALLBACK,
Collections.singletonList(MediaType.VIDEO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));
CallConnectionAsync callConnectionAsync = callingServerAsyncClient.joinCall(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options).block();
assertNotNull(callConnectionAsync);
}

private CallConnectionAsync getPlayAudioCallConnection() {
return CallingServerResponseMocker.getCallConnectionAsync(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201),
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generatePlayAudioResult(
OPERATION_ID,
OperationStatus.COMPLETED,
new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")),
202)
)));
}

private CallConnectionAsync getAddParticipantCallConnection() {
return CallingServerResponseMocker.getCallConnectionAsync(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201),
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateAddParticipantResult(NEW_PARTICIPANT_ID), 202)
)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callingserver;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.AbstractMap.SimpleEntry;

import com.azure.communication.callingserver.implementation.models.ResultInfoInternal;
import com.azure.communication.callingserver.models.AddParticipantResult;
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.EventSubscriptionType;
import com.azure.communication.callingserver.models.JoinCallOptions;
import com.azure.communication.callingserver.models.MediaType;
import com.azure.communication.callingserver.models.OperationStatus;
import com.azure.communication.callingserver.models.PlayAudioOptions;
import com.azure.communication.callingserver.models.PlayAudioResult;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;

import org.junit.jupiter.api.Test;

public class CallConnectionUnitTests {

static final String CALL_CONNECTION_ID = "callConnectionId";
static final String OPERATION_ID = "operationId";
static final String NEW_PARTICIPANT_ID = "newParticipantId";

@Test
public void createConnectionWithResponse() {
CallingServerClient callingServerClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CallingServerResponseMocker.CALL_CONNECTION_ID), 201)
)));

CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id");
List<CommunicationIdentifier> targetUsers = new ArrayList<CommunicationIdentifier>();
targetUsers.add(new CommunicationUserIdentifier("id2"));

CreateCallOptions options = new CreateCallOptions(
"serverCallId",
Collections.singletonList(MediaType.AUDIO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));

Response<CallConnection> callConnectionAsyncResponse = callingServerClient.createCallConnectionWithResponse(sourceUser, targetUsers, options, Context.NONE);
assertEquals(201, callConnectionAsyncResponse.getStatusCode());
assertNotNull(callConnectionAsyncResponse.getValue());
}

@Test
public void getCallConnectionCallingServerClient() {
CallingServerClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList()));

CallConnection callConnection = callingServerAsyncClient.getCallConnection(CallingServerResponseMocker.CALL_CONNECTION_ID);
assertNotNull(callConnection);
}

@Test
public void playAudioWithResponse() {
CallConnection callConnection = getCallConnection();

PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri");
Response<PlayAudioResult> playAudioResultResponse = callConnection.playAudioWithResponse("audioFileUri", playAudioOptions, Context.NONE);
assertEquals(202, playAudioResultResponse.getStatusCode());
PlayAudioResult playAudioResult = playAudioResultResponse.getValue();
assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus());
}

@Test
public void playAudio() {
CallConnection callConnection = getCallConnection();

PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri");
PlayAudioResult playAudioResult = callConnection.playAudio("audioFileUri", playAudioOptions);
assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus());
}

@Test
public void playAudioWithoutPlayAudioOptions() {
CallConnection callConnection = getCallConnection();

PlayAudioResult playAudioResult = callConnection.playAudio("audioFileUri", false, "audioFieldId", "callbackUri", "operationContext");
assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus());
}

@Test
public void appParticipantWithResponse() {
CallConnection callConnection = getAddParticipantCallConnection();

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
Response<AddParticipantResult> addParticipantResultResponse = callConnection.addParticipantWithResponse(user, "alternateCallerId", "operationContext", Context.NONE);
assertEquals(202, addParticipantResultResponse.getStatusCode());
AddParticipantResult addParticipantResult = addParticipantResultResponse.getValue();
assertEquals(user.getId(), addParticipantResult.getParticipantId());
}

@Test
public void appParticipant() {
CallConnection callConnection = getAddParticipantCallConnection();

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
AddParticipantResult addParticipantResult = callConnection.addParticipant(user, "alternateCallerId", "operationContext");
assertEquals(user.getId(), addParticipantResult.getParticipantId());
}

@Test
public void joinCall() {
CallingServerClient callingServerClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202)
)));

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
JoinCallOptions options = new JoinCallOptions(
CallingServerResponseMocker.URI_CALLBACK,
Collections.singletonList(MediaType.VIDEO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));
CallConnection callConnection = callingServerClient.joinCall(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options);
assertNotNull(callConnection);
}

@Test
public void joinCallWithResponse() {
CallingServerClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202)
)));

CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID);
JoinCallOptions options = new JoinCallOptions(
CallingServerResponseMocker.URI_CALLBACK,
Collections.singletonList(MediaType.VIDEO),
Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED));
Response<CallConnection> callConnectionResponse = callingServerAsyncClient.joinCallWithResponse(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options, Context.NONE);
assertEquals(202, callConnectionResponse.getStatusCode());
assertNotNull(callConnectionResponse.getValue());
}

private CallConnection getCallConnection() {
return CallingServerResponseMocker.getCallConnection(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201),
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generatePlayAudioResult(
OPERATION_ID,
OperationStatus.COMPLETED,
new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")),
202)
)));
}

private CallConnection getAddParticipantCallConnection() {
return CallingServerResponseMocker.getCallConnection(new ArrayList<SimpleEntry<String, Integer>>(
Arrays.asList(
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201),
new SimpleEntry<String, Integer>(CallingServerResponseMocker.generateAddParticipantResult(NEW_PARTICIPANT_ID), 202)
)));
}
}
Loading