From 11d601d3f0f94e38d68ba407bdf6732bc5afe02d Mon Sep 17 00:00:00 2001 From: empassaro Date: Tue, 17 Dec 2024 18:28:42 +0100 Subject: [PATCH] [SELC-6172] feat: removed DELETE_MANAGERS_BY_IC_AND_ADE activity --- .../functions/OnboardingFunctions.java | 15 -- .../functions/utils/ActivityName.java | 1 - .../onboarding/service/CompletionService.java | 2 - .../service/CompletionServiceDefault.java | 107 -------- .../workflow/WorkflowExecutorForUsersPg.java | 1 - .../functions/OnboardingFunctionsTest.java | 19 +- .../service/CompletionServiceDefaultTest.java | 228 ------------------ 7 files changed, 3 insertions(+), 370 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index ecb395889..57396a1b5 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -648,21 +648,6 @@ public void createAggregatesCsv( readOnboardingWorkflowValue(objectMapper, onboardingWorkflowString)); } - @FunctionName(DELETE_MANAGERS_BY_IC_AND_ADE) - public void deleteOldPgManagers( - @DurableActivityTrigger(name = "onboardingString") String onboardingString, - final ExecutionContext context) { - context - .getLogger() - .info( - () -> - String.format( - FORMAT_LOGGER_ONBOARDING_STRING, - DELETE_MANAGERS_BY_IC_AND_ADE, - onboardingString)); - completionService.deleteOldPgManagers(readOnboardingValue(objectMapper, onboardingString)); - } - @FunctionName(RETRIEVE_AGGREGATES_ACTIVITY) public String retrieveAggregates( @DurableActivityTrigger(name = "onboardingString") String onboardingString, diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java index 8b03f1358..b0d46cdaa 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/utils/ActivityName.java @@ -30,7 +30,6 @@ public class ActivityName { public static final String RESEND_NOTIFICATIONS_ACTIVITY = "ResendNotificationsActivity"; public static final String CREATE_AGGREGATES_CSV_ACTIVITY = "CreateAggregatesCsv"; public static final String EXISTS_DELEGATION_ACTIVITY = "ExistsDelegationActivity"; - public static final String DELETE_MANAGERS_BY_IC_AND_ADE = "DeleteManagersByIcAndAde"; public static final String RETRIEVE_AGGREGATES_ACTIVITY = "RetrieveAggregates"; public static final String BUILD_ATTACHMENTS_SAVE_TOKENS_ACTIVITY = "BuildAttachmentAndSaveTokens"; diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionService.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionService.java index 6d8f8911f..588001c50 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionService.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionService.java @@ -34,8 +34,6 @@ public interface CompletionService { String existsDelegation(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput); - void deleteOldPgManagers(Onboarding onboarding); - List retrieveAggregates(Onboarding onboarding); diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java index 3d34e46ec..e951f8764 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java @@ -31,13 +31,7 @@ import org.openapi.quarkus.party_registry_proxy_json.api.InfocamereApi; import org.openapi.quarkus.party_registry_proxy_json.api.NationalRegistriesApi; import org.openapi.quarkus.party_registry_proxy_json.api.UoApi; -import org.openapi.quarkus.party_registry_proxy_json.model.BusinessesResource; -import org.openapi.quarkus.party_registry_proxy_json.model.GetInstitutionsByLegalDto; -import org.openapi.quarkus.party_registry_proxy_json.model.GetInstitutionsByLegalFilterDto; -import org.openapi.quarkus.party_registry_proxy_json.model.LegalVerificationResult; import org.openapi.quarkus.user_json.model.AddUserRoleDto; -import org.openapi.quarkus.user_json.model.OnboardedProductState; -import org.openapi.quarkus.user_json.model.UserInstitutionResponse; import org.openapi.quarkus.user_registry_json.api.UserApi; import java.time.LocalDateTime; @@ -401,19 +395,6 @@ private List getDestinationMails(Onboarding onboarding) { .collect(Collectors.toList()); } - @Override - public void deleteOldPgManagers(Onboarding onboarding) { - String institutionId = onboarding.getInstitution().getId(); - String productId = onboarding.getProductId(); - List oldPgManagersUid = retrieveActiveManagersOnInstitution(institutionId, productId); - Origin origin = onboarding.getInstitution().getOrigin(); - - oldPgManagersUid.stream() - .map(uid -> new PgManagerInfo(uid, retrieveTaxCode(uid))) - .filter(pgManagerInfo -> !isActiveManagerOnRegistries(pgManagerInfo.getTaxCode(), onboarding.getInstitution().getTaxCode(), origin)) - .forEach(pgManagerInfo -> deleteManagerFromProduct(pgManagerInfo.getUid(), institutionId, productId)); - } - @Override public List retrieveAggregates(Onboarding onboarding) { String institutionId = onboarding.getInstitution().getId(); @@ -421,92 +402,4 @@ public List retrieveAggregates(Onboarding onboarding) { DelegationWithPaginationResponse delegations = delegationApi.getDelegationsUsingGET1(null, institutionId, productId, null, null, null, null, null); return delegations.getDelegations(); } - - private List retrieveActiveManagersOnInstitution(String institutionId, String productId) { - List activeManagers = userInstitutionApi.retrieveUserInstitutions( - institutionId, - null, - List.of(productId), - List.of(MANAGER.name()), - List.of(OnboardedProductState.ACTIVE.name()), - null - ); - - if(Objects.isNull(activeManagers) || CollectionUtils.isEmpty(activeManagers)) { - return Collections.emptyList(); - } - - return activeManagers.stream() - .map(UserInstitutionResponse::getUserId) - .toList(); - } - - private String retrieveTaxCode(String uid) { - return userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, uid).getFiscalCode(); - } - - private boolean isActiveManagerOnRegistries(String userTaxCode, String institutionTaxCode, Origin origin) { - return switch (origin) { - case INFOCAMERE -> isActiveManagerOnInfocamereRegistry(userTaxCode, institutionTaxCode); - case ADE -> isActiveManagerOnAdeRegistry(userTaxCode, institutionTaxCode); - default -> throw new GenericOnboardingException("Origin not supported"); - }; - } - - private boolean isActiveManagerOnInfocamereRegistry(String userTaxCode, String institutionTaxCode) { - BusinessesResource businessesResource = infocamereApi.institutionsByLegalTaxIdUsingPOST(toGetInstitutionByLegalDto(userTaxCode)); - if(Objects.isNull(businessesResource) || CollectionUtils.isEmpty(businessesResource.getBusinesses())) { - return false; - } - - return businessesResource.getBusinesses().stream() - .anyMatch(business -> institutionTaxCode.equals(business.getBusinessTaxId())); - } - - private GetInstitutionsByLegalDto toGetInstitutionByLegalDto(String userTaxCode) { - GetInstitutionsByLegalDto getInstitutionsByLegalDto = new GetInstitutionsByLegalDto(); - GetInstitutionsByLegalFilterDto getInstitutionsByLegalFilterDto = new GetInstitutionsByLegalFilterDto(); - getInstitutionsByLegalFilterDto.setLegalTaxId(userTaxCode); - getInstitutionsByLegalDto.setFilter(getInstitutionsByLegalFilterDto); - return getInstitutionsByLegalDto; - } - - private boolean isActiveManagerOnAdeRegistry(String userTaxCode, String institutionTaxCode) { - try { - LegalVerificationResult legalVerificationResult = nationalRegistriesApi.verifyLegalUsingGET(userTaxCode, institutionTaxCode); - return legalVerificationResult.getVerificationResult(); - } catch (WebApplicationException e) { - // 400 status code means that the user is not a manager of the institution - if (e.getResponse().getStatus() == 400) { - return false; - } - throw new GenericOnboardingException(String.format("Error during verify legal %s", e.getMessage())); - } - } - - private void deleteManagerFromProduct(String uid, String institutionId, String productId) { - try (Response response = userApi.deleteProducts(institutionId, productId, uid)) { - if (!SUCCESSFUL.equals(response.getStatusInfo().getFamily())) { - throw new GenericOnboardingException(String.format("Failed to delete user %s from product %s in institution %s", uid, productId, institutionId)); - } - } - } - - private static class PgManagerInfo { - private final String uid; - private final String taxCode; - - public PgManagerInfo(String uid, String taxCode) { - this.uid = uid; - this.taxCode = taxCode; - } - - public String getUid() { - return uid; - } - - public String getTaxCode() { - return taxCode; - } - } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForUsersPg.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForUsersPg.java index 802f84d02..10ef1eb02 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForUsersPg.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/workflow/WorkflowExecutorForUsersPg.java @@ -29,7 +29,6 @@ public Optional executeToBeValidatedState(TaskOrchestrationCon @Override public Optional executePendingState(TaskOrchestrationContext ctx, OnboardingWorkflow onboardingWorkflow) { final String onboardingString = getOnboardingString(objectMapper(), onboardingWorkflow.getOnboarding()); - ctx.callActivity(DELETE_MANAGERS_BY_IC_AND_ADE, onboardingString, optionsRetry(), String.class).await(); ctx.callActivity(CREATE_USERS_ACTIVITY, onboardingString, optionsRetry(), String.class).await(); ctx.callActivity(STORE_ONBOARDING_ACTIVATEDAT, onboardingString, optionsRetry(), String.class).await(); return Optional.of(COMPLETED); diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java index 0e22cdb7b..7eb4b837f 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctionsTest.java @@ -917,11 +917,10 @@ void usersPgOrchestrator_whenStatusPending() { function.onboardingsOrchestrator(orchestrationContext, executionContext); ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); - verify(orchestrationContext, times(3)) + verify(orchestrationContext, times(2)) .callActivity(captorActivity.capture(), any(), any(), any()); - assertEquals(DELETE_MANAGERS_BY_IC_AND_ADE, captorActivity.getAllValues().get(0)); - assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(1)); - assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(2)); + assertEquals(CREATE_USERS_ACTIVITY, captorActivity.getAllValues().get(0)); + assertEquals(STORE_ONBOARDING_ACTIVATEDAT, captorActivity.getAllValues().get(1)); } @Test @@ -1077,18 +1076,6 @@ void sendTestEmail() { verify(completionService, times(1)).sendTestEmail(executionContext); } - @Test - void deleteOldPgManagers() { - final String onboardingString = "{\"onboardingId\":\"onboardingId\"}"; - - when(executionContext.getLogger()).thenReturn(Logger.getGlobal()); - doNothing().when(completionService).deleteOldPgManagers(any()); - - function.deleteOldPgManagers(onboardingString, executionContext); - - verify(completionService, times(1)).deleteOldPgManagers(any()); - } - @Test void retrieveAggregates() { List delegationResponseList = new ArrayList<>(); diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java index 2dd8def68..9f9104132 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java @@ -37,7 +37,6 @@ import org.openapi.quarkus.party_registry_proxy_json.api.NationalRegistriesApi; import org.openapi.quarkus.party_registry_proxy_json.api.UoApi; import org.openapi.quarkus.party_registry_proxy_json.model.*; -import org.openapi.quarkus.user_json.model.UserInstitutionResponse; import org.openapi.quarkus.user_registry_json.api.UserApi; import org.openapi.quarkus.user_registry_json.model.UserResource; import org.openapi.quarkus.user_registry_json.model.WorkContactResource; @@ -857,233 +856,6 @@ void forceInstitutionCreationFlagTrue(){ verify(institutionApi, times(1)).getInstitutionsUsingGET(any(), any(), any(), any()); } - @Test - void deleteOldPgManagers_shouldDeleteInactiveManagers_OnInfocamere() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.INFOCAMERE); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - UserInstitutionResponse user2 = new UserInstitutionResponse(); - user2.setUserId("user2"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1, user2)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - UserResource userResource2 = new UserResource(); - userResource2.setFiscalCode("taxCode2"); - - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user2")).thenReturn(userResource2); - - when(infocamereApi.institutionsByLegalTaxIdUsingPOST(any())).thenReturn(new BusinessesResource()); - - Response responseOk = new ServerResponse(null, 204, null); - when(userControllerApi.deleteProducts("institution-id","productId", "user1")) - .thenReturn(responseOk); - when(userControllerApi.deleteProducts("institution-id","productId", "user2")) - .thenReturn(responseOk); - - completionServiceDefault.deleteOldPgManagers(onboarding); - - verify(userControllerApi, times(2)).deleteProducts(eq("institution-id"), eq("productId"), any()); - } - - @Test - void deleteOldPgManagers_shouldDeleteInactiveManagers_InvalidOrigin() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.IPA); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - UserInstitutionResponse user2 = new UserInstitutionResponse(); - user2.setUserId("user2"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1, user2)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - UserResource userResource2 = new UserResource(); - userResource2.setFiscalCode("taxCode2"); - - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user2")).thenReturn(userResource2); - - LegalVerificationResult legalVerificationResult = new LegalVerificationResult(); - legalVerificationResult.setVerificationResult(false); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode1"), any())).thenReturn(legalVerificationResult); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode2"), any())).thenThrow(new WebApplicationException(500)); - - Response responseOk = new ServerResponse(null, 204, null); - when(userControllerApi.deleteProducts("institution-id","productId", "user1")) - .thenReturn(responseOk); - when(userControllerApi.deleteProducts("institution-id","productId", "user2")) - .thenReturn(responseOk); - - Assertions.assertThrows(GenericOnboardingException.class, - () -> completionServiceDefault.deleteOldPgManagers(onboarding), - "Origin not supported"); - - } - - @Test - void deleteOldPgManagers_shouldDeleteInactiveManagers_getStatusInfoNotSuccessfull() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.ADE); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - UserInstitutionResponse user2 = new UserInstitutionResponse(); - user2.setUserId("user2"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1, user2)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - UserResource userResource2 = new UserResource(); - userResource2.setFiscalCode("taxCode2"); - - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user2")).thenReturn(userResource2); - - LegalVerificationResult legalVerificationResult = new LegalVerificationResult(); - legalVerificationResult.setVerificationResult(false); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode1"), any())).thenReturn(legalVerificationResult); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode2"), any())).thenThrow(new WebApplicationException(500)); - - Response responseKo = new ServerResponse(null, 400, null); - when(userControllerApi.deleteProducts("institution-id","productId", "user1")) - .thenReturn(responseKo); - when(userControllerApi.deleteProducts("institution-id","productId", "user2")) - .thenReturn(responseKo); - - Assertions.assertThrows(GenericOnboardingException.class, - () -> completionServiceDefault.deleteOldPgManagers(onboarding), - "Failed to delete user user1 from product productId in institution institution-id"); - - } - - @Test - void deleteOldPgManagers_shouldDeleteInactiveManagers_OnAde() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.ADE); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - UserInstitutionResponse user2 = new UserInstitutionResponse(); - user2.setUserId("user2"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1, user2)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - UserResource userResource2 = new UserResource(); - userResource2.setFiscalCode("taxCode2"); - - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user2")).thenReturn(userResource2); - - LegalVerificationResult legalVerificationResult = new LegalVerificationResult(); - legalVerificationResult.setVerificationResult(false); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode1"), any())).thenReturn(legalVerificationResult); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode2"), any())).thenThrow(new WebApplicationException(400)); - - Response responseOk = new ServerResponse(null, 204, null); - when(userControllerApi.deleteProducts("institution-id","productId", "user1")) - .thenReturn(responseOk); - when(userControllerApi.deleteProducts("institution-id","productId", "user2")) - .thenReturn(responseOk); - - completionServiceDefault.deleteOldPgManagers(onboarding); - - verify(userControllerApi, times(2)).deleteProducts(eq("institution-id"), eq("productId"), any()); - } - - @Test - void deleteOldPgManagers_shouldDeleteInactiveManagers_OnAde_Error_isActiveManagerOnAdeRegistry() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.ADE); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - - Response responseOk = new ServerResponse(null, 204, null); - when(userControllerApi.deleteProducts("institution-id","productId", "user1")) - .thenReturn(responseOk); - when(nationalRegistriesApi.verifyLegalUsingGET(eq("taxCode1"), any())).thenThrow(new WebApplicationException(404)); - - Assertions.assertThrows(GenericOnboardingException.class, - () -> completionServiceDefault.deleteOldPgManagers(onboarding), "Error during verify legal HTTP 404 Not Found"); - } - - @Test - void deleteOldPgManagers_shouldNotDeleteActiveManagers() { - // Shouldn't perform deletion, because user1 will be found on the registry. - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.INFOCAMERE); - - UserInstitutionResponse user1 = new UserInstitutionResponse(); - user1.setUserId("user1"); - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(List.of(user1)); - - UserResource userResource1 = new UserResource(); - userResource1.setFiscalCode("taxCode1"); - when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, "user1")).thenReturn(userResource1); - - BusinessesResource businessesResource = new BusinessesResource(); - BusinessResource businessResource = new BusinessResource(); - businessResource.setBusinessTaxId("institution-tax-code"); - businessesResource.setBusinesses(List.of(businessResource)); - when(infocamereApi.institutionsByLegalTaxIdUsingPOST(any())).thenReturn(businessesResource); - - completionServiceDefault.deleteOldPgManagers(onboarding); - - verify(userControllerApi, never()).deleteProducts(eq("institution-id"), eq("productId"), any()); - } - - @Test - void deleteOldPgManagers_shouldHandleEmptyManagersList() { - Onboarding onboarding = createOnboarding(); - onboarding.getInstitution().setId("institution-id"); - onboarding.getInstitution().setTaxCode("institution-tax-code"); - onboarding.getInstitution().setOrigin(Origin.INFOCAMERE); - - when(userInstitutionApi.retrieveUserInstitutions( - eq("institution-id"), any(), eq(List.of("productId")), eq(List.of("MANAGER")), eq(List.of("ACTIVE")), any())) - .thenReturn(Collections.emptyList()); - - completionServiceDefault.deleteOldPgManagers(onboarding); - - verify(userControllerApi, never()).deleteProducts(any(), eq("institution-id"), eq("productId")); - } - @Test void retrieveAggregates() { Onboarding onboarding = createOnboarding();