Skip to content

Commit 63bdc84

Browse files
minnieliuMinnie Liu
andauthored
[Communication] - Administration - Improve test coverage (Azure#17784)
* Added test coverage for Identity tests * Adding more unhappy test cases for TNM * Adding more test cases * Merge * Update recorded session * Decrease jacoco requirement * Decrease jacoco requirement * Fix identity test case * Decrease jacoco requirement * Decrease jacoco requirement * Testing jacoco coverage * Decrease jacoco requirement * test coverage in pipeline * Revert chat changes * Cleanup Co-authored-by: Minnie Liu <peiliu@microsoft.com>
1 parent 7417e79 commit 63bdc84

File tree

45 files changed

+1648
-691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1648
-691
lines changed

sdk/communication/azure-communication-administration/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
<properties>
5050
<src.dir>src/main</src.dir>
5151
<test.dir>src/test</test.dir>
52-
<jacoco.min.branchcoverage>0.10</jacoco.min.branchcoverage>
53-
<jacoco.min.linecoverage>0.10</jacoco.min.linecoverage>
52+
<jacoco.min.linecoverage>0.85</jacoco.min.linecoverage>
53+
<jacoco.min.branchcoverage>0.70</jacoco.min.branchcoverage>
5454
</properties>
5555

5656
<dependencies>
@@ -122,8 +122,8 @@
122122
<version>0.8.5</version> <!-- {x-version-update;org.jacoco:jacoco-maven-plugin;external_dependency} -->
123123
<configuration>
124124
<excludes>
125-
<exclude>com/azure/communication/administration/models/**/*</exclude>
126-
<exclude>com/azure/communication/administration/implementation/**/*</exclude>
125+
<exclude>com/azure/communication/**/models/**/*</exclude>
126+
<exclude>com/azure/communication/**/implementation/**/*</exclude>
127127
</excludes>
128128
</configuration>
129129
</plugin>

sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/CommunicationIdentityAsyncClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import java.time.OffsetDateTime;
2222
import java.util.List;
23+
import java.util.Objects;
24+
2325
import reactor.core.publisher.Mono;
2426

2527
import static com.azure.core.util.FluxUtil.monoError;
@@ -103,6 +105,7 @@ public Mono<Response<CommunicationUser>> createUser(Context context) {
103105
@ServiceMethod(returns = ReturnType.SINGLE)
104106
public Mono<Void> deleteUser(CommunicationUser communicationUser) {
105107
try {
108+
Objects.requireNonNull(communicationUser);
106109
return withContext(context -> deleteUser(communicationUser, context)
107110
.flatMap(
108111
(Response<Void> res) -> {
@@ -122,6 +125,7 @@ public Mono<Void> deleteUser(CommunicationUser communicationUser) {
122125
@ServiceMethod(returns = ReturnType.SINGLE)
123126
public Mono<Response<Void>> deleteUserWithResponse(CommunicationUser communicationUser) {
124127
try {
128+
Objects.requireNonNull(communicationUser);
125129
return withContext(context -> deleteUser(communicationUser, context));
126130
} catch (RuntimeException ex) {
127131
return monoError(logger, ex);
@@ -151,6 +155,7 @@ public Mono<Response<Void>> deleteUser(CommunicationUser communicationUser, Cont
151155
@ServiceMethod(returns = ReturnType.SINGLE)
152156
public Mono<Void> revokeTokens(CommunicationUser communicationUser, OffsetDateTime issuedBefore) {
153157
try {
158+
Objects.requireNonNull(communicationUser);
154159
return withContext(context -> revokeTokens(communicationUser, issuedBefore, context)
155160
.flatMap(
156161
(Response<Void> res) -> {
@@ -172,6 +177,7 @@ public Mono<Void> revokeTokens(CommunicationUser communicationUser, OffsetDateTi
172177
public Mono<Response<Void>> revokeTokensWithResponse(
173178
CommunicationUser communicationUser, OffsetDateTime issuedBefore) {
174179
try {
180+
Objects.requireNonNull(communicationUser);
175181
return withContext(context -> revokeTokens(communicationUser, issuedBefore, context));
176182
} catch (RuntimeException ex) {
177183
return monoError(logger, ex);
@@ -208,6 +214,8 @@ public Mono<Response<Void>> revokeTokens(
208214
public Mono<CommunicationUserToken> issueToken(
209215
CommunicationUser communicationUser, List<String> scopes) {
210216
try {
217+
Objects.requireNonNull(communicationUser);
218+
Objects.requireNonNull(scopes);
211219
return withContext(context -> issueToken(communicationUser, scopes, context)
212220
.flatMap(
213221
(Response<CommunicationUserToken> res) -> {
@@ -232,6 +240,8 @@ public Mono<CommunicationUserToken> issueToken(
232240
public Mono<Response<CommunicationUserToken>> issueTokenWithResponse(
233241
CommunicationUser communicationUser, List<String> scopes) {
234242
try {
243+
Objects.requireNonNull(communicationUser);
244+
Objects.requireNonNull(scopes);
235245
return withContext(context -> issueToken(communicationUser, scopes, context));
236246
} catch (RuntimeException ex) {
237247
return monoError(logger, ex);

sdk/communication/azure-communication-administration/src/main/java/com/azure/communication/administration/PhoneNumberAsyncClient.java

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public Mono<Response<AreaCodes>> getAllAreaCodesWithResponse(
126126
Mono<Response<AreaCodes>> getAllAreaCodesWithResponse(
127127
String locationType, String countryCode, String phonePlanId, List<LocationOptionsQuery> locationOptions,
128128
Context context) {
129-
Objects.requireNonNull(locationType, "'locationType' cannot be null.");
130-
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
131-
Objects.requireNonNull(phonePlanId, "'phonePlanId' cannot be null.");
132129

133130
LocationOptionsQueries locationOptionsQueries = new LocationOptionsQueries();
134131
locationOptionsQueries.setLocationOptions(locationOptions);
135132

136133
try {
134+
Objects.requireNonNull(locationType, "'locationType' cannot be null.");
135+
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
136+
Objects.requireNonNull(phonePlanId, "'phonePlanId' cannot be null.");
137137
if (context == null) {
138138
return phoneNumberAdministrations.getAllAreaCodesWithResponseAsync(
139139
locationType, countryCode, phonePlanId, locationOptionsQueries);
@@ -173,9 +173,8 @@ public Mono<Response<UpdatePhoneNumberCapabilitiesResponse>> getCapabilitiesUpda
173173

174174
Mono<Response<UpdatePhoneNumberCapabilitiesResponse>> getCapabilitiesUpdateWithResponse(
175175
String capabilitiesId, Context context) {
176-
Objects.requireNonNull(capabilitiesId, "'capabilitiesId' cannot be null.");
177-
178176
try {
177+
Objects.requireNonNull(capabilitiesId, "'capabilitiesId' cannot be null.");
179178
if (context == null) {
180179
return phoneNumberAdministrations.getCapabilitiesUpdateWithResponseAsync(capabilitiesId);
181180
} else {
@@ -214,17 +213,15 @@ public Mono<Response<UpdateNumberCapabilitiesResponse>> updateCapabilitiesWithRe
214213

215214
Mono<Response<UpdateNumberCapabilitiesResponse>> updateCapabilitiesWithResponse(
216215
Map<PhoneNumber, NumberUpdateCapabilities> phoneNumberCapabilitiesUpdate, Context context) {
217-
Objects.requireNonNull(phoneNumberCapabilitiesUpdate, "'phoneNumberCapabilitiesUpdate' cannot be null.");
218-
219-
Map<String, NumberUpdateCapabilities> capabilitiesMap = new HashMap<>();
220-
for (Map.Entry<PhoneNumber, NumberUpdateCapabilities> entry : phoneNumberCapabilitiesUpdate.entrySet()) {
221-
capabilitiesMap.put(entry.getKey().getValue(), entry.getValue());
222-
}
223-
224-
UpdateNumberCapabilitiesRequest updateNumberCapabilitiesRequest = new UpdateNumberCapabilitiesRequest();
225-
updateNumberCapabilitiesRequest.setPhoneNumberCapabilitiesUpdate(capabilitiesMap);
226-
227216
try {
217+
Objects.requireNonNull(phoneNumberCapabilitiesUpdate, "'phoneNumberCapabilitiesUpdate' cannot be null.");
218+
Map<String, NumberUpdateCapabilities> capabilitiesMap = new HashMap<>();
219+
for (Map.Entry<PhoneNumber, NumberUpdateCapabilities> entry : phoneNumberCapabilitiesUpdate.entrySet()) {
220+
capabilitiesMap.put(entry.getKey().getValue(), entry.getValue());
221+
}
222+
UpdateNumberCapabilitiesRequest updateNumberCapabilitiesRequest = new UpdateNumberCapabilitiesRequest();
223+
updateNumberCapabilitiesRequest.setPhoneNumberCapabilitiesUpdate(capabilitiesMap);
224+
228225
if (context == null) {
229226
return phoneNumberAdministrations.updateCapabilitiesWithResponseAsync(
230227
updateNumberCapabilitiesRequest);
@@ -285,12 +282,11 @@ public Mono<Response<NumberConfigurationResponse>> getNumberConfigurationWithRes
285282

286283
Mono<Response<NumberConfigurationResponse>> getNumberConfigurationWithResponse(
287284
PhoneNumber phoneNumber, Context context) {
288-
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
289-
290-
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
291-
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
292-
293285
try {
286+
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
287+
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
288+
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
289+
294290
if (context == null) {
295291
return phoneNumberAdministrations.getNumberConfigurationWithResponseAsync(
296292
configurationPhoneNumber);
@@ -330,13 +326,13 @@ public Mono<Response<Void>> configureNumberWithResponse(
330326

331327
Mono<Response<Void>> configureNumberWithResponse(
332328
PhoneNumber phoneNumber, PstnConfiguration pstnConfiguration, Context context) {
333-
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
334-
Objects.requireNonNull(pstnConfiguration, "'pstnConfiguration' cannot be null.");
335-
336-
NumberConfiguration numberConfiguration = new NumberConfiguration();
337-
numberConfiguration.setPhoneNumber(phoneNumber.getValue()).setPstnConfiguration(pstnConfiguration);
338-
339329
try {
330+
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
331+
Objects.requireNonNull(pstnConfiguration, "'pstnConfiguration' cannot be null.");
332+
333+
NumberConfiguration numberConfiguration = new NumberConfiguration();
334+
numberConfiguration.setPhoneNumber(phoneNumber.getValue()).setPstnConfiguration(pstnConfiguration);
335+
340336
if (context == null) {
341337
return phoneNumberAdministrations.configureNumberWithResponseAsync(numberConfiguration);
342338
} else {
@@ -370,11 +366,11 @@ public Mono<Response<Void>> unconfigureNumberWithResponse(PhoneNumber phoneNumbe
370366
}
371367

372368
Mono<Response<Void>> unconfigureNumberWithResponse(PhoneNumber phoneNumber, Context context) {
373-
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
374-
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
375-
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
376-
377369
try {
370+
Objects.requireNonNull(phoneNumber, "'phoneNumber' cannot be null.");
371+
NumberConfigurationPhoneNumber configurationPhoneNumber = new NumberConfigurationPhoneNumber();
372+
configurationPhoneNumber.setPhoneNumber(phoneNumber.getValue());
373+
378374
if (context == null) {
379375
return phoneNumberAdministrations.unconfigureNumberWithResponseAsync(configurationPhoneNumber);
380376
} else {
@@ -401,9 +397,8 @@ public PagedFlux<PhonePlanGroup> listPhonePlanGroups(
401397

402398
PagedFlux<PhonePlanGroup> listPhonePlanGroups(
403399
String countryCode, String locale, Boolean includeRateInformation, Context context) {
404-
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
405-
406400
try {
401+
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
407402
if (context == null) {
408403
return phoneNumberAdministrations.getPhonePlanGroupsAsync(
409404
countryCode, locale, includeRateInformation, null, null);
@@ -430,10 +425,9 @@ public PagedFlux<PhonePlan> listPhonePlans(String countryCode, String phonePlanG
430425
}
431426

432427
PagedFlux<PhonePlan> listPhonePlans(String countryCode, String phonePlanGroupId, String locale, Context context) {
433-
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
434-
Objects.requireNonNull(phonePlanGroupId, "'phonePlanGroupId' cannot be null.");
435-
436428
try {
429+
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
430+
Objects.requireNonNull(phonePlanGroupId, "'phonePlanGroupId' cannot be null.");
437431
if (context == null) {
438432
return phoneNumberAdministrations.getPhonePlansAsync(
439433
countryCode, phonePlanGroupId, locale, null, null);
@@ -481,11 +475,11 @@ public Mono<Response<LocationOptionsResponse>> getPhonePlanLocationOptionsWithRe
481475

482476
Mono<Response<LocationOptionsResponse>> getPhonePlanLocationOptionsWithResponse(
483477
String countryCode, String phonePlanGroupId, String phonePlanId, String locale, Context context) {
484-
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
485-
Objects.requireNonNull(phonePlanGroupId, "'phonePlanGroupId' cannot be null.");
486-
Objects.requireNonNull(phonePlanId, "'phonePlanId' cannot be null.");
487-
488478
try {
479+
Objects.requireNonNull(countryCode, "'countryCode' cannot be null.");
480+
Objects.requireNonNull(phonePlanGroupId, "'phonePlanGroupId' cannot be null.");
481+
Objects.requireNonNull(phonePlanId, "'phonePlanId' cannot be null.");
482+
489483
if (context == null) {
490484
return phoneNumberAdministrations.getPhonePlanLocationOptionsWithResponseAsync(
491485
countryCode, phonePlanGroupId, phonePlanId, locale);
@@ -522,9 +516,8 @@ public Mono<Response<PhoneNumberRelease>> getReleaseByIdWithResponse(String rele
522516
}
523517

524518
Mono<Response<PhoneNumberRelease>> getReleaseByIdWithResponse(String releaseId, Context context) {
525-
Objects.requireNonNull(releaseId, "'releaseId' cannot be null.");
526-
527519
try {
520+
Objects.requireNonNull(releaseId, "'releaseId' cannot be null.");
528521
if (context == null) {
529522
return phoneNumberAdministrations.getReleaseByIdWithResponseAsync(releaseId);
530523
} else {
@@ -621,9 +614,8 @@ public Mono<Response<PhoneNumberReservation>> getReservationByIdWithResponse(Str
621614
}
622615

623616
Mono<Response<PhoneNumberReservation>> getReservationByIdWithResponse(String reservationId, Context context) {
624-
Objects.requireNonNull(reservationId, "'ReservationId' cannot be null.");
625-
626617
try {
618+
Objects.requireNonNull(reservationId, "'reservationId' cannot be null.");
627619
if (context == null) {
628620
return phoneNumberAdministrations.getSearchByIdWithResponseAsync(reservationId);
629621
} else {
@@ -658,9 +650,9 @@ private Mono<Response<CreateReservationResponse>> createReservationWithResponse(
658650

659651
private Mono<Response<CreateReservationResponse>> createReservationWithResponse(
660652
CreateReservationOptions reservationOptions, Context context) {
661-
Objects.requireNonNull(reservationOptions, "'reservationOptions' cannot be null.");
662-
663653
try {
654+
Objects.requireNonNull(reservationOptions, "'reservationOptions' cannot be null.");
655+
664656
if (context == null) {
665657
return phoneNumberAdministrations.createSearchWithResponseAsync(reservationOptions);
666658
} else {
@@ -716,9 +708,9 @@ public Mono<Response<Void>> cancelReservationWithResponse(String reservationId)
716708
}
717709

718710
Mono<Response<Void>> cancelReservationWithResponse(String reservationId, Context context) {
719-
Objects.requireNonNull(reservationId, "'ReservationId' cannot be null.");
720-
721711
try {
712+
Objects.requireNonNull(reservationId, "'ReservationId' cannot be null.");
713+
722714
if (context == null) {
723715
return phoneNumberAdministrations.cancelSearchWithResponseAsync(reservationId);
724716
} else {
@@ -750,9 +742,8 @@ private Mono<Response<Void>> purchaseReservationWithResponse(String reservationI
750742
}
751743

752744
private Mono<Response<Void>> purchaseReservationWithResponse(String reservationId, Context context) {
753-
Objects.requireNonNull(reservationId, "'reservationId' cannot be null.");
754-
755745
try {
746+
Objects.requireNonNull(reservationId, "'reservationId' cannot be null.");
756747
if (context == null) {
757748
return phoneNumberAdministrations.purchaseSearchWithResponseAsync(reservationId);
758749
} else {

sdk/communication/azure-communication-administration/src/test/java/com/azure/communication/administration/CommunicationIdentityAsyncTests.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ public void deleteUserWithResponse(HttpClient httpClient) {
130130
.verifyComplete();
131131
}
132132

133+
@ParameterizedTest
134+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
135+
public void deleteUserWithNullUser(HttpClient httpClient) {
136+
// Arrange
137+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
138+
139+
// Action & Assert
140+
StepVerifier.create(
141+
asyncClient.deleteUser(null))
142+
.verifyError(NullPointerException.class);
143+
}
144+
145+
@ParameterizedTest
146+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
147+
public void deleteUserWithResponseWithNullUser(HttpClient httpClient) {
148+
// Arrange
149+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
150+
151+
// Action & Assert
152+
StepVerifier.create(
153+
asyncClient.deleteUserWithResponse(null))
154+
.verifyError(NullPointerException.class);
155+
}
156+
133157
@ParameterizedTest
134158
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
135159
public void revokeToken(HttpClient httpClient) {
@@ -171,6 +195,31 @@ public void revokeTokenWithResponse(HttpClient httpClient) {
171195
.verifyComplete();
172196
}
173197

198+
@ParameterizedTest
199+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
200+
public void revokeTokenWithNullUser(HttpClient httpClient) {
201+
// Arrange
202+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
203+
204+
// Action & Assert
205+
StepVerifier.create(
206+
asyncClient.revokeTokens(null, null))
207+
.verifyError(NullPointerException.class);
208+
}
209+
210+
@ParameterizedTest
211+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
212+
public void revokeTokenWithResponseWithNullUser(HttpClient httpClient) {
213+
// Arrange
214+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
215+
216+
// Action & Assert
217+
StepVerifier.create(
218+
asyncClient.revokeTokensWithResponse(null, null))
219+
.verifyError(NullPointerException.class);
220+
}
221+
222+
174223
@ParameterizedTest
175224
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
176225
public void issueToken(HttpClient httpClient) {
@@ -216,4 +265,41 @@ public void issueTokenWithResponse(HttpClient httpClient) {
216265
})
217266
.verifyComplete();
218267
}
268+
269+
@ParameterizedTest
270+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
271+
public void issueTokenWithNullUser(HttpClient httpClient) {
272+
// Arrange
273+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
274+
List<String> scopes = new ArrayList<>(Arrays.asList("chat"));
275+
276+
// Action & Assert
277+
StepVerifier.create(
278+
asyncClient.issueToken(null, scopes))
279+
.verifyError(NullPointerException.class);
280+
}
281+
282+
@ParameterizedTest
283+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
284+
public void issueTokenWithNullScope(HttpClient httpClient) {
285+
// Arrange
286+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
287+
288+
// Action & Assert
289+
StepVerifier.create(asyncClient.issueToken(new CommunicationUser("testUser"), null))
290+
.verifyError(NullPointerException.class);
291+
}
292+
293+
@ParameterizedTest
294+
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
295+
public void issueTokenWithResponseWithNullUser(HttpClient httpClient) {
296+
// Arrange
297+
asyncClient = getCommunicationIdentityClient(httpClient).buildAsyncClient();
298+
List<String> scopes = new ArrayList<>(Arrays.asList("chat"));
299+
300+
// Action & Assert
301+
StepVerifier.create(
302+
asyncClient.issueTokenWithResponse(null, scopes))
303+
.verifyError(NullPointerException.class);
304+
}
219305
}

0 commit comments

Comments
 (0)