Skip to content

Commit

Permalink
[SELC-6461] fix: roles and status params can be null in getUserCount (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetano-miglionico authored Feb 7, 2025
1 parent 0b56f6c commit 0010a15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public UserCountResource getUserCount(@ApiParam("${swagger.dashboard.institution
@ApiParam(value = "${swagger.dashboard.user.model.statusList}")
@RequestParam(name = "status", required = false) String[] status) {
log.trace("getUserCount start");
UserCount userCount = userService.getUserCount(institutionId, productId, Arrays.asList(roles), Arrays.asList(status));
UserCount userCount = userService.getUserCount(institutionId, productId,
Optional.ofNullable(roles).map(Arrays::asList).orElse(Collections.emptyList()),
Optional.ofNullable(status).map(Arrays::asList).orElse(Collections.emptyList()));
UserCountResource result = userMapperV2.toUserCountResource(userCount);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getUserCount result = {}", result);
log.trace("getUserCount end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,39 @@ void getUserCount() throws Exception {
verifyNoMoreInteractions(userServiceMock);
}

@Test
void getUserCountWithNullRolesAndStatus() throws Exception {
final String institutionId = "institutionId";
final String productId = "productId";

final UserCount userCount = new UserCount();
userCount.setInstitutionId(institutionId);
userCount.setProductId(productId);
userCount.setRoles(Arrays.asList("defaultRole1", "defaultRole2"));
userCount.setStatus(Arrays.asList("defaultStatus1", "defaultStatus2"));
userCount.setCount(2L);
when(userServiceMock.getUserCount(institutionId, productId, Collections.emptyList(), Collections.emptyList())).thenReturn(userCount);

final MvcResult result = mockMvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/{institutionId}/products/{productId}/users/count", institutionId, productId)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andReturn();

UserCountResource resource = objectMapper.readValue(
result.getResponse().getContentAsString(), new TypeReference<>() {});
assertEquals(userCount.getInstitutionId(), resource.getInstitutionId());
assertEquals(userCount.getProductId(), resource.getProductId());
assertIterableEquals(userCount.getRoles(), resource.getRoles());
assertIterableEquals(userCount.getStatus(), resource.getStatus());
assertEquals(userCount.getCount(), resource.getCount());

verify(userServiceMock, times(1))
.getUserCount(institutionId, productId, Collections.emptyList(), Collections.emptyList());
verifyNoMoreInteractions(userServiceMock);
}

private DelegationWithInfo dummyDelegation() {
DelegationWithInfo delegation = new DelegationWithInfo();
delegation.setInstitutionId("from");
Expand Down

0 comments on commit 0010a15

Please sign in to comment.