getDelegationResponse(String institutionId, Subscription subscriptionCode) {
- if (Boolean.TRUE.equals(subscriptionCode.getAuthDelegations())) {
- return this.externalApiClient.getBrokerDelegation(
- null, institutionId, "prod-pagopa", "FULL", null);
- }
- return new ArrayList<>();
- }
-
/**
* Regenerate the primary subscription key to the specified subscription for the given institution.
*
@@ -244,35 +262,94 @@ public void regenerateSecondaryKey(@NotNull String institutionId, @NotNull Strin
}
}
- private void updateAuthorization(String institutionId, String subscriptionId, String subscriptionPrefixId, boolean isPrimaryKey) {
+ /**
+ * Updates authorizer config for all broker's API keys that require delegations configuration.
+ * Retrieves the updated list of creditor institution and the relative list of segregation codes associated to
+ * broker's station and use this list to update segregation codes metadata in authorizer configuration.
+ *
+ * @param institutionId broker's institution id
+ * @param ciTaxCode broker's tax code
+ */
+ public void updateBrokerAuthorizerSegregationCodesMetadata(
+ String institutionId,
+ String ciTaxCode
+ ) {
+ List apiKeys = this.apimClient.getApiSubscriptions(institutionId).parallelStream()
+ .filter(this::checkIfAPIKeyHasAuthDelegations)
+ .toList();
+
+ CreditorInstitutionStationSegregationCodesList ciSegregationCodes =
+ this.apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(ciTaxCode);
+
+ apiKeys.parallelStream().forEach(
+ apiKey -> {
+ String prefixId = apiKey.getId().split("-")[0] + "-";
+ updateAuthorizerConfigMetadata(institutionId, prefixId, ciSegregationCodes, true);
+ updateAuthorizerConfigMetadata(institutionId, prefixId, ciSegregationCodes, false);
+ }
+ );
+ }
+
+ private boolean checkIfAPIKeyHasAuthDelegations(InstitutionApiKeys institutionApiKeys) {
+ try {
+ String prefixId = institutionApiKeys.getId().split("-")[0] + "-";
+ return Subscription.fromPrefix(prefixId).getAuthDelegations();
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private void updateAuthorization(
+ String institutionId,
+ String subscriptionId,
+ String subscriptionPrefixId,
+ boolean isPrimaryKey
+ ) {
InstitutionApiKeys apiKeys = this.apimClient.getApiSubscriptions(institutionId).stream()
.filter(institutionApiKeys -> institutionApiKeys.getId().equals(subscriptionId))
.findFirst()
.orElseThrow(() -> new AppException(AppError.APIM_KEY_NOT_FOUND, institutionId));
+ Subscription subscription = Subscription.fromPrefix(subscriptionPrefixId);
Authorization authorization;
try {
String authorizationId = createAuthorizationId(subscriptionPrefixId, institutionId, isPrimaryKey);
authorization = this.authorizerConfigClient.getAuthorization(authorizationId);
- this.authorizerConfigClient.deleteAuthorization(authorization.getId());
authorization.setSubscriptionKey(isPrimaryKey ? apiKeys.getPrimaryKey() : apiKeys.getSecondaryKey());
- InstitutionResponse institution =
- getInstitutionResponse(institutionId);
- List delegationResponse = getDelegationResponse(institutionId, Subscription.fromPrefix(subscriptionPrefixId));
- authorization.setAuthorizedEntities(getAuthorizationEntities(institution, delegationResponse));
+ InstitutionResponse institution = getInstitutionResponse(institutionId);
+ DelegationInfo delegationInfoResponse = getDelegationInfo(institutionId, subscription.getAuthDelegations(), institution.getTaxCode());
+
+ authorization.setAuthorizedEntities(getAuthorizationEntities(institution, delegationInfoResponse.delegationResponse));
+ authorization.setOtherMetadata(getAuthorizationMetadataList(delegationInfoResponse.ciSegregationCodes, authorization.getOtherMetadata()));
+ this.authorizerConfigClient.deleteAuthorization(authorization.getId());
this.authorizerConfigClient.createAuthorization(authorization);
} catch (FeignException.NotFound e) {
- createSubscriptionKeys(institutionId, Subscription.fromPrefix(subscriptionPrefixId));
+ log.error("An error occurred while updating API key authorizer configuration for institution {} and subscription {}, proceed to recreate the API key",
+ sanitizeLogParam(institutionId), sanitizeLogParam(subscription.getDisplayName()), e);
+ createSubscriptionKeys(institutionId, subscription);
}
}
+ private List getAuthorizationMetadataList(
+ CreditorInstitutionStationSegregationCodesList ciSegregationCodes,
+ List otherMetadata
+ ) {
+ AuthorizationMetadata authorizationMetadata = buildAuthorizationMetadata(ciSegregationCodes);
+ if (otherMetadata != null) {
+ List newOtherMetadata = new ArrayList<>(otherMetadata);
+ newOtherMetadata.removeIf(metadata -> metadata.getShortKey().equals(AUTHORIZER_SEGREGATION_CODES_METADATA_SHORT_KEY));
+ newOtherMetadata.add(authorizationMetadata);
+ return newOtherMetadata;
+ }
+ return Collections.singletonList(authorizationMetadata);
+ }
+
private InstitutionResponse getInstitutionResponse(String institutionId) {
- InstitutionResponse institution =
- this.externalApiClient.getInstitution(institutionId);
+ InstitutionResponse institution = this.externalApiClient.getInstitution(institutionId);
if (institution == null) {
throw new AppException(AppError.APIM_USER_NOT_FOUND, institutionId);
}
@@ -280,29 +357,32 @@ private InstitutionResponse getInstitutionResponse(String institutionId) {
}
private Authorization buildAuthorization(
- String domain,
- String subscriptionPrefixId,
+ Subscription subscription,
String subscriptionKey,
InstitutionResponse institution,
boolean isPrimaryKey,
- List delegationResponse
+ DelegationInfo delegationInfo
) {
+ String authDomain = subscription.getAuthDomain();
return Authorization.builder()
- .id(createAuthorizationId(subscriptionPrefixId, institution.getId(), isPrimaryKey))
- .domain(domain)
+ .id(createAuthorizationId(subscription.getPrefixId(), institution.getId(), isPrimaryKey))
+ .domain(authDomain)
.subscriptionKey(subscriptionKey)
- .description(String.format("%s key configuration for %s", isPrimaryKey ? PRIMARY : SECONDARY, domain))
+ .description(String.format("%s key configuration for %s", isPrimaryKey ? PRIMARY : SECONDARY, authDomain))
.owner(AuthorizationOwner.builder()
.id(institution.getTaxCode())
.name(institution.getDescription())
.type(getOwnerType(institution))
.build())
- .authorizedEntities(getAuthorizationEntities(institution, delegationResponse))
- .otherMetadata(Collections.emptyList())
+ .authorizedEntities(getAuthorizationEntities(institution, delegationInfo.delegationResponse))
+ .otherMetadata(Collections.singletonList(buildAuthorizationMetadata(delegationInfo.ciSegregationCodes)))
.build();
}
- private static List getAuthorizationEntities(InstitutionResponse institution, List delegationResponse) {
+ private List getAuthorizationEntities(
+ InstitutionResponse institution,
+ List delegationResponse
+ ) {
List authorizedEntities = new ArrayList<>();
if (delegationResponse != null && !delegationResponse.isEmpty()) {
@@ -329,8 +409,10 @@ private String createAuthorizationId(String subscriptionPrefixId, String institu
return String.format("%s%s_%s", subscriptionPrefixId, institutionId, isPrimaryKey ? PRIMARY : SECONDARY);
}
- private void createUserIfNotExist(String institutionId,
- InstitutionResponse institution) {
+ private void createUserIfNotExist(
+ String institutionId,
+ InstitutionResponse institution
+ ) {
try {
this.apimClient.getInstitution(institutionId);
} catch (IllegalArgumentException e) {
@@ -346,5 +428,66 @@ private void createUserIfNotExist(String institutionId,
private char getEnvironment() {
return environment.toLowerCase().charAt(0);
}
+
+ private void updateAuthorizerConfigMetadata(
+ String institutionId,
+ String prefixId,
+ CreditorInstitutionStationSegregationCodesList ciSegregationCodes,
+ boolean isPrimaryKey
+ ) {
+ Subscription subscription = Subscription.fromPrefix(prefixId);
+ try {
+ String authorizationId = createAuthorizationId(prefixId, institutionId, isPrimaryKey);
+ Authorization authorization = this.authorizerConfigClient.getAuthorization(authorizationId);
+
+ authorization.setOtherMetadata(getAuthorizationMetadataList(ciSegregationCodes, authorization.getOtherMetadata()));
+
+ this.authorizerConfigClient.deleteAuthorization(authorization.getId());
+ this.authorizerConfigClient.createAuthorization(authorization);
+ } catch (FeignException.NotFound e) {
+ log.error("An error occurred while updating API key authorizer configuration for institution {} and subscription {}, proceed to recreate the API key",
+ sanitizeLogParam(institutionId), sanitizeLogParam(subscription.getDisplayName()), e);
+ createSubscriptionKeys(institutionId, subscription);
+ }
+ }
+
+ private AuthorizationMetadata buildAuthorizationMetadata(CreditorInstitutionStationSegregationCodesList ciStationCodesList) {
+ List genericKeyValues =
+ ciStationCodesList.getCiStationCodes().parallelStream()
+ .map(elem ->
+ AuthorizationGenericKeyValue.builder()
+ .key(elem.getCiTaxCode())
+ .values(elem.getSegregationCodes())
+ .build()
+ )
+ .toList();
+
+ return AuthorizationMetadata.builder()
+ .name("Segregation codes")
+ .shortKey(AUTHORIZER_SEGREGATION_CODES_METADATA_SHORT_KEY)
+ .content(genericKeyValues)
+ .build();
+ }
+
+ private DelegationInfo getDelegationInfo(
+ String institutionId,
+ Boolean hasAuthDelegations,
+ String institutionTaxCode
+ ) {
+ List delegationResponse = new ArrayList<>();
+ CreditorInstitutionStationSegregationCodesList ciSegregationCodes = new CreditorInstitutionStationSegregationCodesList(new ArrayList<>());
+ if (Boolean.TRUE.equals(hasAuthDelegations)) {
+ delegationResponse = this.externalApiClient
+ .getBrokerDelegation(null, institutionId, "prod-pagopa", "FULL", null);
+ ciSegregationCodes =
+ this.apiConfigSelfcareIntegrationClient
+ .getCreditorInstitutionsSegregationCodeAssociatedToBroker(institutionTaxCode);
+ }
+ return new DelegationInfo(delegationResponse, ciSegregationCodes);
+ }
+
+ private record DelegationInfo(List delegationResponse,
+ CreditorInstitutionStationSegregationCodesList ciSegregationCodes) {
+ }
}
diff --git a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionService.java b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionService.java
index 11c65d0c3..4290f48b4 100644
--- a/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionService.java
+++ b/src/main/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionService.java
@@ -64,18 +64,22 @@ public class CreditorInstitutionService {
private final ModelMapper modelMapper;
+ private final ApiManagementService apiManagementService;
+
@Autowired
public CreditorInstitutionService(
ApiConfigClient apiConfigClient,
ApiConfigSelfcareIntegrationClient apiConfigSelfcareIntegrationClient,
TavoloOpRepository operativeTableRepository,
- ExternalApiClient externalApiClient, ModelMapper modelMapper
+ ExternalApiClient externalApiClient, ModelMapper modelMapper,
+ ApiManagementService apiManagementService
) {
this.apiConfigClient = apiConfigClient;
this.apiConfigSelfcareIntegrationClient = apiConfigSelfcareIntegrationClient;
this.operativeTableRepository = operativeTableRepository;
this.externalApiClient = externalApiClient;
this.modelMapper = modelMapper;
+ this.apiManagementService = apiManagementService;
}
/**
@@ -120,36 +124,86 @@ public AvailableCodes getCreditorInstitutionSegregationCodes(String ciTaxCode, S
return this.apiConfigSelfcareIntegrationClient.getCreditorInstitutionSegregationCodes(ciTaxCode, targetCITaxCode);
}
+ /**
+ * Associate the provided creditor institution to the given station.
+ *
+ * Check if the provided tax code is a creditor institution tax code and if so, associates it to the given station and
+ * updates the authorizer config for each broker's api keys by adding the specified segregation code
+ *
+ * @param ciTaxCode creditor institution's tax code
+ * @param institutionId broker's institution id
+ * @param brokerTaxCode broker's tax code
+ * @param dto creditor institution - station association info
+ * @return the creditor institution - station association info
+ */
public CreditorInstitutionStationEditResource associateStationToCreditorInstitution(
- String ecCode,
+ String ciTaxCode,
+ String institutionId,
+ String brokerTaxCode,
@NotNull CreditorInstitutionStationDto dto
) {
+ checkIfIsCITaxCodeFailOtherwise(ciTaxCode);
+ CreditorInstitutionStationEdit station = this.mapper.fromDto(dto);
+ CreditorInstitutionStationEdit ecStation = this.apiConfigClient.createCreditorInstitutionStationRelationship(ciTaxCode, station);
try {
- apiConfigClient.getCreditorInstitutionDetails(ecCode);
- } catch (FeignException e) {
- throw new AppException(AppError.CREDITOR_INSTITUTION_NOT_FOUND, ecCode);
+ this.apiManagementService.updateBrokerAuthorizerSegregationCodesMetadata(institutionId, brokerTaxCode);
+ } catch (Exception e) {
+ log.error("Failed to update broker API key authorizations, revert associate station to CI operation");
+ this.apiConfigClient.deleteCreditorInstitutionStationRelationship(ciTaxCode, ecStation.getStationCode());
+ throw e;
}
- CreditorInstitutionStationEdit station = mapper.fromDto(dto);
- CreditorInstitutionStationEdit ecStation = apiConfigClient.createCreditorInstitutionStationRelationship(ecCode, station);
- return mapper.toResource(ecStation);
+ return this.mapper.toResource(ecStation);
}
+ /**
+ * Updates the association between creditor institution and station.
+ *
+ * Check if the provided tax code is a creditor institution tax code and if so, updates the association to the given
+ * station with the provided info
+ *
+ * @param ciTaxCode creditor institution's tax code
+ * @param dto creditor institution - station association info
+ * @return the updated creditor institution - station association info
+ */
public CreditorInstitutionStationEditResource updateStationAssociationToCreditorInstitution(
- String ecCode,
+ String ciTaxCode,
@NotNull CreditorInstitutionStationDto dto
) {
- try {
- apiConfigClient.getCreditorInstitutionDetails(ecCode);
- } catch (FeignException e) {
- throw new AppException(AppError.CREDITOR_INSTITUTION_NOT_FOUND, ecCode);
- }
- CreditorInstitutionStationEdit station = mapper.fromDto(dto);
- CreditorInstitutionStationEdit ecStation = apiConfigClient.updateCreditorInstitutionStationRelationship(ecCode, station.getStationCode(), station);
- return mapper.toResource(ecStation);
+ checkIfIsCITaxCodeFailOtherwise(ciTaxCode);
+ CreditorInstitutionStationEdit station = this.mapper.fromDto(dto);
+ CreditorInstitutionStationEdit ecStation = this.apiConfigClient.updateCreditorInstitutionStationRelationship(ciTaxCode, station.getStationCode(), station);
+ return this.mapper.toResource(ecStation);
}
- public void deleteCreditorInstitutionStationRelationship(String ecCode, String stationCode) {
- apiConfigClient.deleteCreditorInstitutionStationRelationship(ecCode, stationCode);
+ /**
+ * Removes the association between creditor institution and station.
+ *
+ * Removes the association and updates the authorizer config for each broker's api keys by removing
+ * the segregation code of the association
+ *
+ * @param ciTaxCode creditor institution's tax code
+ * @param institutionId broker's institution id
+ * @param brokerTaxCode broker's tax code
+ */
+ public void deleteCreditorInstitutionStationRelationship(
+ String ciTaxCode,
+ String stationCode,
+ String institutionId,
+ String brokerTaxCode
+ ) {
+ this.apiConfigClient.deleteCreditorInstitutionStationRelationship(ciTaxCode, stationCode);
+ try {
+ this.apiManagementService.updateBrokerAuthorizerSegregationCodesMetadata(institutionId, brokerTaxCode);
+ } catch (Exception e) {
+ log.error("Failed to update broker API key authorizations, revert dissociate station to CI operation");
+ CreditorInstitutions creditorInstitutions =
+ this.apiConfigClient.getCreditorInstitutionsByStation(stationCode, 1, 0, ciTaxCode);
+ CreditorInstitutionStationEdit dto =
+ this.modelMapper.map(creditorInstitutions.getCreditorInstitutionList().get(0), CreditorInstitutionStationEdit.class);
+ dto.setStationCode(stationCode);
+ this.apiConfigClient.createCreditorInstitutionStationRelationship(ciTaxCode, dto);
+ throw e;
+ }
}
@@ -327,4 +381,11 @@ private boolean brokerCanBeAddedToDelegation(
&& delegationExternals.stream().noneMatch(delegationExternal -> delegationExternal.getTaxCode().equals(broker.getTaxCode()));
}
+ private void checkIfIsCITaxCodeFailOtherwise(String ciTaxCode) {
+ try {
+ this.apiConfigClient.getCreditorInstitutionDetails(ciTaxCode);
+ } catch (FeignException e) {
+ throw new AppException(AppError.CREDITOR_INSTITUTION_NOT_FOUND, ciTaxCode);
+ }
+ }
}
diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/controller/CreditorInstitutionControllerTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/controller/CreditorInstitutionControllerTest.java
index 3bf17b4fe..66fc82cff 100644
--- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/controller/CreditorInstitutionControllerTest.java
+++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/controller/CreditorInstitutionControllerTest.java
@@ -83,9 +83,11 @@ void getCreditorInstitutionSegregationCodes() throws Exception {
@Test
void associateStationToCreditorInstitution() throws Exception {
String url = "/creditor-institutions/12345678900/station";
- when(ciService.associateStationToCreditorInstitution(anyString(), any(CreditorInstitutionStationDto.class)))
+ when(ciService.associateStationToCreditorInstitution(anyString(), anyString(), anyString(), any(CreditorInstitutionStationDto.class)))
.thenReturn(TestUtil.fileToObject("response/service/post_creditor_institution_station_association_ok.json", CreditorInstitutionStationEditResource.class));
mvc.perform(post(url)
+ .param("institutionId", "institutionId")
+ .param("brokerTaxCode", "brokerTaxCode")
.content(TestUtil.readJsonFromFile("request/post_creditor_institution_station_association.json"))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
@@ -107,8 +109,10 @@ void updateStationAssociationToCreditorInstitution() throws Exception {
@Test
void deleteCreditorInstitutionStationRelationship() throws Exception {
String url = "/creditor-institutions/12345678900/station/00000000000_01";
- doNothing().when(ciService).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
- mvc.perform(delete(url).contentType(MediaType.APPLICATION_JSON))
+ doNothing().when(ciService).deleteCreditorInstitutionStationRelationship(anyString(), anyString(), anyString(), anyString());
+ mvc.perform(delete(url).contentType(MediaType.APPLICATION_JSON)
+ .param("institutionId", "institutionId")
+ .param("brokerTaxCode", "brokerTaxCode"))
.andExpect(status().isOk());
}
diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java
index a20255352..e813cea26 100644
--- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java
+++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/ApiManagementServiceTest.java
@@ -1,12 +1,18 @@
package it.pagopa.selfcare.pagopa.backoffice.service;
import com.azure.spring.cloud.feature.management.FeatureManager;
+import feign.FeignException;
import it.pagopa.selfcare.pagopa.backoffice.TestUtil;
+import it.pagopa.selfcare.pagopa.backoffice.client.ApiConfigSelfcareIntegrationClient;
import it.pagopa.selfcare.pagopa.backoffice.client.AuthorizerConfigClient;
import it.pagopa.selfcare.pagopa.backoffice.client.AzureApiManagerClient;
import it.pagopa.selfcare.pagopa.backoffice.client.ExternalApiClient;
import it.pagopa.selfcare.pagopa.backoffice.config.MappingsConfiguration;
import it.pagopa.selfcare.pagopa.backoffice.model.authorization.Authorization;
+import it.pagopa.selfcare.pagopa.backoffice.model.authorization.AuthorizationGenericKeyValue;
+import it.pagopa.selfcare.pagopa.backoffice.model.authorization.AuthorizationMetadata;
+import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.client.CreditorInstitutionStationSegregationCodes;
+import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.client.CreditorInstitutionStationSegregationCodesList;
import it.pagopa.selfcare.pagopa.backoffice.model.institutions.*;
import it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.InstitutionApiKeys;
import it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.InstitutionInfo;
@@ -18,6 +24,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -32,6 +39,7 @@ class ApiManagementServiceTest {
private final String INSTITUTION_ID = "INSTITUTION_ID";
private final String SUBSCRIPTION_ID = "SUBSCRIPTION_ID";
private final String BROKER_ID = "BROKER_ID";
+ private static final String CI_TAX_CODE = "ciTaxCode";
@MockBean
private AzureApiManagerClient apimClient;
@@ -45,6 +53,9 @@ class ApiManagementServiceTest {
@MockBean
private AuthorizerConfigClient authorizerConfigClient;
+ @MockBean
+ private ApiConfigSelfcareIntegrationClient apiConfigSelfcareIntegrationClient;
+
@Autowired
private ApiManagementService service;
@@ -158,6 +169,8 @@ void createSubscriptionKeys() throws IOException {
verify(apimClient).createInstitutionSubscription(any(), any(), any(), any(), any());
verify(externalApiClient).getInstitution(INSTITUTION_ID);
verify(authorizerConfigClient, never()).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -179,6 +192,8 @@ void createSubscriptionKeysWithoutAPIMUser() throws IOException {
verify(apimClient).createInstitutionSubscription(any(), any(), any(), any(), any());
verify(externalApiClient).getInstitution(INSTITUTION_ID);
verify(authorizerConfigClient, never()).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -202,6 +217,8 @@ void createSubscriptionKeysForBOExtEC() throws IOException {
verify(apimClient).createInstitutionSubscription(any(), any(), any(), any(), any());
verify(externalApiClient).getInstitution(INSTITUTION_ID);
verify(authorizerConfigClient, times(2)).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -213,6 +230,10 @@ void createSubscriptionKeysForFdrPsp() throws IOException {
when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse);
when(apimClient.getApiSubscriptions(any())).thenReturn(Collections.singletonList(institutionApiKeys));
+ when(externalApiClient.getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null))
+ .thenReturn(createDelegations());
+ when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString()))
+ .thenReturn(buildCreditorInstitutionStationSegregationCodesList());
InstitutionApiKeysResource result = service.createSubscriptionKeys(INSTITUTION_ID, Subscription.FDR_PSP);
@@ -237,6 +258,10 @@ void regeneratePrimaryKey() throws IOException {
.id("auth-id")
.build());
when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse);
+ when(externalApiClient.getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null))
+ .thenReturn(createDelegations());
+ when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString()))
+ .thenReturn(buildCreditorInstitutionStationSegregationCodesList());
assertDoesNotThrow(() -> service.regeneratePrimaryKey(INSTITUTION_ID, "gdp-123456"));
@@ -246,6 +271,34 @@ void regeneratePrimaryKey() throws IOException {
verify(authorizerConfigClient).createAuthorization(any());
}
+ @Test
+ void regeneratePrimaryKeyFailOnAuthorizerConfigUpdateTriggerAPIKeyRecreation() throws IOException {
+ InstitutionResponse institutionResponse = TestUtil.fileToObject(
+ "response/externalapi/institution_response.json", InstitutionResponse.class);
+ InstitutionApiKeys institutionApiKeys = buildInstitutionApiKeys("gdp-aTaxCode");
+ when(apimClient.getApiSubscriptions(anyString()))
+ .thenReturn(Collections.singletonList(institutionApiKeys))
+ .thenReturn(Collections.singletonList(institutionApiKeys));
+ when(authorizerConfigClient.getAuthorization(anyString()))
+ .thenThrow(FeignException.NotFound.class)
+ .thenReturn(Authorization.builder().id("auth-id").build());
+ when(externalApiClient.getInstitution(any())).thenReturn(institutionResponse);
+ when(externalApiClient.getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null))
+ .thenReturn(createDelegations());
+ when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString()))
+ .thenReturn(buildCreditorInstitutionStationSegregationCodesList());
+
+ assertDoesNotThrow(() -> service.regeneratePrimaryKey(INSTITUTION_ID, "gdp-aTaxCode"));
+
+ verify(apimClient).regeneratePrimaryKey("gdp-aTaxCode");
+ verify(apimClient, times(2)).getApiSubscriptions(INSTITUTION_ID);
+ verify(apimClient).getInstitution(INSTITUTION_ID);
+ verify(apimClient, never()).createInstitution(anyString(), any());
+ verify(apimClient).createInstitutionSubscription(any(), any(), any(), any(), any());
+ verify(authorizerConfigClient, times(2)).createAuthorization(any());
+ verify(authorizerConfigClient, never()).deleteAuthorization(anyString());
+ }
+
@Test
void regeneratePrimaryKeyForBOExtEC() throws IOException {
InstitutionResponse institutionResponse = TestUtil.fileToObject(
@@ -263,6 +316,8 @@ void regeneratePrimaryKeyForBOExtEC() throws IOException {
verify(apimClient).getApiSubscriptions(INSTITUTION_ID);
verify(authorizerConfigClient).deleteAuthorization(anyString());
verify(authorizerConfigClient).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -282,6 +337,8 @@ void regeneratePrimaryKeyForBOExtPSP() throws IOException {
verify(apimClient).getApiSubscriptions(INSTITUTION_ID);
verify(authorizerConfigClient).deleteAuthorization(anyString());
verify(authorizerConfigClient).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -295,6 +352,10 @@ void regenerateSecondaryKey() throws IOException {
when(authorizerConfigClient.getAuthorization(anyString())).thenReturn(Authorization.builder()
.id("auth-id")
.build());
+ when(externalApiClient.getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null))
+ .thenReturn(createDelegations());
+ when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString()))
+ .thenReturn(buildCreditorInstitutionStationSegregationCodesList());
assertDoesNotThrow(() -> service.regenerateSecondaryKey(INSTITUTION_ID, "gdp-123456"));
@@ -321,6 +382,8 @@ void regenerateSecondaryKeyForBOExtEC() throws IOException {
verify(apimClient).getApiSubscriptions(INSTITUTION_ID);
verify(authorizerConfigClient).deleteAuthorization(anyString());
verify(authorizerConfigClient).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
}
@Test
@@ -340,6 +403,48 @@ void regenerateSecondaryKeyForBOExtPSP() throws IOException {
verify(apimClient).getApiSubscriptions(INSTITUTION_ID);
verify(authorizerConfigClient).deleteAuthorization(anyString());
verify(authorizerConfigClient).createAuthorization(any());
+ verify(externalApiClient, never()).getBrokerDelegation(null, INSTITUTION_ID, "prod-pagopa", "FULL", null);
+ verify(apiConfigSelfcareIntegrationClient, never()).getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString());
+ }
+
+ @Test
+ void updateBrokerAuthorizerSegregationCodesMetadataSuccess() {
+ String subscriptionId = String.format("%s%s", Subscription.GPD.getPrefixId(), CI_TAX_CODE);
+ InstitutionApiKeys institutionApiKeys1 = buildInstitutionApiKeys(subscriptionId);
+ InstitutionApiKeys institutionApiKeys2 = buildInstitutionApiKeys("not from BO API key");
+
+ when(apimClient.getApiSubscriptions(INSTITUTION_ID)).thenReturn(List.of(institutionApiKeys1, institutionApiKeys2));
+ when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionsSegregationCodeAssociatedToBroker(anyString()))
+ .thenReturn(buildCreditorInstitutionStationSegregationCodesList());
+ when(authorizerConfigClient.getAuthorization(anyString())).thenReturn(
+ buildAuthorizationWithSegregationCodes(CI_TAX_CODE),
+ buildAuthorizationWithSegregationCodes("pippo")
+ );
+
+ assertDoesNotThrow(() -> service.updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, CI_TAX_CODE));
+
+ verify(apimClient).getApiSubscriptions(INSTITUTION_ID);
+ verify(authorizerConfigClient, times(2)).deleteAuthorization(anyString());
+ verify(authorizerConfigClient, times(2)).createAuthorization(any());
+ }
+
+ private Authorization buildAuthorizationWithSegregationCodes(String ciTaxCode) {
+ List keyValues = new ArrayList<>();
+ keyValues.add(
+ AuthorizationGenericKeyValue.builder()
+ .key(ciTaxCode)
+ .values(Collections.singletonList("02"))
+ .build());
+ List metadata = new ArrayList<>();
+ metadata.add(AuthorizationMetadata.builder()
+ .name("Segregation codes")
+ .shortKey("_seg")
+ .content(keyValues)
+ .build());
+ return Authorization.builder()
+ .id("auth-id")
+ .otherMetadata(metadata)
+ .build();
}
private InstitutionApiKeys buildInstitutionApiKeys(String subscriptionId) {
@@ -383,4 +488,14 @@ public List createDelegations() {
return delegationExternals;
}
+ private CreditorInstitutionStationSegregationCodesList buildCreditorInstitutionStationSegregationCodesList() {
+ return CreditorInstitutionStationSegregationCodesList.builder()
+ .ciStationCodes(Arrays.asList(
+ CreditorInstitutionStationSegregationCodes.builder()
+ .ciTaxCode(CI_TAX_CODE)
+ .segregationCodes(List.of("01", "14"))
+ .build()
+ ))
+ .build();
+ }
}
diff --git a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionServiceTest.java b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionServiceTest.java
index 586f27c64..ff1cf31df 100644
--- a/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionServiceTest.java
+++ b/src/test/java/it/pagopa/selfcare/pagopa/backoffice/service/CreditorInstitutionServiceTest.java
@@ -12,6 +12,7 @@
import it.pagopa.selfcare.pagopa.backoffice.model.connector.broker.Brokers;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.ApiConfigCreditorInstitutionsOrderBy;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.AvailableCodes;
+import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitution;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitutionDetails;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitutions;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.CreditorInstitutionStationEdit;
@@ -61,7 +62,6 @@
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -76,6 +76,10 @@ class CreditorInstitutionServiceTest {
private static final String STATION_CODE = "stationCode";
private static final String CI_TAX_CODE_1 = "12345677";
private static final String CI_TAX_CODE_2 = "12345666";
+ private static final String INSTITUTION_ID = "institutionId";
+ private static final String BROKER_TAX_CODE = "brokerTaxCode";
+ private static final String CI_TAX_CODE = "12345678900";
+ private static final String STATION_CODE1 = "00000000000_01";
@MockBean
private ApiConfigClient apiConfigClient;
@@ -89,6 +93,9 @@ class CreditorInstitutionServiceTest {
@MockBean
private ExternalApiClient externalApiClient;
+ @MockBean
+ private ApiManagementService apiManagementService;
+
@Autowired
private CreditorInstitutionService service;
@@ -168,7 +175,7 @@ void getCreditorInstitutionDetails_ok() throws IOException {
when(apiConfigClient.getCreditorInstitutionDetails(anyString()))
.thenReturn(TestUtil.fileToObject("response/apiconfig/get_creditor_institution_details_ok.json", CreditorInstitutionDetails.class));
- CreditorInstitutionDetailsResource result = service.getCreditorInstitutionDetails("12345678900");
+ CreditorInstitutionDetailsResource result = service.getCreditorInstitutionDetails(CI_TAX_CODE);
assertNotNull(result);
}
@@ -178,7 +185,7 @@ void getCreditorInstitutionDetails_ko() {
FeignException feignException = mock(FeignException.InternalServerError.class);
when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(feignException);
- assertThrows(FeignException.class, () -> service.getCreditorInstitutionDetails("12345678900"));
+ assertThrows(FeignException.class, () -> service.getCreditorInstitutionDetails(CI_TAX_CODE));
}
@Test
@@ -186,7 +193,7 @@ void getCreditorInstitutionSegregationCodes_ok() {
when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionSegregationCodes(anyString(), anyString()))
.thenReturn(AvailableCodes.builder().availableCodeList(Collections.singletonList("2")).build());
- AvailableCodes result = assertDoesNotThrow(() -> service.getCreditorInstitutionSegregationCodes("12345678900", "111111"));
+ AvailableCodes result = assertDoesNotThrow(() -> service.getCreditorInstitutionSegregationCodes(CI_TAX_CODE, "111111"));
assertNotNull(result);
}
@@ -196,7 +203,7 @@ void getCreditorInstitutionSegregationCodes_ko() {
FeignException feignException = mock(FeignException.InternalServerError.class);
when(apiConfigSelfcareIntegrationClient.getCreditorInstitutionSegregationCodes(anyString(), anyString())).thenThrow(feignException);
- assertThrows(FeignException.class, () -> service.getCreditorInstitutionSegregationCodes("12345678900", "111111"));
+ assertThrows(FeignException.class, () -> service.getCreditorInstitutionSegregationCodes(CI_TAX_CODE, "111111"));
}
@Test
@@ -206,19 +213,41 @@ void associateStationToCreditorInstitution_ok() throws IOException {
.thenReturn(TestUtil.fileToObject("response/apiconfig/post_creditor_institution_station_association_ok.json", CreditorInstitutionStationEdit.class));
CreditorInstitutionStationDto dto = TestUtil.fileToObject("request/post_creditor_institution_station_association.json", CreditorInstitutionStationDto.class);
- CreditorInstitutionStationEditResource result = service.associateStationToCreditorInstitution("12345678900", dto);
+ CreditorInstitutionStationEditResource result = service.associateStationToCreditorInstitution(CI_TAX_CODE, INSTITUTION_ID, BROKER_TAX_CODE, dto);
assertNotNull(result);
+
+ verify(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, BROKER_TAX_CODE);
}
@Test
void associateStationToCreditorInstitution_ko() throws IOException {
- FeignException feignException = mock(FeignException.InternalServerError.class);
- when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(feignException);
+ when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(FeignException.InternalServerError.class);
CreditorInstitutionStationDto dto = TestUtil.fileToObject("request/post_creditor_institution_station_association.json", CreditorInstitutionStationDto.class);
- assertThrows(AppException.class, () -> service.associateStationToCreditorInstitution("12345678900", dto));
- verify(apiConfigClient, times(0)).createCreditorInstitutionStationRelationship(anyString(), any(CreditorInstitutionStationEdit.class));
+ assertThrows(AppException.class, () -> service.associateStationToCreditorInstitution(CI_TAX_CODE, INSTITUTION_ID, BROKER_TAX_CODE, dto));
+
+ verify(apiConfigClient, never()).createCreditorInstitutionStationRelationship(anyString(), any(CreditorInstitutionStationEdit.class));
+ verify(apiManagementService, never()).updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, BROKER_TAX_CODE);
+ }
+
+ @Test
+ void associateStationToCreditorInstitutionFailOnAuthorizerUpdateExpectRollback() throws IOException {
+ when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenReturn(new CreditorInstitutionDetails());
+ when(apiConfigClient.createCreditorInstitutionStationRelationship(anyString(), any(CreditorInstitutionStationEdit.class)))
+ .thenReturn(
+ TestUtil.fileToObject(
+ "response/apiconfig/post_creditor_institution_station_association_ok.json",
+ CreditorInstitutionStationEdit.class)
+ );
+ doThrow(AppException.class).when(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(anyString(), anyString());
+
+ CreditorInstitutionStationDto dto =
+ TestUtil.fileToObject("request/post_creditor_institution_station_association.json", CreditorInstitutionStationDto.class);
+ assertThrows(AppException.class, () -> service.associateStationToCreditorInstitution(CI_TAX_CODE, INSTITUTION_ID, BROKER_TAX_CODE, dto));
+
+ verify(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, BROKER_TAX_CODE);
+ verify(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
}
@Test
@@ -228,34 +257,48 @@ void updateStationAssociationToCreditorInstitution_ok() throws IOException {
.thenReturn(TestUtil.fileToObject("response/apiconfig/post_creditor_institution_station_association_ok.json", CreditorInstitutionStationEdit.class));
CreditorInstitutionStationDto dto = TestUtil.fileToObject("request/post_creditor_institution_station_association.json", CreditorInstitutionStationDto.class);
- CreditorInstitutionStationEditResource result = service.updateStationAssociationToCreditorInstitution("12345678900", dto);
+ CreditorInstitutionStationEditResource result = service.updateStationAssociationToCreditorInstitution(CI_TAX_CODE, dto);
assertNotNull(result);
}
@Test
- void updateStationAssociationToCreditorInstitutio_ko() throws IOException {
+ void updateStationAssociationToCreditorInstitution_ko() throws IOException {
FeignException feignException = mock(FeignException.InternalServerError.class);
when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(feignException);
CreditorInstitutionStationDto dto = TestUtil.fileToObject("request/post_creditor_institution_station_association.json", CreditorInstitutionStationDto.class);
- assertThrows(AppException.class, () -> service.updateStationAssociationToCreditorInstitution("12345678900", dto));
+ assertThrows(AppException.class, () -> service.updateStationAssociationToCreditorInstitution(CI_TAX_CODE, dto));
verify(apiConfigClient, times(0)).updateCreditorInstitutionStationRelationship(anyString(), anyString(),any(CreditorInstitutionStationEdit.class));
}
@Test
void deleteCreditorInstitutionStationRelationship_ok() {
- doNothing().when(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
+ assertDoesNotThrow(() -> service.deleteCreditorInstitutionStationRelationship(CI_TAX_CODE, STATION_CODE1, INSTITUTION_ID, BROKER_TAX_CODE));
- assertDoesNotThrow(() -> service.deleteCreditorInstitutionStationRelationship("12345678900", "00000000000_01"));
+ verify(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
+ verify(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(INSTITUTION_ID, BROKER_TAX_CODE);
}
@Test
void deleteCreditorInstitutionStationRelationship_ko() {
- FeignException feignException = mock(FeignException.InternalServerError.class);
- doThrow(feignException).when(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
+ doThrow(FeignException.InternalServerError.class).when(apiConfigClient)
+ .deleteCreditorInstitutionStationRelationship(anyString(), anyString());
- assertThrows(FeignException.class, () -> service.deleteCreditorInstitutionStationRelationship("12345678900", "00000000000_01"));
+ assertThrows(FeignException.class, () ->
+ service.deleteCreditorInstitutionStationRelationship(CI_TAX_CODE, STATION_CODE1, INSTITUTION_ID, BROKER_TAX_CODE));
+ }
+
+ @Test
+ void deleteCreditorInstitutionStationRelationshipFailOnAuthorizerUpdateExpectRollback() {
+ doThrow(AppException.class).when(apiManagementService).updateBrokerAuthorizerSegregationCodesMetadata(anyString(), anyString());
+ when(apiConfigClient.getCreditorInstitutionsByStation(STATION_CODE1, 1, 0, CI_TAX_CODE))
+ .thenReturn(buildCreditorInstitutions());
+ assertThrows(AppException.class, () ->
+ service.deleteCreditorInstitutionStationRelationship(CI_TAX_CODE, STATION_CODE1, INSTITUTION_ID, BROKER_TAX_CODE));
+
+ verify(apiConfigClient).deleteCreditorInstitutionStationRelationship(anyString(), anyString());
+ verify(apiConfigClient).createCreditorInstitutionStationRelationship(anyString(), any());
}
@Test
@@ -307,7 +350,7 @@ void updateCreditorInstitution_ok() throws IOException {
.thenReturn(TestUtil.fileToObject("response/apiconfig/post_creditor_institution_ok.json", CreditorInstitutionDetails.class));
UpdateCreditorInstitutionDto dto = TestUtil.fileToObject("request/post_creditor_institution.json", UpdateCreditorInstitutionDto.class);
- CreditorInstitutionDetailsResource result = service.updateCreditorInstitutionDetails("12345678900", dto);
+ CreditorInstitutionDetailsResource result = service.updateCreditorInstitutionDetails(CI_TAX_CODE, dto);
assertNotNull(result);
}
@@ -318,7 +361,7 @@ void updateCreditorInstitution_ko() throws IOException {
when(apiConfigClient.updateCreditorInstitutionDetails(anyString(), any(CreditorInstitutionDetails.class))).thenThrow(feignException);
UpdateCreditorInstitutionDto dto = TestUtil.fileToObject("request/post_creditor_institution.json", UpdateCreditorInstitutionDto.class);
- assertThrows(FeignException.class, () -> service.updateCreditorInstitutionDetails("12345678900", dto));
+ assertThrows(FeignException.class, () -> service.updateCreditorInstitutionDetails(CI_TAX_CODE, dto));
}
@ParameterizedTest
@@ -331,7 +374,7 @@ void getBrokerAndEcDetails_ok(String existsBroker, String existsCI) throws IOExc
FeignException feignException = mock(FeignException.NotFound.class);
boolean isBrokerExistent = "true".equals(existsBroker);
boolean isCIExistent = "true".equals(existsCI);
- String brokerCode = "12345678900";
+ String brokerCode = CI_TAX_CODE;
if (isBrokerExistent) {
when(apiConfigClient.getBrokersEC(1, 0, brokerCode, null, null, "ASC"))
@@ -346,7 +389,7 @@ void getBrokerAndEcDetails_ok(String existsBroker, String existsCI) throws IOExc
when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(feignException);
}
- BrokerAndEcDetailsResource result = service.getBrokerAndEcDetails("12345678900");
+ BrokerAndEcDetailsResource result = service.getBrokerAndEcDetails(CI_TAX_CODE);
assertNotNull(result);
if (isBrokerExistent) {
@@ -367,7 +410,7 @@ void getBrokerAndEcDetails_ko() {
when(apiConfigClient.getBrokersEC(anyInt(), anyInt(), anyString(), anyString(), anyString(), anyString())).thenThrow(feignException);
when(apiConfigClient.getCreditorInstitutionDetails(anyString())).thenThrow(feignException);
- assertThrows(AppException.class, () -> service.getBrokerAndEcDetails("12345678900"));
+ assertThrows(AppException.class, () -> service.getBrokerAndEcDetails(CI_TAX_CODE));
}
@Test
@@ -376,14 +419,14 @@ void getCreditorInstitutionContactsSuccess() {
InstitutionProductUsers users = buildInstitutionProductUsers();
when(operativeTableRepository.findByTaxCode("ciTaxCode")).thenReturn(Optional.of(entity));
when(externalApiClient.getInstitutionProductUsers(
- "institutionId",
+ INSTITUTION_ID,
null,
null,
Collections.singletonList(SelfcareProductUser.ADMIN.getProductUser()))
).thenReturn(Collections.singletonList(users));
CreditorInstitutionContactsResource result = assertDoesNotThrow(() ->
- service.getCreditorInstitutionContacts("ciTaxCode", "institutionId"));
+ service.getCreditorInstitutionContacts("ciTaxCode", INSTITUTION_ID));
assertNotNull(result);
assertNotNull(result.getOperativeTable());
@@ -405,14 +448,14 @@ void getCreditorInstitutionContactsWithOperativeTableNotFound() {
InstitutionProductUsers users = buildInstitutionProductUsers();
when(operativeTableRepository.findByTaxCode("ciTaxCode")).thenReturn(Optional.empty());
when(externalApiClient.getInstitutionProductUsers(
- "institutionId",
+ INSTITUTION_ID,
null,
null,
Collections.singletonList(SelfcareProductUser.ADMIN.getProductUser()))
).thenReturn(Collections.singletonList(users));
CreditorInstitutionContactsResource result = assertDoesNotThrow(() ->
- service.getCreditorInstitutionContacts("ciTaxCode", "institutionId"));
+ service.getCreditorInstitutionContacts("ciTaxCode", INSTITUTION_ID));
assertNotNull(result);
assertNull(result.getOperativeTable());
@@ -677,4 +720,23 @@ private DelegationExternal buildDelegation(String institutionType, String taxCod
private InstitutionResponse buildInstitutionResponse(InstitutionType institutionType, String taxCode) {
return InstitutionResponse.builder().description("Broker").taxCode(taxCode).institutionType(institutionType).build();
}
+
+ private CreditorInstitutions buildCreditorInstitutions() {
+ return CreditorInstitutions.builder()
+ .creditorInstitutionList(Collections.singletonList(
+ CreditorInstitution.builder()
+ .aca(true)
+ .standIn(true)
+ .creditorInstitutionCode(CI_TAX_CODE)
+ .mod4(false)
+ .applicationCode(null)
+ .segregationCode(2L)
+ .auxDigit(null)
+ .broadcast(false)
+ .enabled(true)
+ .cbillCode("cbill")
+ .build()
+ ))
+ .build();
+ }
}
diff --git a/src/test/resources/response/apiconfig/get_creditor_institution_details_ok.json b/src/test/resources/response/apiconfig/get_creditor_institution_details_ok.json
index d97786d7c..2690cd44f 100644
--- a/src/test/resources/response/apiconfig/get_creditor_institution_details_ok.json
+++ b/src/test/resources/response/apiconfig/get_creditor_institution_details_ok.json
@@ -3,10 +3,10 @@
"enabled": true,
"business_name": "Comune XYZ",
"cbill_code": "COXYZ",
- "application_code": "01",
- "aux_digit": "03",
- "segregation_code": "02",
- "mod4": "x",
+ "application_code": 1,
+ "aux_digit": 3,
+ "segregation_code": 2,
+ "mod4": false,
"broadcast": false,
"address": {
"location": "via Roma 1",
diff --git a/src/test/resources/response/apiconfig/post_creditor_institution_ok.json b/src/test/resources/response/apiconfig/post_creditor_institution_ok.json
index d97786d7c..2690cd44f 100644
--- a/src/test/resources/response/apiconfig/post_creditor_institution_ok.json
+++ b/src/test/resources/response/apiconfig/post_creditor_institution_ok.json
@@ -3,10 +3,10 @@
"enabled": true,
"business_name": "Comune XYZ",
"cbill_code": "COXYZ",
- "application_code": "01",
- "aux_digit": "03",
- "segregation_code": "02",
- "mod4": "x",
+ "application_code": 1,
+ "aux_digit": 3,
+ "segregation_code": 2,
+ "mod4": false,
"broadcast": false,
"address": {
"location": "via Roma 1",