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

[SELC-6461] fix: roles and status params can be null in getUserCount #508

Merged
merged 1 commit into from
Feb 7, 2025
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 @@ -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
Loading