Skip to content

Commit 6aeebfd

Browse files
[SELC-6461] fix: roles and status params can be null in getUserCount
1 parent 0b56f6c commit 6aeebfd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/InstitutionV2Controller.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public UserCountResource getUserCount(@ApiParam("${swagger.dashboard.institution
109109
@ApiParam(value = "${swagger.dashboard.user.model.statusList}")
110110
@RequestParam(name = "status", required = false) String[] status) {
111111
log.trace("getUserCount start");
112-
UserCount userCount = userService.getUserCount(institutionId, productId, Arrays.asList(roles), Arrays.asList(status));
112+
UserCount userCount = userService.getUserCount(institutionId, productId,
113+
Optional.ofNullable(roles).map(Arrays::asList).orElse(Collections.emptyList()),
114+
Optional.ofNullable(status).map(Arrays::asList).orElse(Collections.emptyList()));
113115
UserCountResource result = userMapperV2.toUserCountResource(userCount);
114116
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getUserCount result = {}", result);
115117
log.trace("getUserCount end");

web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/InstitutionV2ControllerTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,39 @@ void getUserCount() throws Exception {
509509
verifyNoMoreInteractions(userServiceMock);
510510
}
511511

512+
@Test
513+
void getUserCountWithNullRolesAndStatus() throws Exception {
514+
final String institutionId = "institutionId";
515+
final String productId = "productId";
516+
517+
final UserCount userCount = new UserCount();
518+
userCount.setInstitutionId(institutionId);
519+
userCount.setProductId(productId);
520+
userCount.setRoles(Arrays.asList("defaultRole1", "defaultRole2"));
521+
userCount.setStatus(Arrays.asList("defaultStatus1", "defaultStatus2"));
522+
userCount.setCount(2L);
523+
when(userServiceMock.getUserCount(institutionId, productId, Collections.emptyList(), Collections.emptyList())).thenReturn(userCount);
524+
525+
final MvcResult result = mockMvc.perform(MockMvcRequestBuilders
526+
.get(BASE_URL + "/{institutionId}/products/{productId}/users/count", institutionId, productId)
527+
.contentType(APPLICATION_JSON_VALUE)
528+
.accept(APPLICATION_JSON_VALUE))
529+
.andExpect(status().isOk())
530+
.andReturn();
531+
532+
UserCountResource resource = objectMapper.readValue(
533+
result.getResponse().getContentAsString(), new TypeReference<>() {});
534+
assertEquals(userCount.getInstitutionId(), resource.getInstitutionId());
535+
assertEquals(userCount.getProductId(), resource.getProductId());
536+
assertIterableEquals(userCount.getRoles(), resource.getRoles());
537+
assertIterableEquals(userCount.getStatus(), resource.getStatus());
538+
assertEquals(userCount.getCount(), resource.getCount());
539+
540+
verify(userServiceMock, times(1))
541+
.getUserCount(institutionId, productId, Collections.emptyList(), Collections.emptyList());
542+
verifyNoMoreInteractions(userServiceMock);
543+
}
544+
512545
private DelegationWithInfo dummyDelegation() {
513546
DelegationWithInfo delegation = new DelegationWithInfo();
514547
delegation.setInstitutionId("from");

0 commit comments

Comments
 (0)