From ee56ac2cec8a9d71f585ced146d11db05a573de4 Mon Sep 17 00:00:00 2001 From: Arif Saikat <71465659+arifsaikat-microsoft@users.noreply.github.com> Date: Mon, 21 Jun 2021 19:02:11 -0700 Subject: [PATCH 01/24] event related unit test to improve test coverage --- .../callingserver/EventTests.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java new file mode 100644 index 0000000000000..9f779908df71a --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.communication.callingserver; + +import com.azure.communication.callingserver.implementation.models.CallConnectionStateChangedEventInternal; +import com.azure.communication.callingserver.models.CallConnectionState; +import com.azure.communication.callingserver.models.events.CallConnectionStateChangedEvent; +import com.azure.core.util.BinaryData; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class EventTests { + @Test + public void callConnectionStateChangedEventTest() throws JsonProcessingException { + var serverCallId = UUID.randomUUID().toString(); + var callConnectionId = UUID.randomUUID().toString(); + CallConnectionStateChangedEventInternal internalEvent = + new CallConnectionStateChangedEventInternal() + .setCallConnectionId(callConnectionId) + .setServerCallId(serverCallId) + .setCallConnectionState(CallConnectionState.CONNECTED); + + ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonData = objectWriter.writeValueAsString(internalEvent); + BinaryData binaryData = BinaryData.fromString(jsonData); + + CallConnectionStateChangedEvent event = CallConnectionStateChangedEvent.deserialize(binaryData); + + assertNotNull(event); + assertEquals(event.getCallConnectionId(), callConnectionId); + assertEquals(event.getServerCallId(), serverCallId); + assertEquals(event.getCallConnectionState(), CallConnectionState.CONNECTED); + } +} From 287bd855103069c167e4a8ee60edba96b977e276 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Mon, 21 Jun 2021 19:31:12 -0700 Subject: [PATCH 02/24] fix(unit-test): add unit tests to improve code coverage --- .../callingserver/CallConnectionAsync.java | 24 --- .../callingserver/ServerCallAsync.java | 25 --- .../CallConnectionAsyncUnitTests.java | 159 +++++++++++++++ .../CallConnectionUnitTests.java | 161 +++++++++++++++ .../CallingServerResponseMocker.java | 183 ++++++++++++++++++ .../DownloadContentAsyncUnitTests.java | 87 +++++++++ .../DownloadContentUnitTests.java | 54 ++++++ .../callingserver/MockHttpClient.java | 41 ++++ .../callingserver/ServerCallUnitTests.java | 183 ++++++++++++++++++ 9 files changed, 868 insertions(+), 49 deletions(-) create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerResponseMocker.java create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentUnitTests.java create mode 100644 sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallConnectionAsync.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallConnectionAsync.java index 5638660cf0df6..c42c73288d227 100644 --- a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallConnectionAsync.java +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallConnectionAsync.java @@ -162,30 +162,6 @@ public Mono> playAudioWithResponse( return playAudioWithResponseInternal(audioFileUri, playAudioOptions, null); } - Mono> playAudioWithResponseInternal( - 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> playAudioWithResponseInternal( String audioFileUri, PlayAudioOptions playAudioOptions, diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ServerCallAsync.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ServerCallAsync.java index d28cdafea76b7..b32b8d5d86e75 100644 --- a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ServerCallAsync.java +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ServerCallAsync.java @@ -543,31 +543,6 @@ public Mono> playAudioWithResponse( return playAudioWithResponseInternal(audioFileUri, playAudioOptions, null); } - Mono> 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> playAudioWithResponseInternal( String audioFileUri, PlayAudioOptions playAudioOptions, diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java new file mode 100644 index 0000000000000..b32d30a278922 --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java @@ -0,0 +1,159 @@ +// 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CallingServerResponseMocker.CALL_CONNECTION_ID), 201) + ))); + + CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id"); + List targetUsers = new ArrayList(); + targetUsers.add(new CommunicationUserIdentifier("id2")); + + CreateCallOptions options = new CreateCallOptions( + "serverCallId", + Collections.singletonList(MediaType.AUDIO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); + + Response callConnectionAsyncResponse = callingServerAsyncClient.createCallConnectionWithResponse(sourceUser, targetUsers, options).block(); + assertEquals(201, callConnectionAsyncResponse.getStatusCode()); + assertNotNull(callConnectionAsyncResponse.getValue()); + } + + @Test + public void getCallConnectionCallingServerAsyncClient() { + CallingServerAsyncClient callingServerAsyncClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList>( + 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 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 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202) + ))); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); + JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + Response 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202) + ))); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); + JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201), + new SimpleEntry(CallingServerResponseMocker.generatePlayAudioResult( + OPERATION_ID, + OperationStatus.COMPLETED, + new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")), + 202) + ))); + } + + private CallConnectionAsync getAddParticipantCallConnection() { + return CallingServerResponseMocker.getCallConnectionAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201), + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(NEW_PARTICIPANT_ID), 202) + ))); + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java new file mode 100644 index 0000000000000..d4450eeac872f --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java @@ -0,0 +1,161 @@ +// 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CallingServerResponseMocker.CALL_CONNECTION_ID), 201) + ))); + + CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id"); + List targetUsers = new ArrayList(); + targetUsers.add(new CommunicationUserIdentifier("id2")); + + CreateCallOptions options = new CreateCallOptions( + "serverCallId", + Collections.singletonList(MediaType.AUDIO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); + + Response 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>( + 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 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 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202) + ))); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); + JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateJoinCallResult(NEW_PARTICIPANT_ID), 202) + ))); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); + JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + Response 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>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201), + new SimpleEntry(CallingServerResponseMocker.generatePlayAudioResult( + OPERATION_ID, + OperationStatus.COMPLETED, + new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")), + 202) + ))); + } + + private CallConnection getAddParticipantCallConnection() { + return CallingServerResponseMocker.getCallConnection(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateCreateCallResult(CALL_CONNECTION_ID), 201), + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(NEW_PARTICIPANT_ID), 202) + ))); + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerResponseMocker.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerResponseMocker.java new file mode 100644 index 0000000000000..87f033c38c646 --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerResponseMocker.java @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.communication.callingserver; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.AbstractMap.SimpleEntry; + +import com.azure.communication.callingserver.implementation.models.AddParticipantResultInternal; +import com.azure.communication.callingserver.implementation.models.CreateCallResultInternal; +import com.azure.communication.callingserver.implementation.models.JoinCallResultInternal; +import com.azure.communication.callingserver.implementation.models.PlayAudioResultInternal; +import com.azure.communication.callingserver.implementation.models.ResultInfoInternal; +import com.azure.communication.callingserver.models.CreateCallOptions; +import com.azure.communication.callingserver.models.EventSubscriptionType; +import com.azure.communication.callingserver.models.MediaType; +import com.azure.communication.callingserver.models.OperationStatus; +import com.azure.communication.common.CommunicationIdentifier; +import com.azure.communication.common.CommunicationUserIdentifier; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class CallingServerResponseMocker { + public static final String CALL_CONNECTION_ID = "callConnectionId"; + public static final String OPERATION_ID = "operationId"; + public static final String MOCK_CONNECTION_STRING = "endpoint=https://REDACTED.communication.azure.com/;accesskey=eyJhbG"; + public static final String NEW_PARTICIPANT_ID = "newParticipantId"; + public static final String URI_CALLBACK = "https://uri.com"; + public static final String SERVER_CALL_ID = "serverCallId"; + + public static String generateCreateCallResult(String callConnectionId) { + + CreateCallResultInternal result = new CreateCallResultInternal() + .setCallConnectionId(callConnectionId); + + return serializeObject(result); + } + + public static String generateAddParticipantResult(String participantId) { + + AddParticipantResultInternal result = new AddParticipantResultInternal() + .setParticipantId(participantId); + + return serializeObject(result); + } + + public static String generateDownloadResult(String content) { + return content; + } + + public static String generatePlayAudioResult(String operationId, OperationStatus status, ResultInfoInternal resultInfo) { + + PlayAudioResultInternal result = new PlayAudioResultInternal() + .setOperationContext("operationContext") + .setOperationId(operationId) + .setStatus(status) + .setResultInfo(resultInfo); + + return serializeObject(result); + } + + public static String generateJoinCallResult(String callConnectionId) { + JoinCallResultInternal result = new JoinCallResultInternal() + .setCallConnectionId(callConnectionId); + + return serializeObject(result); + } + + public static CallConnectionAsync getCallConnectionAsync(ArrayList> responses) { + CallingServerAsyncClient callingServerAsyncClient = getCallingServerAsyncClient(responses); + + CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id"); + List targetUsers = new ArrayList(); + CreateCallOptions options = new CreateCallOptions( + "serverCallId", + Collections.singletonList(MediaType.AUDIO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); + + return callingServerAsyncClient.createCallConnection(sourceUser, targetUsers, options).block(); + } + + public static CallConnection getCallConnection(ArrayList> responses) { + CallingServerClient callingServerClient = getCallingServerClient(responses); + + CommunicationUserIdentifier sourceUser = new CommunicationUserIdentifier("id"); + List targetUsers = new ArrayList(); + CreateCallOptions options = new CreateCallOptions( + "serverCallId", + Collections.singletonList(MediaType.AUDIO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); + + return callingServerClient.createCallConnection(sourceUser, targetUsers, options); + } + + public static ServerCallAsync getServerCallAsync(ArrayList> responses) { + CallingServerAsyncClient callingServerClient = getCallingServerAsyncClient(responses); + return callingServerClient.initializeServerCall("serverCallId"); + } + + public static ServerCall getServerCall(ArrayList> responses) { + CallingServerClient callingServerClient = getCallingServerClient(responses); + return callingServerClient.initializeServerCall("serverCallId"); + } + + public static CallingServerAsyncClient getCallingServerAsyncClient(ArrayList> responses) { + HttpClient mockHttpClient = new MockHttpClient(responses); + + return new CallingServerClientBuilder() + .httpClient(mockHttpClient) + .connectionString(MOCK_CONNECTION_STRING) + .buildAsyncClient(); + } + + public static CallingServerClient getCallingServerClient(ArrayList> responses) { + HttpClient mockHttpClient = new MockHttpClient(responses); + + return new CallingServerClientBuilder() + .httpClient(mockHttpClient) + .connectionString(MOCK_CONNECTION_STRING) + .buildClient(); + } + + public static HttpResponse generateMockResponse(String body, HttpRequest request, int statusCode) { + return new HttpResponse(request) { + @Override + public int getStatusCode() { + return statusCode; + } + + @Override + public String getHeaderValue(String name) { + return null; + } + + @Override + public HttpHeaders getHeaders() { + return new HttpHeaders(); + } + + @Override + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8))); + } + + @Override + public Mono getBodyAsByteArray() { + return Mono.just(body.getBytes(StandardCharsets.UTF_8)); + } + + @Override + public Mono getBodyAsString() { + return Mono.just(body); + } + + @Override + public Mono getBodyAsString(Charset charset) { + return Mono.just(body); + } + }; + } + + private static String serializeObject(Object o) { + ObjectMapper mapper = new ObjectMapper(); + String body = null; + try { + body = mapper.writeValueAsString(o); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return body; + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java new file mode 100644 index 0000000000000..6e364d4f2d01d --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java @@ -0,0 +1,87 @@ +// 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.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.UUID; +import java.util.AbstractMap.SimpleEntry; + +import com.azure.communication.callingserver.models.ParallelDownloadOptions; +import com.azure.core.http.HttpRange; +import com.azure.core.http.rest.Response; + +import org.junit.jupiter.api.Test; + +import reactor.core.publisher.Flux; + +public class DownloadContentAsyncUnitTests { + @Test + public void downloadStream() throws IOException { + String contents = "VideoContents"; + CallingServerAsyncClient callingServerClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateDownloadResult(contents), 200) + ))); + + Flux fluxByteBuffer = callingServerClient.downloadStream("https://url.com", new HttpRange(contents.length())); + + var resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); + assertEquals("VideoContents", resultContents); + } + + @Test + public void downloadStreamWithResponse() throws IOException { + String contents = "VideoContents"; + CallingServerAsyncClient callingServerClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateDownloadResult(contents), 200) + ))); + + Response> fluxByteBufferResponse = callingServerClient.downloadStreamWithResponse("https://url.com", new HttpRange(contents.length())).block(); + assertEquals(200, fluxByteBufferResponse.getStatusCode()); + Flux fluxByteBuffer = fluxByteBufferResponse.getValue(); + var resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); + assertEquals("VideoContents", resultContents); + } + + @Test + public void downloadToWithResponse() throws IOException { + String contents = "VideoContents"; + CallingServerAsyncClient callingServerClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateDownloadResult(contents), 200) + ))); + String fileName = "./" + UUID.randomUUID().toString().replace("-", "") + ".txt"; + Path path = FileSystems.getDefault().getPath(fileName); + ParallelDownloadOptions options = new ParallelDownloadOptions().setMaxConcurrency(1).setBlockSize(512L); + File file = null; + + try { + Response response = callingServerClient.downloadToWithResponse("https://url.com", path, options, true).block(); + assertEquals(200, response.getStatusCode()); + + file = path.toFile(); + assertTrue(file.exists(), "file does not exist"); + BufferedReader br = new BufferedReader(new FileReader(file)); + assertEquals("VideoContents", br.readLine()); + br.close(); + } finally { + if (file != null && file.exists()) { + file.delete(); + } + } + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentUnitTests.java new file mode 100644 index 0000000000000..8297c614637af --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentUnitTests.java @@ -0,0 +1,54 @@ +// 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 java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.AbstractMap.SimpleEntry; + +import com.azure.core.http.HttpRange; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +import org.junit.jupiter.api.Test; + +public class DownloadContentUnitTests { + @Test + public void downloadTo() throws IOException { + CallingServerClient callingServerClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateDownloadResult("VideoContents"), 200) + ))); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + callingServerClient.downloadTo("https://url.com", stream, new HttpRange(1)); + Reader reader = new InputStreamReader(new ByteArrayInputStream(stream.toByteArray())); + BufferedReader b = new BufferedReader(reader); + assertEquals("VideoContents", b.readLine()); + } + + @Test + public void downloadToWithResponse() throws IOException { + CallingServerClient callingServerClient = CallingServerResponseMocker.getCallingServerClient(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateDownloadResult("VideoContents"), 200) + ))); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + Response response = callingServerClient.downloadToWithResponse("https://url.com", stream, new HttpRange(1), Context.NONE); + assertEquals(200, response.getStatusCode()); + Reader reader = new InputStreamReader(new ByteArrayInputStream(stream.toByteArray())); + BufferedReader b = new BufferedReader(reader); + assertEquals("VideoContents", b.readLine()); + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java new file mode 100644 index 0000000000000..d7df37b7ee4db --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.communication.callingserver; + +import java.util.ArrayList; +import java.util.List; +import java.util.AbstractMap.SimpleEntry; + +import com.azure.communication.callingserver.CallingServerClientBuilderUnitTests.NoOpHttpClient; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; + +import reactor.core.publisher.Mono; + +public class MockHttpClient extends NoOpHttpClient { + private ArrayList> responses = new ArrayList>(); + private ArrayList requests = new ArrayList(); + + public MockHttpClient(ArrayList> responses) { + this.responses = responses; + } + + public List getRequests() { + return requests; + } + + @Override + public Mono send(HttpRequest request) { + requests.add(request); + + if (responses.size() > 0) { + SimpleEntry entry = responses.get(0); + responses.remove(entry); + + return Mono.just(CallingServerResponseMocker.generateMockResponse(entry.getKey(), request, entry.getValue())); + } + + return Mono.just(CallingServerResponseMocker.generateMockResponse("", request, 500)); + } +} diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/ServerCallUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/ServerCallUnitTests.java index e79c9e38217b1..8bd48492fcf4e 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/ServerCallUnitTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/ServerCallUnitTests.java @@ -3,9 +3,23 @@ package com.azure.communication.callingserver; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.Arrays; +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.OperationStatus; +import com.azure.communication.callingserver.models.PlayAudioOptions; +import com.azure.communication.callingserver.models.PlayAudioResult; +import com.azure.communication.common.CommunicationUserIdentifier; +import com.azure.core.http.rest.Response; import com.azure.core.test.http.NoOpHttpClient; +import com.azure.core.util.Context; + import org.junit.jupiter.api.Test; public class ServerCallUnitTests { @@ -65,4 +79,173 @@ public void startRecordingAsyncFails() { () -> serverCall.startRecording("/not/absolute/uri") .block()); } + + @Test + public void playAudioWithResponse() { + ServerCall serverCall = getServerCall(); + PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri"); + Response playAudioResultResponse = serverCall.playAudioWithResponse("audioFileUri", playAudioOptions, Context.NONE); + assertEquals(202, playAudioResultResponse.getStatusCode()); + PlayAudioResult playAudioResult = playAudioResultResponse.getValue(); + assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus()); + } + + @Test + public void playAudio() { + ServerCall serverCall = getServerCall(); + + PlayAudioResult playAudioResult = serverCall.playAudio("audioFileUri", "audioFieldId", "callbackUri", "operationContext"); + assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus()); + } + + @Test + public void playAudioWithResponseAsync() { + ServerCallAsync serverCall = getServerCallAsync(); + PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri"); + Response playAudioResultResponse = serverCall.playAudioWithResponse("audioFileUri", playAudioOptions).block(); + assertEquals(202, playAudioResultResponse.getStatusCode()); + PlayAudioResult playAudioResult = playAudioResultResponse.getValue(); + assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus()); + } + + @Test + public void playAudioAsync() { + ServerCallAsync serverCall = getServerCallAsync(); + + PlayAudioResult playAudioResult = serverCall.playAudio("audioFileUri", "audioFieldId", "callbackUri", "operationContext").block(); + assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus()); + } + + @Test + public void playAudioAsyncUsingOptions() { + ServerCallAsync serverCall = getServerCallAsync(); + + PlayAudioOptions playAudioOptions = new PlayAudioOptions().setAudioFileId("audioFileId").setCallbackUri("callbackUri"); + PlayAudioResult playAudioResult = serverCall.playAudio("audioFileUri", playAudioOptions).block(); + assertEquals(OperationStatus.COMPLETED, playAudioResult.getStatus()); + } + + @Test + public void appParticipantServerCall() { + ServerCall serverCall = CallingServerResponseMocker.getServerCall(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(CallingServerResponseMocker.NEW_PARTICIPANT_ID), 202) + )) + ); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(CallingServerResponseMocker.NEW_PARTICIPANT_ID); + AddParticipantResult addParticipantResult = serverCall.addParticipant(user, CallingServerResponseMocker.URI_CALLBACK, "alternateCallerId", "operationContext"); + assertEquals(user.getId(), addParticipantResult.getParticipantId()); + } + + @Test + public void appParticipantServerCallWithResponse() { + ServerCall serverCall = CallingServerResponseMocker.getServerCall(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(CallingServerResponseMocker.NEW_PARTICIPANT_ID), 202) + )) + ); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(CallingServerResponseMocker.NEW_PARTICIPANT_ID); + Response addParticipantResultResponse = serverCall.addParticipantWithResponse(user, CallingServerResponseMocker.URI_CALLBACK, "alternateCallerId", "operationContext", Context.NONE); + assertEquals(202, addParticipantResultResponse.getStatusCode()); + AddParticipantResult addParticipantResult = addParticipantResultResponse.getValue(); + assertEquals(user.getId(), addParticipantResult.getParticipantId()); + } + + @Test + public void appParticipantServerCallAsync() { + ServerCallAsync serverCall = CallingServerResponseMocker.getServerCallAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(CallingServerResponseMocker.NEW_PARTICIPANT_ID), 202) + )) + ); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(CallingServerResponseMocker.NEW_PARTICIPANT_ID); + AddParticipantResult addParticipantResult = serverCall.addParticipant(user, CallingServerResponseMocker.URI_CALLBACK, "alternateCallerId", "operationContext").block(); + assertEquals(user.getId(), addParticipantResult.getParticipantId()); + } + + @Test + public void appParticipantServerCallAsyncWithResponse() { + ServerCallAsync serverCall = CallingServerResponseMocker.getServerCallAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generateAddParticipantResult(CallingServerResponseMocker.NEW_PARTICIPANT_ID), 202) + )) + ); + + CommunicationUserIdentifier user = new CommunicationUserIdentifier(CallingServerResponseMocker.NEW_PARTICIPANT_ID); + Response addParticipantResultResponse = serverCall.addParticipantWithResponse(user, CallingServerResponseMocker.URI_CALLBACK, "alternateCallerId", "operationContext").block(); + assertEquals(202, addParticipantResultResponse.getStatusCode()); + AddParticipantResult addParticipantResult = addParticipantResultResponse.getValue(); + assertEquals(user.getId(), addParticipantResult.getParticipantId()); + } + + @Test + public void removeParticipantServerCall() { + ServerCall serverCall = CallingServerResponseMocker.getServerCall(new ArrayList>( + Arrays.asList( + new SimpleEntry("", 202) + )) + ); + + serverCall.removeParticipant(CallingServerResponseMocker.NEW_PARTICIPANT_ID); + } + + @Test + public void removeParticipantServerCallWithResponse() { + ServerCall serverCall = CallingServerResponseMocker.getServerCall(new ArrayList>( + Arrays.asList( + new SimpleEntry("", 202) + )) + ); + + Response removeParticipantResultResponse = serverCall.removeParticipantWithResponse(CallingServerResponseMocker.NEW_PARTICIPANT_ID, Context.NONE); + assertEquals(202, removeParticipantResultResponse.getStatusCode()); + } + + @Test + public void removeParticipantServerCallAsync() { + ServerCallAsync serverCall = CallingServerResponseMocker.getServerCallAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry("", 202) + )) + ); + + serverCall.removeParticipant(CallingServerResponseMocker.NEW_PARTICIPANT_ID).block(); + } + + @Test + public void removeParticipantServerCallAsyncWithResponse() { + ServerCallAsync serverCall = CallingServerResponseMocker.getServerCallAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry("", 202) + )) + ); + + Response removeParticipantResultResponse = serverCall.removeParticipantWithResponse(CallingServerResponseMocker.NEW_PARTICIPANT_ID, Context.NONE).block(); + assertEquals(202, removeParticipantResultResponse.getStatusCode()); + } + + private ServerCall getServerCall() { + return CallingServerResponseMocker.getServerCall(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generatePlayAudioResult( + CallingServerResponseMocker.OPERATION_ID, + OperationStatus.COMPLETED, + new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")), + 202) + ))); + } + + private ServerCallAsync getServerCallAsync() { + return CallingServerResponseMocker.getServerCallAsync(new ArrayList>( + Arrays.asList( + new SimpleEntry(CallingServerResponseMocker.generatePlayAudioResult( + CallingServerResponseMocker.OPERATION_ID, + OperationStatus.COMPLETED, + new ResultInfoInternal().setCode(202).setSubcode(0).setMessage("message")), + 202) + ))); + } } From 7893b1310d27fb4c02f7cc63dc2fccd31117940a Mon Sep 17 00:00:00 2001 From: Arif Saikat <71465659+arifsaikat-microsoft@users.noreply.github.com> Date: Mon, 21 Jun 2021 19:35:16 -0700 Subject: [PATCH 03/24] event related unit test --- .../callingserver/EventTests.java | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index 9f779908df71a..8811df5a7cf31 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -3,8 +3,12 @@ package com.azure.communication.callingserver; +import com.azure.communication.callingserver.implementation.models.AddParticipantResultEventInternal; import com.azure.communication.callingserver.implementation.models.CallConnectionStateChangedEventInternal; +import com.azure.communication.callingserver.implementation.models.ResultInfoInternal; import com.azure.communication.callingserver.models.CallConnectionState; +import com.azure.communication.callingserver.models.OperationStatus; +import com.azure.communication.callingserver.models.events.AddParticipantResultEvent; import com.azure.communication.callingserver.models.events.CallConnectionStateChangedEvent; import com.azure.core.util.BinaryData; import com.fasterxml.jackson.core.JsonProcessingException; @@ -12,10 +16,13 @@ import com.fasterxml.jackson.databind.ObjectWriter; import org.junit.jupiter.api.Test; +import java.security.InvalidParameterException; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class EventTests { @Test @@ -28,15 +35,43 @@ public void callConnectionStateChangedEventTest() throws JsonProcessingException .setServerCallId(serverCallId) .setCallConnectionState(CallConnectionState.CONNECTED); - ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); - String jsonData = objectWriter.writeValueAsString(internalEvent); - BinaryData binaryData = BinaryData.fromString(jsonData); - - CallConnectionStateChangedEvent event = CallConnectionStateChangedEvent.deserialize(binaryData); + BinaryData binaryData = getBinaryData(internalEvent); + CallConnectionStateChangedEvent event = + assertDoesNotThrow(() -> CallConnectionStateChangedEvent.deserialize(binaryData)); assertNotNull(event); assertEquals(event.getCallConnectionId(), callConnectionId); assertEquals(event.getServerCallId(), serverCallId); assertEquals(event.getCallConnectionState(), CallConnectionState.CONNECTED); } + + @Test + public void addParticipantResultEventTest() throws JsonProcessingException { + var operationContext = UUID.randomUUID().toString(); + var message = "Participant added."; + AddParticipantResultEventInternal internalEvent = + new AddParticipantResultEventInternal() + .setOperationContext(operationContext) + .setStatus(OperationStatus.COMPLETED) + .setResultInfo(new ResultInfoInternal().setCode(100).setSubcode(200).setMessage(message)); + + BinaryData binaryData = getBinaryData(internalEvent); + AddParticipantResultEvent event = + assertDoesNotThrow(() -> AddParticipantResultEvent.deserialize(binaryData)); + + assertNotNull(event); + assertEquals(event.getOperationContext(), operationContext); + assertEquals(event.getStatus(), OperationStatus.COMPLETED); + assertNotNull(event.getResultInfo()); + assertEquals(event.getResultInfo().getCode(), 100); + assertEquals(event.getResultInfo().getSubcode(), 200); + assertEquals(event.getResultInfo().getMessage(), message); + + } + + private BinaryData getBinaryData(Object eventObject) throws JsonProcessingException { + ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonData = objectWriter.writeValueAsString(eventObject); + return BinaryData.fromString(jsonData); + } } From 4dcec1d25bb8375648b09d29c163d21fac1876dd Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Mon, 21 Jun 2021 19:45:41 -0700 Subject: [PATCH 04/24] fix(unit-tests): remove var declarators --- .../callingserver/DownloadContentAsyncUnitTests.java | 4 ++-- .../com/azure/communication/callingserver/EventTests.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java index 6e364d4f2d01d..a849aea37a366 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java @@ -38,7 +38,7 @@ public void downloadStream() throws IOException { Flux fluxByteBuffer = callingServerClient.downloadStream("https://url.com", new HttpRange(contents.length())); - var resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); + String resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); assertEquals("VideoContents", resultContents); } @@ -53,7 +53,7 @@ public void downloadStreamWithResponse() throws IOException { Response> fluxByteBufferResponse = callingServerClient.downloadStreamWithResponse("https://url.com", new HttpRange(contents.length())).block(); assertEquals(200, fluxByteBufferResponse.getStatusCode()); Flux fluxByteBuffer = fluxByteBufferResponse.getValue(); - var resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); + String resultContents = new String(fluxByteBuffer.next().block().array(), StandardCharsets.UTF_8); assertEquals("VideoContents", resultContents); } diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index 9f779908df71a..cc94f4e494666 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -20,8 +20,8 @@ public class EventTests { @Test public void callConnectionStateChangedEventTest() throws JsonProcessingException { - var serverCallId = UUID.randomUUID().toString(); - var callConnectionId = UUID.randomUUID().toString(); + String serverCallId = UUID.randomUUID().toString(); + String callConnectionId = UUID.randomUUID().toString(); CallConnectionStateChangedEventInternal internalEvent = new CallConnectionStateChangedEventInternal() .setCallConnectionId(callConnectionId) From 9d38e7a04ccc52bfaa5efcb2319e17e8ef482915 Mon Sep 17 00:00:00 2001 From: Arif Saikat <71465659+arifsaikat-microsoft@users.noreply.github.com> Date: Mon, 21 Jun 2021 21:33:03 -0700 Subject: [PATCH 05/24] event related unit test --- .../callingserver/EventTests.java | 153 +++++++++++++++++- 1 file changed, 150 insertions(+), 3 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index 8811df5a7cf31..dc63ffb2d4329 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -5,24 +5,52 @@ import com.azure.communication.callingserver.implementation.models.AddParticipantResultEventInternal; import com.azure.communication.callingserver.implementation.models.CallConnectionStateChangedEventInternal; +import com.azure.communication.callingserver.implementation.models.CallParticipantInternal; +import com.azure.communication.callingserver.implementation.models.CallRecordingStateChangeEventInternal; +import com.azure.communication.callingserver.implementation.models.CommunicationIdentifierModel; +import com.azure.communication.callingserver.implementation.models.ParticipantsUpdatedEventInternal; +import com.azure.communication.callingserver.implementation.models.PhoneNumberIdentifierModel; +import com.azure.communication.callingserver.implementation.models.PlayAudioResultEventInternal; import com.azure.communication.callingserver.implementation.models.ResultInfoInternal; +import com.azure.communication.callingserver.implementation.models.ToneInfoInternal; +import com.azure.communication.callingserver.implementation.models.ToneReceivedEventInternal; import com.azure.communication.callingserver.models.CallConnectionState; +import com.azure.communication.callingserver.models.CallRecordingState; import com.azure.communication.callingserver.models.OperationStatus; +import com.azure.communication.callingserver.models.ToneValue; import com.azure.communication.callingserver.models.events.AddParticipantResultEvent; import com.azure.communication.callingserver.models.events.CallConnectionStateChangedEvent; +import com.azure.communication.callingserver.models.events.CallRecordingStateChangeEvent; +import com.azure.communication.callingserver.models.events.ParticipantsUpdatedEvent; +import com.azure.communication.callingserver.models.events.PlayAudioResultEvent; +import com.azure.communication.callingserver.models.events.ToneReceivedEvent; +import com.azure.communication.common.PhoneNumberIdentifier; import com.azure.core.util.BinaryData; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.junit.jupiter.api.Test; -import java.security.InvalidParameterException; +import java.io.IOException; +import java.time.OffsetDateTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EventTests { @Test @@ -66,12 +94,131 @@ public void addParticipantResultEventTest() throws JsonProcessingException { assertEquals(event.getResultInfo().getCode(), 100); assertEquals(event.getResultInfo().getSubcode(), 200); assertEquals(event.getResultInfo().getMessage(), message); + } + + @Test + public void callRecordingStateChangeEventTest() throws JsonProcessingException { + var serverCallId = UUID.randomUUID().toString(); + var recordingId = UUID.randomUUID().toString(); + CallRecordingStateChangeEventInternal internalEvent = + new CallRecordingStateChangeEventInternal() + .setServerCallId(serverCallId) + .setRecordingId(recordingId) + .setState(CallRecordingState.ACTIVE) + .setStartDateTime(OffsetDateTime.MIN); + + BinaryData binaryData = getBinaryData(internalEvent); + CallRecordingStateChangeEvent event = + assertDoesNotThrow(() -> CallRecordingStateChangeEvent.deserialize(binaryData)); + + assertNotNull(event); + assertEquals(event.getRecordingId(), recordingId); + assertEquals(event.getServerCallId(), serverCallId); + assertEquals(event.getState(), CallRecordingState.ACTIVE); + assertEquals(event.getStartDateTime(), OffsetDateTime.MIN); + } + + @Test + public void playAudioResultEventTest() throws JsonProcessingException { + var operationContext = UUID.randomUUID().toString(); + var message = "Media operation executed."; + PlayAudioResultEventInternal internalEvent = + new PlayAudioResultEventInternal() + .setOperationContext(operationContext) + .setStatus(OperationStatus.COMPLETED) + .setResultInfo(new ResultInfoInternal().setCode(100).setSubcode(200).setMessage(message)); + + BinaryData binaryData = getBinaryData(internalEvent); + PlayAudioResultEvent event = + assertDoesNotThrow(() -> PlayAudioResultEvent.deserialize(binaryData)); + + assertNotNull(event); + assertEquals(event.getOperationContext(), operationContext); + assertEquals(event.getStatus(), OperationStatus.COMPLETED); + assertNotNull(event.getResultInfo()); + assertEquals(event.getResultInfo().getCode(), 100); + assertEquals(event.getResultInfo().getSubcode(), 200); + assertEquals(event.getResultInfo().getMessage(), message); + } + + @Test + public void toneReceivedEventTest() throws JsonProcessingException { + var callConnectionId = UUID.randomUUID().toString(); + ToneReceivedEventInternal internalEvent = + new ToneReceivedEventInternal() + .setCallConnectionId(callConnectionId) + .setToneInfo(new ToneInfoInternal() + .setSequenceId(1) + .setTone(ToneValue.TONE1)); + + BinaryData binaryData = getBinaryData(internalEvent); + ToneReceivedEvent event = + assertDoesNotThrow(() -> ToneReceivedEvent.deserialize(binaryData)); + + assertNotNull(event); + assertEquals(event.getCallConnectionId(), callConnectionId); + assertNotNull(event.getToneInfo()); + assertEquals(event.getToneInfo().getSequenceId(), 1); + assertEquals(event.getToneInfo().getTone(), ToneValue.TONE1); + } + + @Test + public void participantsUpdatedEventTest() throws JsonProcessingException { + var callConnectionId = UUID.randomUUID().toString(); + var participantId = UUID.randomUUID().toString(); + var phoneNumber = "+18881112222"; + ParticipantsUpdatedEventInternal internalEvent = + new ParticipantsUpdatedEventInternal() + .setCallConnectionId(callConnectionId) + .setParticipants( + new LinkedList<>(Collections.singletonList( + new CallParticipantInternal() + .setParticipantId(participantId) + .setIsMuted(false) + .setIdentifier(new CommunicationIdentifierModel() + .setPhoneNumber(new PhoneNumberIdentifierModel().setValue(phoneNumber)))))); + BinaryData binaryData = getBinaryData(internalEvent); + ParticipantsUpdatedEvent event = + assertDoesNotThrow(() -> ParticipantsUpdatedEvent.deserialize(binaryData)); + + assertNotNull(event); + assertEquals(event.getCallConnectionId(), callConnectionId); + assertNotNull(event.getParticipants()); + assertEquals(1, event.getParticipants().size()); + assertEquals(event.getParticipants().get(0).getParticipantId(), participantId); + assertFalse(event.getParticipants().get(0).isMuted()); + assertEquals(((PhoneNumberIdentifier) event.getParticipants().get(0).getIdentifier()).getPhoneNumber(), phoneNumber); } private BinaryData getBinaryData(Object eventObject) throws JsonProcessingException { - ObjectWriter objectWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); + ObjectWriter objectWriter = getObjectMapper().writer().withDefaultPrettyPrinter(); String jsonData = objectWriter.writeValueAsString(eventObject); return BinaryData.fromString(jsonData); } + + private ObjectMapper getObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<>() { + @Override + public void serialize( + OffsetDateTime offsetDateTime, + JsonGenerator jsonGenerator, + SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeString(offsetDateTime.toString()); + } + }); + simpleModule.addDeserializer(OffsetDateTime.class, new JsonDeserializer<>() { + @Override + public OffsetDateTime deserialize( + JsonParser jsonParser, + DeserializationContext deserializationContext) throws IOException { + return OffsetDateTime.parse(jsonParser.getText()); + } + }); + objectMapper.registerModule(simpleModule); + return objectMapper; + } } From bd7a50000b284372b1605a2a328ecc03f71e798b Mon Sep 17 00:00:00 2001 From: Arif Saikat <71465659+arifsaikat-microsoft@users.noreply.github.com> Date: Mon, 21 Jun 2021 21:36:11 -0700 Subject: [PATCH 06/24] event related unit test --- .../java/com/azure/communication/callingserver/EventTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index dc63ffb2d4329..142d80863e509 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -41,7 +41,6 @@ import java.io.IOException; import java.time.OffsetDateTime; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.UUID; @@ -50,7 +49,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; public class EventTests { @Test From dff0ed5bc684ce8cb9b3d8dcad531cca46ae8ed8 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Mon, 21 Jun 2021 22:31:49 -0700 Subject: [PATCH 07/24] fix(unit-tests): fix issue with List.to, increase coverage --- .../CallConnectionAsyncUnitTests.java | 10 ++++++++-- .../callingserver/CallConnectionUnitTests.java | 10 ++++++++-- .../DownloadContentAsyncUnitTests.java | 14 ++++++++++++++ .../callingserver/MockHttpClient.java | 6 ++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java index b32d30a278922..e7700230e85bf 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionAsyncUnitTests.java @@ -118,7 +118,10 @@ public void joinCallWithResponse() { ))); CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); - JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + JoinCallOptions options = new JoinCallOptions( + CallingServerResponseMocker.URI_CALLBACK, + Collections.singletonList(MediaType.VIDEO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); Response callConnectionAsyncResponse = callingServerAsyncClient.joinCallWithResponse(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options).block(); assertEquals(202, callConnectionAsyncResponse.getStatusCode()); assertNotNull(callConnectionAsyncResponse.getValue()); @@ -132,7 +135,10 @@ public void joinCall() { ))); CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); - JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + 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); } diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java index d4450eeac872f..12b5f1d4f89b2 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallConnectionUnitTests.java @@ -120,7 +120,10 @@ public void joinCall() { ))); CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); - JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + 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); } @@ -133,7 +136,10 @@ public void joinCallWithResponse() { ))); CommunicationUserIdentifier user = new CommunicationUserIdentifier(NEW_PARTICIPANT_ID); - JoinCallOptions options = new JoinCallOptions(CallingServerResponseMocker.URI_CALLBACK, List.of(MediaType.VIDEO), List.of(EventSubscriptionType.PARTICIPANTS_UPDATED)); + JoinCallOptions options = new JoinCallOptions( + CallingServerResponseMocker.URI_CALLBACK, + Collections.singletonList(MediaType.VIDEO), + Collections.singletonList(EventSubscriptionType.PARTICIPANTS_UPDATED)); Response callConnectionResponse = callingServerAsyncClient.joinCallWithResponse(CallingServerResponseMocker.SERVER_CALL_ID, (CommunicationIdentifier) user, options, Context.NONE); assertEquals(202, callConnectionResponse.getStatusCode()); assertNotNull(callConnectionResponse.getValue()); diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java index a849aea37a366..d66736dc646a8 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/DownloadContentAsyncUnitTests.java @@ -4,6 +4,7 @@ package com.azure.communication.callingserver; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; @@ -57,6 +58,19 @@ public void downloadStreamWithResponse() throws IOException { assertEquals("VideoContents", resultContents); } + @Test + public void downloadStreamWithResponseThrowException() throws IOException { + String contents = "VideoContents"; + CallingServerAsyncClient callingServerClient = CallingServerResponseMocker.getCallingServerAsyncClient(new ArrayList>( + Arrays.asList( + new SimpleEntry("", 416) + ))); + + Response> fluxByteBufferResponse = callingServerClient.downloadStreamWithResponse("https://url.com", new HttpRange(contents.length())).block(); + Flux fluxByteBuffer = fluxByteBufferResponse.getValue(); + assertThrows(NullPointerException.class, () -> fluxByteBuffer.next().block()); + } + @Test public void downloadToWithResponse() throws IOException { String contents = "VideoContents"; diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java index d7df37b7ee4db..3a3c5061ae0d6 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/MockHttpClient.java @@ -8,12 +8,14 @@ import java.util.AbstractMap.SimpleEntry; import com.azure.communication.callingserver.CallingServerClientBuilderUnitTests.NoOpHttpClient; +import com.azure.communication.callingserver.models.CallingServerErrorException; import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; import reactor.core.publisher.Mono; public class MockHttpClient extends NoOpHttpClient { + public static final String THROW_TEST_EXCEPTION = "exception"; private ArrayList> responses = new ArrayList>(); private ArrayList requests = new ArrayList(); @@ -32,6 +34,10 @@ public Mono send(HttpRequest request) { if (responses.size() > 0) { SimpleEntry entry = responses.get(0); responses.remove(entry); + HttpResponse response = CallingServerResponseMocker.generateMockResponse(entry.getKey(), request, entry.getValue()); + if (entry.getKey().startsWith(THROW_TEST_EXCEPTION)) { + return Mono.error(new CallingServerErrorException("Mock error", response)); + } return Mono.just(CallingServerResponseMocker.generateMockResponse(entry.getKey(), request, entry.getValue())); } From 0250e4005e4169c2f55670da2a88c1ec921c5f65 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 00:03:40 -0700 Subject: [PATCH 08/24] fix(unit-tests): remove var declarations --- .../callingserver/EventTests.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index a1d28bfef0859..17cbaab9ba6f1 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -73,8 +73,8 @@ public void callConnectionStateChangedEventTest() throws JsonProcessingException @Test public void addParticipantResultEventTest() throws JsonProcessingException { - var operationContext = UUID.randomUUID().toString(); - var message = "Participant added."; + String operationContext = UUID.randomUUID().toString(); + String message = "Participant added."; AddParticipantResultEventInternal internalEvent = new AddParticipantResultEventInternal() .setOperationContext(operationContext) @@ -96,8 +96,8 @@ public void addParticipantResultEventTest() throws JsonProcessingException { @Test public void callRecordingStateChangeEventTest() throws JsonProcessingException { - var serverCallId = UUID.randomUUID().toString(); - var recordingId = UUID.randomUUID().toString(); + String serverCallId = UUID.randomUUID().toString(); + String recordingId = UUID.randomUUID().toString(); CallRecordingStateChangeEventInternal internalEvent = new CallRecordingStateChangeEventInternal() .setServerCallId(serverCallId) @@ -118,8 +118,8 @@ public void callRecordingStateChangeEventTest() throws JsonProcessingException { @Test public void playAudioResultEventTest() throws JsonProcessingException { - var operationContext = UUID.randomUUID().toString(); - var message = "Media operation executed."; + String operationContext = UUID.randomUUID().toString(); + String message = "Media operation executed."; PlayAudioResultEventInternal internalEvent = new PlayAudioResultEventInternal() .setOperationContext(operationContext) @@ -141,7 +141,7 @@ public void playAudioResultEventTest() throws JsonProcessingException { @Test public void toneReceivedEventTest() throws JsonProcessingException { - var callConnectionId = UUID.randomUUID().toString(); + String callConnectionId = UUID.randomUUID().toString(); ToneReceivedEventInternal internalEvent = new ToneReceivedEventInternal() .setCallConnectionId(callConnectionId) @@ -162,9 +162,9 @@ public void toneReceivedEventTest() throws JsonProcessingException { @Test public void participantsUpdatedEventTest() throws JsonProcessingException { - var callConnectionId = UUID.randomUUID().toString(); - var participantId = UUID.randomUUID().toString(); - var phoneNumber = "+18881112222"; + String callConnectionId = UUID.randomUUID().toString(); + String participantId = UUID.randomUUID().toString(); + String phoneNumber = "+18881112222"; ParticipantsUpdatedEventInternal internalEvent = new ParticipantsUpdatedEventInternal() .setCallConnectionId(callConnectionId) From 82ac2d7b4f4f6c2a2f24717944c93261a0783d4b Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 09:37:36 -0700 Subject: [PATCH 09/24] fix(unit-tests): fix issue with infered generic in annonymous type --- .../com/azure/communication/callingserver/EventTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java index 17cbaab9ba6f1..960ea4e9dd71d 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/EventTests.java @@ -199,7 +199,7 @@ private ObjectMapper getObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); SimpleModule simpleModule = new SimpleModule(); - simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<>() { + simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer() { @Override public void serialize( OffsetDateTime offsetDateTime, @@ -208,7 +208,7 @@ public void serialize( jsonGenerator.writeString(offsetDateTime.toString()); } }); - simpleModule.addDeserializer(OffsetDateTime.class, new JsonDeserializer<>() { + simpleModule.addDeserializer(OffsetDateTime.class, new JsonDeserializer() { @Override public OffsetDateTime deserialize( JsonParser jsonParser, From 3a0795a03335d157d39f01ed03f738f5d3ed83f7 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 09:46:08 -0700 Subject: [PATCH 10/24] fix(test-config): attempt to remove int --- sdk/communication/azure-communication-callingserver/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index afd6c1d779248..fb18b3e729323 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -5,4 +5,5 @@ stages: parameters: PackageName: azure-communication-callingserver SafeName: azurecommunicationcallingserver + Clouds: Public From 04c84d9523a3563b0442cc6e7dfa78e3602b2e0d Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 10:35:17 -0700 Subject: [PATCH 11/24] fix(test-config): override communication test template to remove int --- .../callingserver/CallingServerTestBase.java | 9 +++-- .../tests.yml | 36 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java index f1ea73fdb1a69..76ab20ba6cb13 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java @@ -46,6 +46,9 @@ public class CallingServerTestBase extends TestBase { .get("COMMUNICATION_LIVETEST_STATIC_RESOURCE_IDENTIFIER", "016a7064-0581-40b9-be73-6dde64d69d72"); + protected static final Boolean GENERATE_RANDOM_GROUP_IDENTIFIER = Configuration.getGlobalConfiguration() + .get("CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER", true); + protected static final String FROM_PHONE_NUMBER = Configuration.getGlobalConfiguration() .get("AZURE_PHONE_NUMBER", "+15551234567"); @@ -107,9 +110,11 @@ protected String getGroupId(String testName) { /* If tests are running in live mode, we want them to all have unique groupId's so they do not conflict with other - recording tests running in live mode. + recording tests running in live mode. Live test pipeline + runs in recording mode, so we need to generate random + groupId's. */ - if (getTestMode() == TestMode.LIVE) { + if (getTestMode() == TestMode.LIVE || GENERATE_RANDOM_GROUP_IDENTIFIER) { return UUID.randomUUID().toString(); } diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index fb18b3e729323..927a67344d70b 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -1,9 +1,35 @@ trigger: none +parameters: + PackageName: azure-communication-callingserver + SafeName: azurecommunicationcallingserver + stages: - - template: /sdk/communication/communication-tests-template.yml - parameters: - PackageName: azure-communication-callingserver - SafeName: azurecommunicationcallingserver + - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml + parameters: + CloudConfig: + Public: + SubscriptionConfigurations: + - $(sub-config-azure-cloud-test-resources) + - $(sub-config-communication-services-cloud-test-resources-common) + - $(sub-config-communication-services-cloud-test-resources-java) Clouds: Public - + Artifacts: + - name: ${{ parameters.PackageName }} + groupId: com.azure + safeName: ${{ parameters.SafeName }} + ServiceDirectory: communication + PreSteps: + - bash: echo "##vso[task.setvariable variable=DefaultTestOptions]-Djacoco.skip=true $(DefaultTestOptions)" + condition: not(startsWith(variables['System.StageName'], 'Public')) + PostSteps: + - task: PublishCodeCoverageResults@1 + condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), startsWith(variables['System.StageName'], 'Public')) + inputs: + codeCoverageTool: JaCoCo + summaryFileLocation: sdk/communication/${{ parameters.PackageName }}/target/site/jacoco/jacoco.xml + reportDirectory: sdk/communication/${{ parameters.PackageName }}/target/site/jacoco/ + failIfCoverageEmpty: true + EnvVars: + SKIP_LIVE_TEST: TRUE + CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER: TRUE \ No newline at end of file From 21fe246773265c727a88a427a1e4e8139172cfe6 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 10:36:57 -0700 Subject: [PATCH 12/24] fix(test-config): override communication test template to remove int --- .../azure-communication-callingserver/tests.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 927a67344d70b..b116bd50cec89 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -1,12 +1,10 @@ trigger: none -parameters: - PackageName: azure-communication-callingserver - SafeName: azurecommunicationcallingserver - stages: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: + parameters: + PackageName: azure-communication-callingserver + SafeName: azurecommunicationcallingserver CloudConfig: Public: SubscriptionConfigurations: From 80c593cc68ccd807b7a92114ce45a5683ecef80f Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 10:38:56 -0700 Subject: [PATCH 13/24] fix(test-config): override communication test template to remove int --- .../azure-communication-callingserver/tests.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index b116bd50cec89..828f8596ea64f 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -2,9 +2,7 @@ trigger: none stages: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: - PackageName: azure-communication-callingserver - SafeName: azurecommunicationcallingserver + parameters: CloudConfig: Public: SubscriptionConfigurations: @@ -13,9 +11,9 @@ stages: - $(sub-config-communication-services-cloud-test-resources-java) Clouds: Public Artifacts: - - name: ${{ parameters.PackageName }} + - name: azure-communication-callingserver groupId: com.azure - safeName: ${{ parameters.SafeName }} + safeName: azurecommunicationcallingserver ServiceDirectory: communication PreSteps: - bash: echo "##vso[task.setvariable variable=DefaultTestOptions]-Djacoco.skip=true $(DefaultTestOptions)" @@ -25,8 +23,8 @@ stages: condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), startsWith(variables['System.StageName'], 'Public')) inputs: codeCoverageTool: JaCoCo - summaryFileLocation: sdk/communication/${{ parameters.PackageName }}/target/site/jacoco/jacoco.xml - reportDirectory: sdk/communication/${{ parameters.PackageName }}/target/site/jacoco/ + summaryFileLocation: sdk/communication/azure-communication-callingserver/target/site/jacoco/jacoco.xml + reportDirectory: sdk/communication/azure-communication-callingserver/target/site/jacoco/ failIfCoverageEmpty: true EnvVars: SKIP_LIVE_TEST: TRUE From 11350830385a77e70f2ce4e12201232c5b79b324 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 11:14:56 -0700 Subject: [PATCH 14/24] fix(unit-tests): update random generation of groupIds --- .../callingserver/CallingServerTestBase.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java index 76ab20ba6cb13..78a2049860c16 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java @@ -46,8 +46,8 @@ public class CallingServerTestBase extends TestBase { .get("COMMUNICATION_LIVETEST_STATIC_RESOURCE_IDENTIFIER", "016a7064-0581-40b9-be73-6dde64d69d72"); - protected static final Boolean GENERATE_RANDOM_GROUP_IDENTIFIER = Configuration.getGlobalConfiguration() - .get("CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER", true); + protected static final Boolean GENERATE_RANDOM_GROUP_IDENTIFIER_RECORD_MODE = Configuration.getGlobalConfiguration() + .get("CALLINGSERVER_GENERATE_RANDOM_GROUPID_IN_RECORD_MODE", true); protected static final String FROM_PHONE_NUMBER = Configuration.getGlobalConfiguration() .get("AZURE_PHONE_NUMBER", "+15551234567"); @@ -110,11 +110,19 @@ protected String getGroupId(String testName) { /* If tests are running in live mode, we want them to all have unique groupId's so they do not conflict with other - recording tests running in live mode. Live test pipeline - runs in recording mode, so we need to generate random - groupId's. + recording tests running in live mode. */ - if (getTestMode() == TestMode.LIVE || GENERATE_RANDOM_GROUP_IDENTIFIER) { + if (getTestMode() == TestMode.LIVE) { + return UUID.randomUUID().toString(); + } + + /* + The Live test pipeline runs in recording mode, so we + need to generate random groupId's. We pull this value + from the test.yml file which is only used in CI and + Live pipeline. + */ + if (getTestMode() == TestMode.RECORD && GENERATE_RANDOM_GROUP_IDENTIFIER_RECORD_MODE) { return UUID.randomUUID().toString(); } From b98886c0b044c691e7376ba137daa354f2dc4707 Mon Sep 17 00:00:00 2001 From: Arif Saikat <71465659+arifsaikat-microsoft@users.noreply.github.com> Date: Tue, 22 Jun 2021 12:52:30 -0700 Subject: [PATCH 15/24] added newline at end of config file --- .../azure-communication-callingserver/tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 828f8596ea64f..41d7425f49e41 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -2,7 +2,7 @@ trigger: none stages: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: + parameters: CloudConfig: Public: SubscriptionConfigurations: @@ -28,4 +28,5 @@ stages: failIfCoverageEmpty: true EnvVars: SKIP_LIVE_TEST: TRUE - CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER: TRUE \ No newline at end of file + CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER: TRUE + From 490219504cd7b12a998ee58f5325a5335282a547 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 14:22:09 -0700 Subject: [PATCH 16/24] fix(tests): update test.yml to be parameterized, force live mode --- .../callingserver/CallingServerTestBase.java | 15 +-------- .../tests.yml | 33 +++---------------- .../communication-tests-template.yml | 8 +++-- 3 files changed, 11 insertions(+), 45 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java index 78a2049860c16..adf6b27ebf1ee 100644 --- a/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java +++ b/sdk/communication/azure-communication-callingserver/src/test/java/com/azure/communication/callingserver/CallingServerTestBase.java @@ -44,10 +44,7 @@ public class CallingServerTestBase extends TestBase { protected static final String AZURE_TENANT_ID = Configuration.getGlobalConfiguration() .get("COMMUNICATION_LIVETEST_STATIC_RESOURCE_IDENTIFIER", - "016a7064-0581-40b9-be73-6dde64d69d72"); - - protected static final Boolean GENERATE_RANDOM_GROUP_IDENTIFIER_RECORD_MODE = Configuration.getGlobalConfiguration() - .get("CALLINGSERVER_GENERATE_RANDOM_GROUPID_IN_RECORD_MODE", true); + "016a7064-0581-40b9-be73-6dde64d69d72"); protected static final String FROM_PHONE_NUMBER = Configuration.getGlobalConfiguration() .get("AZURE_PHONE_NUMBER", "+15551234567"); @@ -116,16 +113,6 @@ protected String getGroupId(String testName) { return UUID.randomUUID().toString(); } - /* - The Live test pipeline runs in recording mode, so we - need to generate random groupId's. We pull this value - from the test.yml file which is only used in CI and - Live pipeline. - */ - if (getTestMode() == TestMode.RECORD && GENERATE_RANDOM_GROUP_IDENTIFIER_RECORD_MODE) { - return UUID.randomUUID().toString(); - } - /* For recording tests we need to make sure the groupId matches the recorded groupId, or the call will fail. diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 828f8596ea64f..bc0e15863ab5e 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -1,31 +1,6 @@ trigger: none -stages: - - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml - parameters: - CloudConfig: - Public: - SubscriptionConfigurations: - - $(sub-config-azure-cloud-test-resources) - - $(sub-config-communication-services-cloud-test-resources-common) - - $(sub-config-communication-services-cloud-test-resources-java) - Clouds: Public - Artifacts: - - name: azure-communication-callingserver - groupId: com.azure - safeName: azurecommunicationcallingserver - ServiceDirectory: communication - PreSteps: - - bash: echo "##vso[task.setvariable variable=DefaultTestOptions]-Djacoco.skip=true $(DefaultTestOptions)" - condition: not(startsWith(variables['System.StageName'], 'Public')) - PostSteps: - - task: PublishCodeCoverageResults@1 - condition: and(eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['JavaTestVersion'], '1.11'), startsWith(variables['System.StageName'], 'Public')) - inputs: - codeCoverageTool: JaCoCo - summaryFileLocation: sdk/communication/azure-communication-callingserver/target/site/jacoco/jacoco.xml - reportDirectory: sdk/communication/azure-communication-callingserver/target/site/jacoco/ - failIfCoverageEmpty: true - EnvVars: - SKIP_LIVE_TEST: TRUE - CALLINGSERVER_GENERATE_RANDOM_GROUP_IDENTIFIER: TRUE \ No newline at end of file + - template: /sdk/communication/communication-tests-template.yml + parameters: + Clouds: Public + TestMode: LIVE \ No newline at end of file diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 627005f89d7e4..7cccff13f81af 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -1,6 +1,8 @@ parameters: PackageName: not-specified SafeName: notspecified + Clouds: 'Public,Int' + EnvVars: {} stages: - template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml @@ -15,7 +17,7 @@ stages: SubscriptionConfigurations: - $(sub-config-communication-int-test-resources-common) - $(sub-config-communication-int-test-resources-java) - Clouds: Public, Int + Clouds: ${{ parameters.Clouds }} Artifacts: - name: ${{ parameters.PackageName }} groupId: com.azure @@ -33,4 +35,6 @@ stages: reportDirectory: sdk/communication/${{ parameters.PackageName }}/target/site/jacoco/ failIfCoverageEmpty: true EnvVars: - SKIP_LIVE_TEST: TRUE \ No newline at end of file + SKIP_LIVE_TEST: TRUE + ${{ each var in parameters.EnVars }}: + ${{ var.key }}: ${{ var.value }} \ No newline at end of file From 375df593a330ecce7356213864092895a80dfef9 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 14:45:03 -0700 Subject: [PATCH 17/24] fix(unit-tests): update random generation of groupIds --- sdk/communication/azure-communication-callingserver/tests.yml | 4 ++-- sdk/communication/communication-tests-template.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 0921fe5e02d31..d3eb6145b93b9 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -4,5 +4,5 @@ trigger: none parameters: PackageName: azure-communication-callingserver SafeName: azurecommunicationcallingserver - Clouds: Public - TestMode: LIVE + Clouds: Public + TestMode: LIVE diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 7cccff13f81af..0b89f66004f23 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -2,6 +2,7 @@ parameters: PackageName: not-specified SafeName: notspecified Clouds: 'Public,Int' + TestMode: ${{ parameters.TestMode }} EnvVars: {} stages: From 6d8feb85f88238838f1dbbe7046f7f25e897a3f7 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 14:49:00 -0700 Subject: [PATCH 18/24] Revert "fix(unit-tests): update yml files" This reverts commit 375df593a330ecce7356213864092895a80dfef9. --- sdk/communication/azure-communication-callingserver/tests.yml | 4 ++-- sdk/communication/communication-tests-template.yml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index d3eb6145b93b9..0921fe5e02d31 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -4,5 +4,5 @@ trigger: none parameters: PackageName: azure-communication-callingserver SafeName: azurecommunicationcallingserver - Clouds: Public - TestMode: LIVE + Clouds: Public + TestMode: LIVE diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 0b89f66004f23..7cccff13f81af 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -2,7 +2,6 @@ parameters: PackageName: not-specified SafeName: notspecified Clouds: 'Public,Int' - TestMode: ${{ parameters.TestMode }} EnvVars: {} stages: From 96c3cc79e152bc2d737fb936c49f67964152ea36 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 14:51:22 -0700 Subject: [PATCH 19/24] fix(tests): fix yaml --- sdk/communication/azure-communication-callingserver/tests.yml | 4 ++-- sdk/communication/communication-tests-template.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 0921fe5e02d31..d3eb6145b93b9 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -4,5 +4,5 @@ trigger: none parameters: PackageName: azure-communication-callingserver SafeName: azurecommunicationcallingserver - Clouds: Public - TestMode: LIVE + Clouds: Public + TestMode: LIVE diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 7cccff13f81af..0b89f66004f23 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -2,6 +2,7 @@ parameters: PackageName: not-specified SafeName: notspecified Clouds: 'Public,Int' + TestMode: ${{ parameters.TestMode }} EnvVars: {} stages: From 1fb208d1b5ee56ee82dbc8f2d4f647af1babbd93 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 14:56:46 -0700 Subject: [PATCH 20/24] fix(tests): fix yaml --- sdk/communication/communication-tests-template.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 0b89f66004f23..8a051e41c5a45 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -1,8 +1,8 @@ parameters: PackageName: not-specified - SafeName: notspecified + SafeName: not-specified Clouds: 'Public,Int' - TestMode: ${{ parameters.TestMode }} + TestMode: LIVE EnvVars: {} stages: From 80a0f5a21d6a5c707a2531e5c1872d344c6f2465 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 15:00:00 -0700 Subject: [PATCH 21/24] fix(unit-tests): update random generation of groupIds --- sdk/communication/communication-tests-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index 8a051e41c5a45..a161ac8888fa4 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -2,7 +2,7 @@ parameters: PackageName: not-specified SafeName: not-specified Clouds: 'Public,Int' - TestMode: LIVE + TestMode: 'LIVE' EnvVars: {} stages: From 9127cdf3636c6407cb198b8be056af9b76af3678 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 15:07:15 -0700 Subject: [PATCH 22/24] fix(tests): fix yaml --- .../azure-communication-callingserver/tests.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index d3eb6145b93b9..12e6941a7ccdc 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -1,8 +1,9 @@ trigger: none - - template: /sdk/communication/communication-tests-template.yml - parameters: - PackageName: azure-communication-callingserver - SafeName: azurecommunicationcallingserver - Clouds: Public - TestMode: LIVE +stages: +- template: /sdk/communication/communication-tests-template.yml + parameters: + PackageName: azure-communication-callingserver + SafeName: azurecommunicationcallingserver + Clouds: Public + TestMode: LIVE From 41733d6a6fd86e7035046bef2caf116ddb8d34f7 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 15:09:52 -0700 Subject: [PATCH 23/24] fix(tests): more yml --- sdk/communication/azure-communication-callingserver/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/communication/azure-communication-callingserver/tests.yml b/sdk/communication/azure-communication-callingserver/tests.yml index 12e6941a7ccdc..27671325fa64a 100644 --- a/sdk/communication/azure-communication-callingserver/tests.yml +++ b/sdk/communication/azure-communication-callingserver/tests.yml @@ -5,5 +5,5 @@ stages: parameters: PackageName: azure-communication-callingserver SafeName: azurecommunicationcallingserver - Clouds: Public - TestMode: LIVE + Clouds: 'Public' + TestMode: 'LIVE' From 7dae96894fada9b31f41b260c1c9bd42388b48f3 Mon Sep 17 00:00:00 2001 From: Christian Whitehead Date: Tue, 22 Jun 2021 15:19:17 -0700 Subject: [PATCH 24/24] fix(tests): fix yaml --- sdk/communication/communication-tests-template.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/communication/communication-tests-template.yml b/sdk/communication/communication-tests-template.yml index a161ac8888fa4..bddcfbd01e480 100644 --- a/sdk/communication/communication-tests-template.yml +++ b/sdk/communication/communication-tests-template.yml @@ -19,6 +19,7 @@ stages: - $(sub-config-communication-int-test-resources-common) - $(sub-config-communication-int-test-resources-java) Clouds: ${{ parameters.Clouds }} + TestMode: ${{ parameters.TestMode }} Artifacts: - name: ${{ parameters.PackageName }} groupId: com.azure