-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More tests to improve coverage and fix LiveTests (#22435)
* event related unit test to improve test coverage * fix(unit-test): add unit tests to improve code coverage * event related unit test * fix(unit-tests): remove var declarators * event related unit test * event related unit test * fix(unit-tests): fix issue with List.to, increase coverage * fix(unit-tests): remove var declarations * fix(unit-tests): fix issue with infered generic in annonymous type * fix(test-config): attempt to remove int * fix(test-config): override communication test template to remove int * fix(test-config): override communication test template to remove int * fix(test-config): override communication test template to remove int * fix(unit-tests): update random generation of groupIds * added newline at end of config file * fix(tests): update test.yml to be parameterized, force live mode * fix(unit-tests): update random generation of groupIds * Revert "fix(unit-tests): update yml files" This reverts commit 375df59. * fix(tests): fix yaml * fix(tests): fix yaml * fix(unit-tests): update random generation of groupIds * fix(tests): fix yaml * fix(tests): more yml * fix(tests): fix yaml Co-authored-by: Christian Whitehead <chrwhit@microsoft.com>
- Loading branch information
1 parent
6249e9a
commit 34dacc4
Showing
13 changed files
with
1,139 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...ver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
))); | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
...ngserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
))); | ||
} | ||
} |
Oops, something went wrong.