Skip to content

Commit f407685

Browse files
authored
Modify Unit tests to increase test coverage (Azure#36146)
* Modifying tets to increase coverage * updating assets.json * Minor Nits
1 parent 5687bd1 commit f407685

File tree

4 files changed

+75
-42
lines changed

4 files changed

+75
-42
lines changed

sdk/communication/azure-communication-rooms/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/communication/azure-communication-rooms",
5-
"Tag": "java/communication/azure-communication-rooms_a38c3e2f08"
5+
"Tag": "java/communication/azure-communication-rooms_3c1e55016f"
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.communication.rooms;
5+
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
import static org.junit.jupiter.api.Assertions.assertNull;
8+
9+
import java.time.OffsetDateTime;
10+
11+
import org.junit.jupiter.api.Test;
12+
13+
import com.azure.communication.rooms.implementation.converters.ParticipantRoleConverter;
14+
import com.azure.communication.rooms.implementation.converters.RoomModelConverter;
15+
16+
public class ConverterTests {
17+
18+
@Test
19+
void testConvertRoomModel() {
20+
com.azure.communication.rooms.implementation.models.RoomModel room = new com.azure.communication.rooms.implementation.models.RoomModel();
21+
room.setId("12345");
22+
room.setValidFrom(OffsetDateTime.now());
23+
room.setValidUntil(OffsetDateTime.now().plusMonths(2));
24+
assertNotNull(RoomModelConverter.convert(room));
25+
room = null;
26+
assertNull(RoomModelConverter.convert(room));
27+
}
28+
29+
@Test
30+
void testConvertRoomParticipantRole() {
31+
com.azure.communication.rooms.implementation.models.ParticipantRole role = com.azure.communication.rooms.implementation.models.ParticipantRole.ATTENDEE;
32+
assertNotNull(ParticipantRoleConverter.convert(role));
33+
role = null;
34+
assertNull(ParticipantRoleConverter.convert(role));
35+
}
36+
}

sdk/communication/azure-communication-rooms/src/test/java/com/azure/communication/rooms/RoomsAsyncClientTests.java

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package com.azure.communication.rooms;
55

66
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertFalse;
78
import static org.junit.jupiter.api.Assertions.assertNotNull;
89
import static org.junit.jupiter.api.Assertions.assertThrows;
910

@@ -80,7 +81,7 @@ public void createRoomFullCycleWithResponseStep(HttpClient httpClient) {
8081
assertHappyPath(roomResult, 200);
8182
}).verifyComplete();
8283

83-
Mono<Response<CommunicationRoom>> response4 = roomsAsyncClient.getRoomWithResponse(roomId);
84+
Mono<Response<CommunicationRoom>> response4 = roomsAsyncClient.getRoomWithResponse(roomId, null);
8485

8586
StepVerifier.create(response4)
8687
.assertNext(result4 -> {
@@ -140,12 +141,8 @@ public void createRoomFullCycleWithOutResponseStep(HttpClient httpClient) {
140141
assertEquals(result4.getRoomId(), roomId);
141142
}).verifyComplete();
142143

143-
Mono<Response<Void>> response5 = roomsAsyncClient.deleteRoomWithResponse(roomId);
144-
StepVerifier.create(response5)
145-
.assertNext(result5 -> {
146-
assertEquals(result5.getStatusCode(), 204);
147-
}).verifyComplete();
148-
144+
Mono<Void> response5 = roomsAsyncClient.deleteRoom(roomId, null);
145+
StepVerifier.create(response5).verifyComplete();
149146
}
150147

