Skip to content

Commit 4b563f6

Browse files
add event handler for remove participant events (Azure#34165)
1 parent fb8215a commit 4b563f6

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.azure.communication.callautomation.models.events.RecognizeFailed;
1919
import com.azure.communication.callautomation.models.events.PlayCompleted;
2020
import com.azure.communication.callautomation.models.events.RecordingStateChanged;
21+
import com.azure.communication.callautomation.models.events.RemoveParticipantFailed;
22+
import com.azure.communication.callautomation.models.events.RemoveParticipantSucceeded;
2123
import com.azure.core.models.CloudEvent;
2224
import com.azure.core.util.logging.ClientLogger;
2325
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -121,8 +123,11 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
121123
ret = mapper.convertValue(eventData, RecognizeFailed.class);
122124
} else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeCanceled")) {
123125
ret = mapper.convertValue(eventData, RecognizeCanceled.class);
126+
} else if (Objects.equals(eventType, "Microsoft.Communication.RemoveParticipantFailed")) {
127+
ret = mapper.convertValue(eventData, RemoveParticipantFailed.class);
128+
} else if (Objects.equals(eventType, "Microsoft.Communication.RemoveParticipantSucceeded")) {
129+
ret = mapper.convertValue(eventData, RemoveParticipantSucceeded.class);
124130
}
125-
126131
return ret;
127132
} catch (RuntimeException e) {
128133
throw LOGGER.logExceptionAsError(e);

sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/EventHandlerUnitTests.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.azure.communication.callautomation.models.events.CallConnected;
1919
import com.azure.communication.callautomation.models.events.RecognizeFailed;
2020
import com.azure.communication.callautomation.models.events.RecordingStateChanged;
21+
import com.azure.communication.callautomation.models.events.RemoveParticipantFailed;
22+
import com.azure.communication.callautomation.models.events.RemoveParticipantSucceeded;
2123
import com.azure.communication.callautomation.models.events.ReasonCode.Recognize;
2224

2325
import org.junit.jupiter.api.Test;
@@ -260,4 +262,76 @@ public void parseRecognizeCanceledEvent() {
260262
assertNotNull(recognizeCanceledEvent);
261263
assertEquals("serverCallId", recognizeCanceledEvent.getServerCallId());
262264
}
265+
266+
@Test
267+
public void parseRemoveParticipantSucceededEvent() {
268+
String receivedEvent = "[{\n"
269+
+ "\"id\": \"c3220fa3-79bd-473e-96a2-3ecb5be7d71f\",\n"
270+
+ "\"source\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\",\n"
271+
+ "\"type\": \"Microsoft.Communication.RemoveParticipantSucceeded\",\n"
272+
+ "\"data\": {\n"
273+
+ "\"operationContext\": \"context\",\n"
274+
+ "\"participant\": {\n"
275+
+ "\"rawId\": \"rawId\",\n"
276+
+ "\"phoneNumber\": {\n"
277+
+ "\"value\": \"value\"\n"
278+
+ "}\n"
279+
+ "},\n"
280+
+ "\"callConnectionId\": \"callConnectionId\",\n"
281+
+ "\"serverCallId\": \"serverCallId\",\n"
282+
+ "\"correlationId\": \"b880bd5a-1916-470a-b43d-aabf3caff91c\"\n"
283+
+ "},\n"
284+
+ "\"time\": \"2023-03-22T16:57:09.287755+00:00\",\n"
285+
+ "\"specversion\": \"1.0\",\n"
286+
+ "\"datacontenttype\": \"application/json\",\n"
287+
+ "\"subject\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\"\n"
288+
+ "}]";
289+
290+
CallAutomationEventBase event = EventHandler.parseEvent(receivedEvent);
291+
292+
assertNotNull(event);
293+
294+
RemoveParticipantSucceeded removeParticipantSucceededEvent = (RemoveParticipantSucceeded) event;
295+
296+
assertNotNull(removeParticipantSucceededEvent);
297+
assertEquals("serverCallId", removeParticipantSucceededEvent.getServerCallId());
298+
assertEquals("callConnectionId", removeParticipantSucceededEvent.getCallConnectionId());
299+
assertEquals("rawId", removeParticipantSucceededEvent.getParticipant().getRawId());
300+
}
301+
302+
@Test
303+
public void parseRemoveParticipantFailedEvent() {
304+
String receivedEvent = "[{\n"
305+
+ "\"id\": \"c3220fa3-79bd-473e-96a2-3ecb5be7d71f\",\n"
306+
+ "\"source\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\",\n"
307+
+ "\"type\": \"Microsoft.Communication.RemoveParticipantFailed\",\n"
308+
+ "\"data\": {\n"
309+
+ "\"operationContext\": \"context\",\n"
310+
+ "\"participant\": {\n"
311+
+ "\"rawId\": \"rawId\",\n"
312+
+ "\"phoneNumber\": {\n"
313+
+ "\"value\": \"value\"\n"
314+
+ "}\n"
315+
+ "},\n"
316+
+ "\"callConnectionId\": \"callConnectionId\",\n"
317+
+ "\"serverCallId\": \"serverCallId\",\n"
318+
+ "\"correlationId\": \"b880bd5a-1916-470a-b43d-aabf3caff91c\"\n"
319+
+ "},\n"
320+
+ "\"time\": \"2023-03-22T16:57:09.287755+00:00\",\n"
321+
+ "\"specversion\": \"1.0\",\n"
322+
+ "\"datacontenttype\": \"application/json\",\n"
323+
+ "\"subject\": \"calling/callConnections/421f3500-f5de-4c12-bf61-9e2641433687\"\n"
324+
+ "}]";
325+
326+
CallAutomationEventBase event = EventHandler.parseEvent(receivedEvent);
327+
328+
assertNotNull(event);
329+
330+
RemoveParticipantFailed removeParticipantFailedEvent = (RemoveParticipantFailed) event;
331+
332+
assertNotNull(removeParticipantFailedEvent);
333+
assertEquals("serverCallId", removeParticipantFailedEvent.getServerCallId());
334+
assertEquals("callConnectionId", removeParticipantFailedEvent.getCallConnectionId());
335+
assertEquals("rawId", removeParticipantFailedEvent.getParticipant().getRawId());
336+
}
263337
}

0 commit comments

Comments
 (0)