From 43e543a03bc0f3162126e38c50ca83f15ac1093b Mon Sep 17 00:00:00 2001 From: Richard Cho Date: Wed, 22 Mar 2023 10:21:27 -0700 Subject: [PATCH] add event handler for remove participant events --- .../callautomation/EventHandler.java | 7 +- .../callautomation/EventHandlerUnitTests.java | 74 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java b/sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java index d6451dce2af9..400aa1df1675 100644 --- a/sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java +++ b/sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java @@ -18,6 +18,8 @@ import com.azure.communication.callautomation.models.events.RecognizeFailed; import com.azure.communication.callautomation.models.events.PlayCompleted; import com.azure.communication.callautomation.models.events.RecordingStateChanged; +import com.azure.communication.callautomation.models.events.RemoveParticipantFailed; +import com.azure.communication.callautomation.models.events.RemoveParticipantSucceeded; import com.azure.core.models.CloudEvent; import com.azure.core.util.logging.ClientLogger; import com.fasterxml.jackson.core.JsonProcessingException; @@ -121,8 +123,11 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String ret = mapper.convertValue(eventData, RecognizeFailed.class); } else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeCanceled")) { ret = mapper.convertValue(eventData, RecognizeCanceled.class); + } else if (Objects.equals(eventType, "Microsoft.Communication.RemoveParticipantFailed")) { + ret = mapper.convertValue(eventData, RemoveParticipantFailed.class); + } else if (Objects.equals(eventType, "Microsoft.Communication.RemoveParticipantSucceeded")) { + ret = mapper.convertValue(eventData, RemoveParticipantSucceeded.class); } - return ret; } catch (RuntimeException e) { throw LOGGER.logExceptionAsError(e); diff --git a/sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/EventHandlerUnitTests.java b/sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/EventHandlerUnitTests.java index de3cedfcba49..627d15822a95 100644 --- a/sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/EventHandlerUnitTests.java +++ b/sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/EventHandlerUnitTests.java @@ -18,6 +18,8 @@ import com.azure.communication.callautomation.models.events.CallConnected; import com.azure.communication.callautomation.models.events.RecognizeFailed; import com.azure.communication.callautomation.models.events.RecordingStateChanged; +import com.azure.communication.callautomation.models.events.RemoveParticipantFailed; +import com.azure.communication.callautomation.models.events.RemoveParticipantSucceeded; import com.azure.communication.callautomation.models.events.ReasonCode.Recognize; import org.junit.jupiter.api.Test; @@ -260,4 +262,76 @@ public void parseRecognizeCanceledEvent() { assertNotNull(recognizeCanceledEvent); assertEquals("serverCallId", recognizeCanceledEvent.getServerCallId()); } + + @Test + public void parseRemoveParticipantSucceededEvent() { + String receivedEvent = "[{\n" + + "\"id\": \"c3220fa3-79bd-473e-96a2-3ecb5be7d71f\",\n" + + "\"source\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\",\n" + + "\"type\": \"Microsoft.Communication.RemoveParticipantSucceeded\",\n" + + "\"data\": {\n" + + "\"operationContext\": \"context\",\n" + + "\"participant\": {\n" + + "\"rawId\": \"rawId\",\n" + + "\"phoneNumber\": {\n" + + "\"value\": \"value\"\n" + + "}\n" + + "},\n" + + "\"callConnectionId\": \"callConnectionId\",\n" + + "\"serverCallId\": \"serverCallId\",\n" + + "\"correlationId\": \"b880bd5a-1916-470a-b43d-aabf3caff91c\"\n" + + "},\n" + + "\"time\": \"2023-03-22T16:57:09.287755+00:00\",\n" + + "\"specversion\": \"1.0\",\n" + + "\"datacontenttype\": \"application/json\",\n" + + "\"subject\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\"\n" + + "}]"; + + CallAutomationEventBase event = EventHandler.parseEvent(receivedEvent); + + assertNotNull(event); + + RemoveParticipantSucceeded removeParticipantSucceededEvent = (RemoveParticipantSucceeded) event; + + assertNotNull(removeParticipantSucceededEvent); + assertEquals("serverCallId", removeParticipantSucceededEvent.getServerCallId()); + assertEquals("callConnectionId", removeParticipantSucceededEvent.getCallConnectionId()); + assertEquals("rawId", removeParticipantSucceededEvent.getParticipant().getRawId()); + } + + @Test + public void parseRemoveParticipantFailedEvent() { + String receivedEvent = "[{\n" + + "\"id\": \"c3220fa3-79bd-473e-96a2-3ecb5be7d71f\",\n" + + "\"source\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\",\n" + + "\"type\": \"Microsoft.Communication.RemoveParticipantFailed\",\n" + + "\"data\": {\n" + + "\"operationContext\": \"context\",\n" + + "\"participant\": {\n" + + "\"rawId\": \"rawId\",\n" + + "\"phoneNumber\": {\n" + + "\"value\": \"value\"\n" + + "}\n" + + "},\n" + + "\"callConnectionId\": \"callConnectionId\",\n" + + "\"serverCallId\": \"serverCallId\",\n" + + "\"correlationId\": \"b880bd5a-1916-470a-b43d-aabf3caff91c\"\n" + + "},\n" + + "\"time\": \"2023-03-22T16:57:09.287755+00:00\",\n" + + "\"specversion\": \"1.0\",\n" + + "\"datacontenttype\": \"application/json\",\n" + + "\"subject\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\"\n" + + "}]"; + + CallAutomationEventBase event = EventHandler.parseEvent(receivedEvent); + + assertNotNull(event); + + RemoveParticipantFailed removeParticipantFailedEvent = (RemoveParticipantFailed) event; + + assertNotNull(removeParticipantFailedEvent); + assertEquals("serverCallId", removeParticipantFailedEvent.getServerCallId()); + assertEquals("callConnectionId", removeParticipantFailedEvent.getCallConnectionId()); + assertEquals("rawId", removeParticipantFailedEvent.getParticipant().getRawId()); + } }