151148
@ParameterizedTest
@@ -210,7 +207,7 @@ public void createRoomWithOnlyParticipantAttributes(HttpClient httpClient) {
210207

211208
String roomId = response1.block().getRoomId();
212209

213-
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId);
210+
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId, null);
214211
StepVerifier.create(response2)
215212
.assertNext(result2 -> {
216213
assertEquals(result2.getStatusCode(), 204);
@@ -234,9 +231,9 @@ public void createRoomWithValidUntilInPast(HttpClient httpClient) {
234231

235232
CommunicationErrorResponseException exception =
236233
assertThrows(CommunicationErrorResponseException.class, () -> {
237-
roomsAsyncClient.createRoomWithResponse(roomOptions, Context.NONE).block();
234+
roomsAsyncClient.createRoomWithResponse(roomOptions, null).block();
238235
});
239-
assertEquals(400, exception.getResponse().getStatusCode());
236+
assertEquals("BadRequest", exception.getValue().getError().getCode());
240237
}
241238

242239
@ParameterizedTest
@@ -255,7 +252,7 @@ public void createRoomWithValidUntilGreaterThan180(HttpClient httpClient) {
255252
assertThrows(CommunicationErrorResponseException.class, () -> {
256253
roomsAsyncClient.createRoomWithResponse(createRoomOptions, Context.NONE).block();
257254
});
258-
assertEquals(400, exception.getResponse().getStatusCode());
255+
assertEquals("BadRequest", exception.getValue().getError().getCode());
259256
}
260257

261258
@ParameterizedTest
@@ -274,7 +271,7 @@ public void createRoomWithOnlyValidFromGreaterThan180(HttpClient httpClient) {
274271
assertThrows(CommunicationErrorResponseException.class, () -> {
275272
roomsAsyncClient.createRoomWithResponse(createRoomOptions, Context.NONE).block();
276273
});
277-
assertEquals(400, exception.getResponse().getStatusCode());
274+
assertEquals("BadRequest", exception.getValue().getError().getCode());
278275
}
279276

280277
@ParameterizedTest
@@ -295,7 +292,8 @@ public void createRoomWithBadParticipantMri(HttpClient httpClient) {
295292
assertThrows(CommunicationErrorResponseException.class, () -> {
296293
roomsAsyncClient.createRoomWithResponse(roomOptions, Context.NONE).block();
297294
});
298-
assertEquals(400, exception.getResponse().getStatusCode());
295+
assertEquals("BadRequest", exception.getValue().getError().getCode());
296+
assertFalse(exception.getValue().getError().getMessage().isEmpty());
299297
}
300298

301299
@ParameterizedTest
@@ -308,7 +306,8 @@ public void getRoomWithUnexistingRoomIdReturnBadRequest(HttpClient httpClient) {
308306
assertThrows(CommunicationErrorResponseException.class, () -> {
309307
roomsAsyncClient.getRoom(nonExistRoomId).block();
310308
});
311-
assertEquals(400, exception.getResponse().getStatusCode());
309+
assertEquals("BadRequest", exception.getValue().getError().getCode());
310+
assertFalse(exception.getValue().getError().getMessage().isEmpty());
312311
}
313312

314313
@ParameterizedTest
@@ -322,7 +321,7 @@ public void updateRoomValidUntilGreaterThan180(HttpClient httpClient) {
322321
.setValidFrom(VALID_FROM)
323322
.setValidUntil(VALID_UNTIL);
324323

325-
Mono<Response<CommunicationRoom>> response1 = roomsAsyncClient.createRoomWithResponse(createRoomOptions);
324+
Mono<Response<CommunicationRoom>> response1 = roomsAsyncClient.createRoomWithResponse(createRoomOptions, null);
326325

327326
StepVerifier.create(response1)
328327
.assertNext(roomResult -> {
@@ -338,15 +337,12 @@ public void updateRoomValidUntilGreaterThan180(HttpClient httpClient) {
338337

339338
CommunicationErrorResponseException exception =
340339
assertThrows(CommunicationErrorResponseException.class, () -> {
341-
roomsAsyncClient.updateRoom(roomId, updateRoomOptions).block();
340+
roomsAsyncClient.updateRoom(roomId, updateRoomOptions, null).block();
342341
});
343-
assertEquals(400, exception.getResponse().getStatusCode());
342+
assertEquals("BadRequest", exception.getValue().getError().getCode());
344343

345-
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId);
346-
StepVerifier.create(response2)
347-
.assertNext(result2 -> {
348-
assertEquals(result2.getStatusCode(), 204);
349-
}).verifyComplete();
344+
Mono<Void> response5 = roomsAsyncClient.deleteRoom(roomId, null);
345+
StepVerifier.create(response5).verifyComplete();
350346
}
351347

352348
@ParameterizedTest
@@ -378,7 +374,7 @@ public void updateRoomValidFromGreaterThan180(HttpClient httpClient) {
378374
assertThrows(CommunicationErrorResponseException.class, () -> {
379375
roomsAsyncClient.updateRoom(roomId, updateRoomOptions).block();
380376
});
381-
assertEquals(400, exception.getResponse().getStatusCode());
377+
assertEquals("BadRequest", exception.getValue().getError().getCode());
382378

383379
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId);
384380
StepVerifier.create(response2)
@@ -416,7 +412,7 @@ public void updateRoomValidUntilInPast(HttpClient httpClient) {
416412
assertThrows(CommunicationErrorResponseException.class, () -> {
417413
roomsAsyncClient.updateRoom(roomId, updateRoomOptions).block();
418414
});
419-
assertEquals(400, exception.getResponse().getStatusCode());
415+
assertEquals("BadRequest", exception.getValue().getError().getCode());
420416

421417
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId);
422418
StepVerifier.create(response2)
@@ -454,7 +450,7 @@ public void updateRoomWithInvalidRoomId(HttpClient httpClient) {
454450
assertThrows(CommunicationErrorResponseException.class, () -> {
455451
roomsAsyncClient.updateRoom(roomId, updateRoomOptions).block();
456452
});
457-
assertEquals(400, exception.getResponse().getStatusCode());
453+
assertEquals("BadRequest", exception.getValue().getError().getCode());
458454

459455
Mono<Response<Void>> response2 = roomsAsyncClient.deleteRoomWithResponse(roomId);
460456
StepVerifier.create(response2)
@@ -503,10 +499,10 @@ public void addUpdateAndRemoveParticipantsOperationsWithFullFlow(HttpClient http
503499
List<RoomParticipant> participants = Arrays.asList(firstParticipant, secondParticipant, thirdParticipant);
504500

505501
// Add 3 participants.
506-
AddOrUpdateParticipantsResult addParticipantResponse = roomsAsyncClient.addOrUpdateParticipants(roomId, participants).block();
502+
AddOrUpdateParticipantsResult addParticipantResponse = roomsAsyncClient.addOrUpdateParticipants(roomId, participants, null).block();
507503

508504
// Check participant count, expected 3
509-
PagedFlux<RoomParticipant> listParticipantsResponse2 = roomsAsyncClient.listParticipants(roomId);
505+
PagedFlux<RoomParticipant> listParticipantsResponse2 = roomsAsyncClient.listParticipants(roomId, null);
510506

511507
StepVerifier.create(listParticipantsResponse2.count())
512508
.expectNext(3L)
@@ -559,12 +555,12 @@ public void addUpdateAndRemoveParticipantsOperationsWithFullFlow(HttpClient http
559555
secondParticipant.getCommunicationIdentifier());
560556

561557
// Remove 2 participants
562-
Mono<RemoveParticipantsResult> removeParticipantResponse = roomsAsyncClient.removeParticipants(roomId,
563-
participantsIdentifiersForParticipants);
558+
Mono<Response<RemoveParticipantsResult>> removeParticipantResponse = roomsAsyncClient.removeParticipantsWithResponse(roomId,
559+
participantsIdentifiersForParticipants, null);
564560

565561
StepVerifier.create(removeParticipantResponse)
566562
.assertNext(result -> {
567-
assertEquals(true, result instanceof RemoveParticipantsResult);
563+
assertEquals(result.getStatusCode(), 200);
568564
})
569565
.verifyComplete();
570566

@@ -582,7 +578,8 @@ public void addUpdateAndRemoveParticipantsOperationsWithFullFlow(HttpClient http
582578
assertThrows(CommunicationErrorResponseException.class, () -> {
583579
roomsAsyncClient.removeParticipants(roomId, participantsIdentifiersForNonExistentParticipant).block();
584580
});
585-
assertEquals(400, exception.getResponse().getStatusCode());
581+
assertEquals("BadRequest", exception.getValue().getError().getCode());
582+
assertFalse(exception.getValue().getError().getMessage().isEmpty());
586583

587584
// Remove Non-existent participants
588585
Mono<RemoveParticipantsResult> removeParticipantResponse2 = roomsAsyncClient.removeParticipants(roomId,
@@ -739,7 +736,7 @@ public void listRoomTestFirstRoomIsNotNullThenDeleteRoomWithOutResponse(HttpClie
739736
String roomId = createCommunicationRoom.block().getRoomId();
740737

741738
//Get created rooms
742-
PagedFlux<CommunicationRoom> listRoomResponse = roomsAsyncClient.listRooms();
739+
PagedFlux<CommunicationRoom> listRoomResponse = roomsAsyncClient.listRooms(null);
743740

744741
StepVerifier.create(listRoomResponse.take(1))
745742
.assertNext(room -> {
@@ -821,7 +818,7 @@ public void updateParticipantsToDefaultRoleWithResponseStep(HttpClient httpClien
821818
.asList(new RoomParticipant(firstParticipant.getCommunicationIdentifier()));
822819

823820
Mono<Response<AddOrUpdateParticipantsResult>> response2 = roomsAsyncClient
824-
.addOrUpdateParticipantsWithResponse(roomId, participantToUpdate);
821+
.addOrUpdateParticipantsWithResponse(roomId, participantToUpdate, null);
825822

826823
StepVerifier.create(response2)
827824
.assertNext(result2 -> {

sdk/communication/azure-communication-rooms/src/test/java/com/azure/communication/rooms/RoomsClientTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void createRoomSyncWithFullOperationWithResponse(HttpClient httpClient) {
100100
.setValidUntil(VALID_UNTIL);
101101

102102
Response<CommunicationRoom> createdRoomResponse = roomsClient.createRoomWithResponse(createRoomOptions,
103-
Context.NONE);
103+
null);
104104
assertHappyPath(createdRoomResponse, 201);
105105

106106
String roomId = createdRoomResponse.getValue().getRoomId();
@@ -110,13 +110,13 @@ public void createRoomSyncWithFullOperationWithResponse(HttpClient httpClient) {
110110
.setValidUntil(VALID_FROM.plusMonths(4));
111111

112112
Response<CommunicationRoom> updateRoomResponse = roomsClient.updateRoomWithResponse(roomId, updateRoomOptions,
113-
Context.NONE);
113+
null);
114114
assertHappyPath(updateRoomResponse, 200);
115115

116-
Response<CommunicationRoom> getRoomResponse = roomsClient.getRoomWithResponse(roomId, Context.NONE);
116+
Response<CommunicationRoom> getRoomResponse = roomsClient.getRoomWithResponse(roomId, null);
117117
assertHappyPath(getRoomResponse, 200);
118118

119-
Response<Void> deleteResponse = roomsClient.deleteRoomWithResponse(roomId, Context.NONE);
119+
Response<Void> deleteResponse = roomsClient.deleteRoomWithResponse(roomId, null);
120120
assertEquals(deleteResponse.getStatusCode(), 204);
121121
}
122122

@@ -137,7 +137,7 @@ public void listRoomTestFirstRoomIsNotNullThenDeleteRoomWithOutResponse(HttpClie
137137

138138
String roomId = createCommunicationRoom.getRoomId();
139139

140-
// Check created room coun
140+
// Check created room count
141141
PagedIterable<CommunicationRoom> listRoomResponse = roomsClient.listRooms();
142142

143143
Iterable<PagedResponse<CommunicationRoom>> rooms = listRoomResponse.iterableByPage(1);
@@ -165,7 +165,7 @@ public void addUpdateAndRemoveParticipantsOperationsSyncWithFullFlow(HttpClient
165165
String roomId = createCommunicationRoom.getRoomId();
166166

167167
// Check participant count, expected 0
168-
PagedIterable<RoomParticipant> listParticipantsResponse1 = roomsClient.listParticipants(roomId);
168+
PagedIterable<RoomParticipant> listParticipantsResponse1 = roomsClient.listParticipants(roomId, null);
169169
assertEquals(0, listParticipantsResponse1.stream().count());
170170

171171
// Create 3 participants
@@ -210,7 +210,7 @@ public void addUpdateAndRemoveParticipantsOperationsSyncWithFullFlow(HttpClient
210210
secondParticipant.getCommunicationIdentifier());
211211

212212
// Remove 2 participants
213-
roomsClient.removeParticipants(roomId, participantsIdentifiersForParticipants);
213+
roomsClient.removeParticipantsWithResponse(roomId, participantsIdentifiersForParticipants, null);
214214

215215
// Check participant count, expected 1
216216
PagedIterable<RoomParticipant> listParticipantsResponse4 = roomsClient.listParticipants(roomId);
@@ -877,7 +877,7 @@ public void addUpdateInvalidParticipants(HttpClient httpClient) {
877877
String roomId = createdRoom.getRoomId();
878878

879879
// Check participant count, expected 0
880-
PagedIterable<CommunicationRoom> listRoomResponse = roomsClient.listRooms();
880+
PagedIterable<CommunicationRoom> listRoomResponse = roomsClient.listRooms(null);
881881

882882
PagedIterable<RoomParticipant> listParticipantsResponse1 = roomsClient.listParticipants(roomId);
883883
assertEquals(0, listParticipantsResponse1.stream().count());

0 commit comments

Comments
 (0)