Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add event handler for remove participant events #34165

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}