From 9614f94e4da38993ccf85799841fcb2efd771d24 Mon Sep 17 00:00:00 2001 From: Giulia Tremolada <124147597+giulia-tremolada@users.noreply.github.com> Date: Fri, 10 May 2024 14:40:03 +0200 Subject: [PATCH] [SELC-4677] refactor: remove users APIs in QueueNotificationController and related methods (#485) --- app/src/main/resources/swagger/api-docs.json | 154 ------------------ .../selfcare/mscore/api/UserConnector.java | 2 - .../connector/dao/UserConnectorImpl.java | 17 +- .../connector/dao/UserConnectorImplTest.java | 26 --- .../mscore/core/QueueNotificationService.java | 5 - .../core/QueueNotificationServiceImpl.java | 58 +------ .../core/QueueNotificationServiceTest.java | 112 +------------ .../QueueNotificationController.java | 33 +--- .../QueueNotificationControllerTest.java | 24 --- 9 files changed, 11 insertions(+), 420 deletions(-) diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 7d3c3dec9..faacf9e28 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -2662,135 +2662,6 @@ } ] } }, - "/notification-event/users" : { - "post" : { - "tags" : [ "kafka" ], - "summary" : "resendUsers", - "description" : "Service to resend old user onboardings to the SCUsers kafka queue, it can send the onboardings of a single user or also retrieve all the users for a given set of products in a paged manner by passing page and size", - "operationId" : "resendUsersUsingPOST", - "parameters" : [ { - "name" : "size", - "in" : "query", - "description" : "size", - "required" : false, - "style" : "form", - "schema" : { - "type" : "integer", - "format" : "int32" - } - }, { - "name" : "page", - "in" : "query", - "description" : "page", - "required" : false, - "style" : "form", - "schema" : { - "type" : "integer", - "format" : "int32" - } - }, { - "name" : "productsFilter", - "in" : "query", - "description" : "productsFilter", - "required" : true, - "style" : "form", - "explode" : true, - "schema" : { - "type" : "string" - } - }, { - "name" : "userId", - "in" : "query", - "description" : "userId", - "required" : false, - "style" : "form", - "schema" : { - "type" : "string" - } - } ], - "responses" : { - "200" : { - "description" : "OK" - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "409" : { - "description" : "Conflict", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, - "/notification-event/users/count" : { - "get" : { - "tags" : [ "kafka" ], - "summary" : "countUsers", - "description" : "Users' Count for single product", - "operationId" : "countUsersUsingGET", - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "*/*" : { - "schema" : { - "$ref" : "#/components/schemas/ProductCountResponse" - } - } - } - }, - "400" : { - "description" : "Bad Request", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - }, - "404" : { - "description" : "Not Found", - "content" : { - "application/problem+json" : { - "schema" : { - "$ref" : "#/components/schemas/Problem" - } - } - } - } - }, - "security" : [ { - "bearerAuth" : [ "global" ] - } ] - } - }, "/tokens" : { "get" : { "tags" : [ "Token" ], @@ -5589,31 +5460,6 @@ } } }, - "ProductCount" : { - "title" : "ProductCount", - "type" : "object", - "properties" : { - "count" : { - "type" : "integer", - "format" : "int32" - }, - "productId" : { - "type" : "string" - } - } - }, - "ProductCountResponse" : { - "title" : "ProductCountResponse", - "type" : "object", - "properties" : { - "products" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/ProductCount" - } - } - } - }, "ProductInfo" : { "title" : "ProductInfo", "type" : "object", diff --git a/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/UserConnector.java b/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/UserConnector.java index 59ed748f7..222d78d44 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/UserConnector.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/UserConnector.java @@ -2,7 +2,6 @@ import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.mscore.constant.RelationshipState; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter; import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct; @@ -61,5 +60,4 @@ public interface UserConnector { List getUserInfo(String userId, String institutionId, String[] states); - List countUsers(); } diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImpl.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImpl.java index f52f551b3..9ebca961b 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImpl.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImpl.java @@ -12,7 +12,6 @@ import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter; import it.pagopa.selfcare.mscore.model.onboarding.OnboardedProduct; @@ -29,7 +28,10 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.MongoOperations; -import org.springframework.data.mongodb.core.aggregation.*; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.GraphLookupOperation; +import org.springframework.data.mongodb.core.aggregation.MatchOperation; +import org.springframework.data.mongodb.core.aggregation.UnwindOperation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -43,7 +45,6 @@ import java.util.stream.Collectors; import static it.pagopa.selfcare.mscore.constant.CustomError.*; -import static org.springframework.data.mongodb.core.aggregation.Aggregation.group; @Slf4j @Component @@ -424,14 +425,4 @@ private String constructQuery(String... variables) { Arrays.stream(variables).forEach(s -> builder.append(".").append(s)); return builder.toString(); } - - @Override - public List countUsers() { - UnwindOperation unwindBindings = Aggregation.unwind("$bindings", "binding", true); - UnwindOperation unwindProducts = Aggregation.unwind("$bindings.products", "products", true); - MatchOperation matchStatusId = Aggregation.match(Criteria.where("bindings.products.status").in(VALID_USER_RELATIONSHIPS)); - GroupOperation productCount = group("bindings.products.productId").count().as("count"); - Aggregation aggregation = Aggregation.newAggregation(unwindBindings, unwindProducts, matchStatusId, productCount); - return mongoOperations.aggregate(aggregation, "User", QueryCount.class).getMappedResults(); - } } diff --git a/connector/dao/src/test/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImplTest.java b/connector/dao/src/test/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImplTest.java index c0db8146b..f00dc9833 100644 --- a/connector/dao/src/test/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImplTest.java +++ b/connector/dao/src/test/java/it/pagopa/selfcare/mscore/connector/dao/UserConnectorImplTest.java @@ -13,7 +13,6 @@ import it.pagopa.selfcare.mscore.constant.Env; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionAggregation; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionBinding; import it.pagopa.selfcare.mscore.model.aggregation.UserInstitutionFilter; @@ -679,29 +678,4 @@ void findUsersByInstitutionIdAndProductId(){ assertEquals(1, userIds.size()); } - - @Test - void countUser() { - //Given - AggregationResults results = mock(AggregationResults.class); - - when(results.getMappedResults()).thenReturn(List.of( - new QueryCount("prod1", 1), - new QueryCount("prod2", 2), - new QueryCount("prod3", 3))); - - //When - when(mongoTemplate.aggregate(any(Aggregation.class), anyString(), any())). - thenReturn(results); - - List response = userConnectorImpl.countUsers(); - - //Then - assertNotNull(response); - assertFalse(response.isEmpty()); - QueryCount actual = response.get(0); - - assertEquals(actual.getCount(), 1); - } - } diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java index e458110de..7bf66c60e 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationService.java @@ -1,6 +1,5 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import org.springframework.scheduling.annotation.Async; import java.util.List; @@ -12,8 +11,4 @@ public interface QueueNotificationService { void sendContractsNotificationsByInstitutionIdAndTokenId(String tokenId, String institutionId); void sendContracts(Optional size, List productsFilter); - - void sendUsers(Optional size, Optional page, List productsFilter, Optional userId); - - List countUsers(); } diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java index c6b91d839..0d624ba53 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceImpl.java @@ -2,14 +2,11 @@ import it.pagopa.selfcare.mscore.api.InstitutionConnector; import it.pagopa.selfcare.mscore.api.TokenConnector; -import it.pagopa.selfcare.mscore.api.UserConnector; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import it.pagopa.selfcare.mscore.model.institution.Institution; import it.pagopa.selfcare.mscore.model.institution.Onboarding; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.onboarding.Token; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -28,25 +25,19 @@ public class QueueNotificationServiceImpl implements QueueNotificationService { public static final int TOKEN_PAGE_SIZE = 100; public static final int USER_PAGE_SIZE = 100; private final ContractEventNotificationService contractService; - private final UserEventService userEventService; private Optional page_size_api = Optional.empty(); private Optional page = Optional.empty(); private final TokenConnector tokenConnector; private final InstitutionConnector institutionConnector; private Optional> productsFilter = Optional.empty(); - private final UserConnector userConnector; - private final List statesToSend = List.of(RelationshipState.ACTIVE, RelationshipState.DELETED); @Autowired public QueueNotificationServiceImpl(ContractEventNotificationService contractService, - UserEventService userEventService, TokenConnector tokenConnector, - InstitutionConnector institutionConnector, UserConnector userConnector) { - this.userEventService = userEventService; - this.userConnector = userConnector; + InstitutionConnector institutionConnector) { log.info("Initializing {}...", QueueNotificationServiceImpl.class.getSimpleName()); this.contractService = contractService; this.tokenConnector = tokenConnector; @@ -134,40 +125,6 @@ private void sendScContractNotifications(List tokens) { }); } - private void sendDataLakeUserNotifications(List users, String productId){ - users.forEach(onboardedUser -> { - userEventService.sendOnboardedUserNotification(onboardedUser, productId); - }); - } - - @Async - public void regenerateUserNotifications(Optional userId){ - if (productsFilter.isPresent()){ - for (String productId: productsFilter.get()){ - boolean nextPage = true; - int page = this.page.orElse(0); - if (userId.isPresent()){ - OnboardedUser user = userConnector.findById(userId.get()); - userEventService.sendOnboardedUserNotification(user, productId); - } - else { - do { - List users = userConnector.findAllValidUsers(page, page_size_api.orElse(USER_PAGE_SIZE), productId); - sendDataLakeUserNotifications(users, productId); - page += 1; - if (users.size() < USER_PAGE_SIZE || this.page.isPresent()) { - nextPage = false; - log.debug("[KAFKA] USER TOTAL NUMBER {}", page * USER_PAGE_SIZE + users.size()); - } - }while(nextPage); - } - page_size_api = Optional.empty(); - } - - } - - } - @Async @Override public void sendContracts(Optional size, List productsFilter) { @@ -176,17 +133,4 @@ public void sendContracts(Optional size, List productsFilter) { regenerateContractsNotifications(); } - @Async - @Override - public void sendUsers(Optional size, Optional page, List productsFilter, Optional userId) { - this.page_size_api = size; - this.productsFilter = Optional.ofNullable(productsFilter); - this.page=page; - regenerateUserNotifications(userId); - } - - @Override - public List countUsers() { - return userConnector.countUsers(); - } } diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java index 9ec6f916d..8a5520287 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/QueueNotificationServiceTest.java @@ -6,11 +6,9 @@ import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; import it.pagopa.selfcare.mscore.model.QueueEvent; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; import it.pagopa.selfcare.mscore.model.institution.Institution; import it.pagopa.selfcare.mscore.model.institution.InstitutionUpdate; import it.pagopa.selfcare.mscore.model.institution.Onboarding; -import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser; import it.pagopa.selfcare.mscore.model.onboarding.Token; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -19,14 +17,12 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Optional; import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -41,8 +37,6 @@ class QueueNotificationServiceTest { @Mock private UserConnector userConnector; @Mock - private UserEventService userEventService; - @Mock private InstitutionConnector institutionConnector; @Mock private TokenConnector tokenConnector; @@ -57,7 +51,7 @@ void startScheduler() { token.setInstitutionUpdate(institutionUpdate); final Institution institution = mockInstance(new Institution()); - schedulerService = new QueueNotificationServiceImpl(contractService, userEventService,tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService,tokenConnector, institutionConnector); when(institutionConnector.findById(anyString())).thenReturn(institution); @@ -89,7 +83,7 @@ void sendContractsNotificationsByInstitutionIdAndTokenId() { onboardingDeleted.setStatus(RelationshipState.DELETED); institution.setOnboarding(List.of(onboardingActive, onboardingDeleted, onboarding)); - schedulerService = new QueueNotificationServiceImpl(contractService, userEventService,tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService,tokenConnector, institutionConnector); when(institutionConnector.findById(institutionId)).thenReturn(institution); //when @@ -110,7 +104,7 @@ void startSchedulerUpdate(){ token.setInstitutionUpdate(institutionUpdate); final Institution institution = mockInstance(new Institution()); - schedulerService = new QueueNotificationServiceImpl(contractService, userEventService, tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService, tokenConnector, institutionConnector); when(institutionConnector.findById(anyString())).thenReturn(institution); @@ -135,7 +129,7 @@ void institutionNotFound(){ final Token token = mockInstance(new Token()); token.setStatus(RelationshipState.DELETED); - schedulerService = new QueueNotificationServiceImpl(contractService, userEventService, tokenConnector, institutionConnector, null); + schedulerService = new QueueNotificationServiceImpl(contractService, tokenConnector, institutionConnector); when(institutionConnector.findById(anyString())).thenThrow(ResourceNotFoundException.class); @@ -161,100 +155,4 @@ void productsFilterNotPresent(){ verifyNoInteractions(tokenConnector, institutionConnector, contractService); } - @Test - void startUserScheduler(){ - //given - final List productIds = List.of("productId"); - final Optional size = Optional.of(1); - final Optional page = Optional.of(0); - final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); - when(userConnector.findAllValidUsers(any(), any(), any())).thenReturn(List.of(onboardedUser)); - //when - Executable executable = () -> schedulerService.sendUsers(size, page, productIds, Optional.empty()); - //then - assertDoesNotThrow(executable); - verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); - } - - @Test - void startUserScheduler_singleUser(){ - //given - final List productIds = List.of("productId"); - final Optional size = Optional.of(1); - final Optional page = Optional.of(0); - final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); - final Optional userId = Optional.of("userId"); - when(userConnector.findById(any())).thenReturn(onboardedUser); - //when - Executable executable = () -> schedulerService.sendUsers(size, page, productIds, userId); - //then - assertDoesNotThrow(executable); - verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); - - } - - @Test - void startUserScheduler_noProducts(){ - //given - final Optional size = Optional.of(1); - final Optional page = Optional.of(0); - final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); - final Optional userId = Optional.of("userId"); - //when - Executable executable = () -> schedulerService.sendUsers(size, page, null, null); - //then - assertDoesNotThrow(executable); - verifyNoInteractions(userEventService, userConnector); - - } - - @Test - void startUserScheduler_pageDefault(){ - //given - final List productIds = List.of("productId"); - final Optional size = Optional.of(1); - final OnboardedUser onboardedUser = mockInstance(new OnboardedUser()); - when(userConnector.findAllValidUsers(any(), any(), any())).thenReturn(List.of(onboardedUser)); - //when - Executable executable = () -> schedulerService.sendUsers(Optional.empty(), Optional.empty(), productIds, Optional.empty()); - //then - assertDoesNotThrow(executable); - verify(userEventService, times(1)).sendOnboardedUserNotification(onboardedUser, productIds.get(0)); - - } - - @Test - void startScheduler_emptyProductList(){ - //given - final List productIds = new ArrayList<>(); - final Optional size = Optional.of(1); - //when - Executable executable = () -> schedulerService.sendUsers(Optional.empty(), Optional.empty(), productIds, Optional.empty()); - //then - assertDoesNotThrow(executable); - verifyNoInteractions(userEventService); - } - - @Test - void countUser(){ - //when - Executable executable = () -> schedulerService.countUsers(); - //then - assertDoesNotThrow(executable); - verify(userConnector, times(1)).countUsers(); - } - - @Test - void countUserMock() { - List prodCount = new ArrayList<>(); - prodCount.add(new QueryCount("prod1", 1)); - prodCount.add(new QueryCount("prod2", 2)); - prodCount.add(new QueryCount("prod3", 3)); - when(userConnector.countUsers()).thenReturn(prodCount); - List responseCount = schedulerService.countUsers(); - assertNotNull(responseCount); - assertFalse(responseCount.isEmpty()); - assertEquals(3, responseCount.size()); - assertEquals(2, responseCount.get(1).getCount()); - } } diff --git a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java index 30416173c..1d52a1e92 100644 --- a/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java +++ b/web/src/main/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationController.java @@ -3,12 +3,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import it.pagopa.selfcare.mscore.core.QueueNotificationService; -import it.pagopa.selfcare.mscore.model.aggregation.QueryCount; -import it.pagopa.selfcare.mscore.web.model.mapper.UserMapper; -import it.pagopa.selfcare.mscore.web.model.user.ProductCountResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -22,11 +18,8 @@ public class QueueNotificationController { private final QueueNotificationService queueNotificationService; - private final UserMapper userMapper; - - public QueueNotificationController(QueueNotificationService queueNotificationService, UserMapper userMapper) { + public QueueNotificationController(QueueNotificationService queueNotificationService) { this.queueNotificationService = queueNotificationService; - this.userMapper = userMapper; } @ApiOperation(value = "", notes = "${swagger.ms-core.notification-event.api.start}") @PostMapping(value = "/contracts") @@ -47,28 +40,4 @@ public void resendContractsByInstitutionIdAndTokenId(@RequestParam(name = "token queueNotificationService.sendContractsNotificationsByInstitutionIdAndTokenId(tokenId, institutionId); } - @ApiOperation(value = "", notes = "${swagger.ms-core.notification-event.api.start.users}") - @PostMapping(value = "/users") - @ResponseStatus(HttpStatus.OK) - public void resendUsers(@RequestParam(name = "size", required = false)Optional size, - @RequestParam(name = "page", required = false)Optional page, - @RequestParam(name = "productsFilter")List productsFilter, - @RequestParam(name = "userId", required = false)Optional userId){ - log.trace("Resend users events started"); - queueNotificationService.sendUsers(size, page, productsFilter, userId); - } - - @ApiOperation(value = "", notes = "${swagger.ms-core.notification-event.api.start.users.count}") - @GetMapping(value = "/users/count") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity countUsers(){ - log.trace("Count users start"); - List counts = queueNotificationService.countUsers(); - - ProductCountResponse productCountResponse = new ProductCountResponse(counts.stream() - .map(userMapper::toProductCount).toList()); - - log.trace("Count users end"); - return ResponseEntity.ok().body(productCountResponse); - } } \ No newline at end of file diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java index 957bea596..10bef06c3 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/QueueNotificationControllerTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.pagopa.selfcare.mscore.core.QueueNotificationService; -import it.pagopa.selfcare.mscore.web.model.mapper.UserMapper; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -25,9 +24,6 @@ class QueueNotificationControllerTest { @Autowired protected MockMvc mvc; - @MockBean - private UserMapper userMapper; - @MockBean private QueueNotificationService queueNotificationService; @@ -61,24 +57,4 @@ void sendContractsByInstitutionIdAndTokenId() throws Exception { Mockito.verify(queueNotificationService, Mockito.times(1)).sendContractsNotificationsByInstitutionIdAndTokenId(tokenId, institutionId); } - @Test - void sendUsers() throws Exception { - Integer size = 1; - Integer page = 0; - String productId = "product"; - mvc.perform(MockMvcRequestBuilders - .post(BASE_URL + "/users") - .param("size", String.valueOf(size)) - .param("page",String.valueOf(page)) - .param("productsFilter", productId)) - .andExpect(status().isOk()); - - Mockito.verify(queueNotificationService, Mockito.times(1)).sendUsers(Optional.of(size),Optional.of(page), List.of(productId), Optional.empty()); - } - - @Test - void countUsers() throws Exception { - mvc.perform(MockMvcRequestBuilders.get(BASE_URL + "/users/count")).andExpect(status().isOk()); - Mockito.verify(queueNotificationService, Mockito.times(1)).countUsers(); - } } \ No newline at end of file