From 98a9b079ff8f592155dc951636b26dce1c18ead2 Mon Sep 17 00:00:00 2001 From: manuraf Date: Mon, 5 Feb 2024 17:23:01 +0100 Subject: [PATCH 1/4] contract service notification --- app/src/main/resources/config/application.yml | 2 + .../ContractEventNotificationService.java | 14 + ...ontractEventNotificationServiceIgnore.java | 32 + .../ContractEventNotificationServiceImpl.java | 209 ++++++ .../selfcare/mscore/core/ContractService.java | 183 +---- .../mscore/core/InstitutionServiceImpl.java | 4 +- .../mscore/core/OnboardingServiceImpl.java | 8 +- .../core/QueueNotificationServiceImpl.java | 4 +- .../mscore/core/TokenServiceImpl.java | 4 +- .../OnboardingInstitutionStrategyFactory.java | 6 +- ...tractEventNotificationServiceImplTest.java | 611 +++++++++++++++++ .../mscore/core/ContractServiceTest.java | 640 +----------------- .../core/InstitutionServiceImplTest.java | 2 +- .../core/OnboardingServiceImplTest.java | 3 + .../core/QueueNotificationServiceTest.java | 2 +- .../mscore/core/TokenServiceImplTest.java | 2 +- .../OnboardingInstitutionStrategyTest.java | 4 +- helm/values-dev.yaml | 1 + helm/values-prod.yaml | 1 + helm/values-uat.yaml | 1 + 20 files changed, 916 insertions(+), 817 deletions(-) create mode 100644 core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationService.java create mode 100644 core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java create mode 100644 core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java create mode 100644 core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java diff --git a/app/src/main/resources/config/application.yml b/app/src/main/resources/config/application.yml index 31cdea2b7..e2d0644f6 100644 --- a/app/src/main/resources/config/application.yml +++ b/app/src/main/resources/config/application.yml @@ -47,3 +47,5 @@ logging: core: user-event-service: type: ${CORE_USER_EVENT_SERVICE_TYPE:ignore} + contract-event-service: + type: ${CORE_CONTRACT_EVENT_SERVICE_TYPE:ignore} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationService.java new file mode 100644 index 000000000..bda69cc74 --- /dev/null +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationService.java @@ -0,0 +1,14 @@ +package it.pagopa.selfcare.mscore.core; + +import it.pagopa.selfcare.mscore.model.NotificationToSend; +import it.pagopa.selfcare.mscore.model.QueueEvent; +import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.onboarding.Token; + +public interface ContractEventNotificationService { + void sendDataLakeNotification(Institution institution, Token token, QueueEvent queueEvent); + + NotificationToSend toNotificationToSend(Institution institution, Token token, QueueEvent queueEvent); + + NotificationToSend toNotificationToSend(NotificationToSend notification, Institution institution, Token token); +} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java new file mode 100644 index 000000000..efc0e12e3 --- /dev/null +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java @@ -0,0 +1,32 @@ +package it.pagopa.selfcare.mscore.core; + +import it.pagopa.selfcare.mscore.model.NotificationToSend; +import it.pagopa.selfcare.mscore.model.QueueEvent; +import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.onboarding.Token; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@ConditionalOnProperty( + value="core.user-event-service.type", + havingValue = "ignore", + matchIfMissing = true) +public class ContractEventNotificationServiceIgnore implements ContractEventNotificationService { + @Override + public void sendDataLakeNotification(Institution institution, Token token, QueueEvent queueEvent) { + + } + + @Override + public NotificationToSend toNotificationToSend(Institution institution, Token token, QueueEvent queueEvent) { + return null; + } + + @Override + public NotificationToSend toNotificationToSend(NotificationToSend notification, Institution institution, Token token) { + return null; + } +} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java new file mode 100644 index 000000000..ae6b20545 --- /dev/null +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java @@ -0,0 +1,209 @@ +package it.pagopa.selfcare.mscore.core; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import it.pagopa.selfcare.commons.base.logging.LogUtils; +import it.pagopa.selfcare.mscore.api.InstitutionConnector; +import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; +import it.pagopa.selfcare.mscore.config.CoreConfig; +import it.pagopa.selfcare.mscore.constant.RelationshipState; +import it.pagopa.selfcare.mscore.core.config.KafkaPropertiesConfig; +import it.pagopa.selfcare.mscore.core.util.InstitutionPaSubunitType; +import it.pagopa.selfcare.mscore.exception.InvalidRequestException; +import it.pagopa.selfcare.mscore.exception.MsCoreException; +import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; +import it.pagopa.selfcare.mscore.model.InstitutionToNotify; +import it.pagopa.selfcare.mscore.model.NotificationToSend; +import it.pagopa.selfcare.mscore.model.QueueEvent; +import it.pagopa.selfcare.mscore.model.RootParent; +import it.pagopa.selfcare.mscore.model.institution.GeographicTaxonomies; +import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.institution.InstitutionProxyInfo; +import it.pagopa.selfcare.mscore.model.institution.Onboarding; +import it.pagopa.selfcare.mscore.model.onboarding.Token; +import lombok.extern.slf4j.Slf4j; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.support.SendResult; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +import java.nio.file.Paths; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +@Slf4j +@Service +public class ContractEventNotificationServiceImpl implements ContractEventNotificationService { + + + static final String DESCRIPTION_TO_REPLACE_REGEX = " - COMUNE"; + + private final KafkaTemplate kafkaTemplate; + private final KafkaPropertiesConfig kafkaPropertiesConfig; + private final ObjectMapper mapper; + private final PartyRegistryProxyConnector partyRegistryProxyConnector; + private final InstitutionConnector institutionConnector; + private final CoreConfig coreConfig; + + public ContractEventNotificationServiceImpl(KafkaTemplate kafkaTemplate, KafkaPropertiesConfig kafkaPropertiesConfig, ObjectMapper mapper, PartyRegistryProxyConnector partyRegistryProxyConnector, InstitutionConnector institutionConnector, CoreConfig coreConfig) { + this.kafkaTemplate = kafkaTemplate; + this.kafkaPropertiesConfig = kafkaPropertiesConfig; + this.mapper = mapper; + this.partyRegistryProxyConnector = partyRegistryProxyConnector; + this.institutionConnector = institutionConnector; + this.coreConfig = coreConfig; + } + + @Override + public void sendDataLakeNotification(Institution institution, Token token, QueueEvent queueEvent) { + log.debug(LogUtils.CONFIDENTIAL_MARKER, "sendDataLakeNotification institution = {}, token = {}, queueEvent = {}", institution, token, queueEvent); + if (institution != null) { + NotificationToSend notification = toNotificationToSend(institution, token, queueEvent); + log.debug(LogUtils.CONFIDENTIAL_MARKER, "Notification to send to the data lake, notification: {}", notification); + try { + String msg = mapper.writeValueAsString(notification); + sendNotification(msg, token.getId()); + } catch (JsonProcessingException e) { + log.warn("error during send dataLake notification for token {}", notification.getId()); + } + } + } + + + @Override + public NotificationToSend toNotificationToSend(Institution institution, Token token, QueueEvent queueEvent) { + NotificationToSend notification = new NotificationToSend(); + if (queueEvent.equals(QueueEvent.ADD)) { + // When Onboarding.complete event id is the onboarding id + notification.setId(token.getId()); + notification.setState(RelationshipState.ACTIVE.toString()); + // when onboarding complete last update is activated date + notification.setUpdatedAt(Optional.ofNullable(token.getActivatedAt()).orElse(token.getCreatedAt())); + } else { + // New id + notification.setId(UUID.randomUUID().toString()); + notification.setState(token.getStatus() == RelationshipState.DELETED ? "CLOSED" : token.getStatus().toString()); + // when update last update is updated date + notification.setUpdatedAt(Optional.ofNullable(token.getUpdatedAt()).orElse(token.getCreatedAt())); + if (token.getStatus().equals(RelationshipState.DELETED)) { + // Queue.ClosedAt: if token.deleted show closedAt + notification.setClosedAt(Optional.ofNullable(token.getDeletedAt()).orElse(token.getUpdatedAt())); + notification.setUpdatedAt(Optional.ofNullable(token.getDeletedAt()).orElse(token.getUpdatedAt())); + } else { + // when update last update is updated date + notification.setUpdatedAt(Optional.ofNullable(token.getUpdatedAt()).orElse(token.getCreatedAt())); + } + } + // ADD or UPDATE msg event + notification.setNotificationType(queueEvent); + return toNotificationToSend(notification, institution, token); + } + + @Override + public NotificationToSend toNotificationToSend(NotificationToSend notification, Institution institution, Token token) { + notification.setInternalIstitutionID(institution.getId()); + notification.setProduct(token.getProductId()); + notification.setFilePath(token.getContractSigned()); + notification.setOnboardingTokenId(token.getId()); + // Queue.CreatedAt: onboarding complete date + notification.setCreatedAt(Optional.ofNullable(token.getActivatedAt()).orElse(token.getCreatedAt())); + + // ADD or UPDATE msg event + notification.setFileName(token.getContractSigned() == null ? "" : Paths.get(token.getContractSigned()).getFileName().toString()); + notification.setContentType(token.getContentType() == null ? "" : token.getContentType()); + + if (token.getProductId() != null && institution.getOnboarding() != null) { + Onboarding onboarding = institution.getOnboarding().stream() + .filter(o -> token.getProductId().equalsIgnoreCase(o.getProductId())) + .findFirst().orElseThrow(() -> new InvalidRequestException(String.format("Product %s not found", token.getProductId()), "0000")); + notification.setPricingPlan(onboarding.getPricingPlan()); + notification.setBilling(onboarding.getBilling() != null ? onboarding.getBilling() : institution.getBilling()); + notification.setInstitution(toInstitutionToNotify(institution)); + } + + return notification; + } + + private void sendNotification(String message, String tokenId) { + ListenableFuture> future = + kafkaTemplate.send(kafkaPropertiesConfig.getDatalakeContractsTopic(), message); + + future.addCallback(new ListenableFutureCallback<>() { + + @Override + public void onSuccess(SendResult result) { + log.info("sent dataLake notification for token : {}", tokenId); + } + + @Override + public void onFailure(Throwable ex) { + log.warn("error during send dataLake notification for token {}: {} ", tokenId, ex.getMessage(), ex); + } + }); + + } + + + + private InstitutionToNotify toInstitutionToNotify(Institution institution) { + InstitutionToNotify toNotify = new InstitutionToNotify(); + toNotify.setInstitutionType(institution.getInstitutionType()); + toNotify.setDescription(institution.getDescription()); + toNotify.setDigitalAddress(institution.getDigitalAddress() == null? coreConfig.getInstitutionAlternativeEmail(): institution.getDigitalAddress()); + toNotify.setAddress(institution.getAddress()); + toNotify.setTaxCode(institution.getTaxCode()); + toNotify.setOrigin(institution.getOrigin()); + toNotify.setOriginId(institution.getOriginId()); + toNotify.setZipCode(institution.getZipCode()); + toNotify.setPaymentServiceProvider(institution.getPaymentServiceProvider()); + if (institution.getSubunitType() != null && !institution.getSubunitType().equals("EC")) { + try { + InstitutionPaSubunitType.valueOf(institution.getSubunitType()); + toNotify.setSubUnitType(institution.getSubunitType()); + toNotify.setSubUnitCode(institution.getSubunitCode()); + } catch (IllegalArgumentException ignored) { + } + } + RootParent rootParent = new RootParent(); + rootParent.setDescription(institution.getParentDescription()); + if (StringUtils.hasText(institution.getRootParentId())) { + rootParent.setId(institution.getRootParentId()); + Institution rootParentInstitution = institutionConnector.findById(institution.getRootParentId()); + rootParent.setOriginId(Objects.nonNull(rootParentInstitution) ? rootParentInstitution.getOriginId() : null); + toNotify.setRootParent(rootParent); + } + + if (institution.getAttributes() != null && institution.getAttributes().size() > 0) { + toNotify.setCategory(institution.getAttributes().get(0).getCode()); + } + if (institution.getCity() == null) { + setInstitutionLocation(toNotify, institution); + } else { + toNotify.setCounty(institution.getCounty()); + toNotify.setCountry(institution.getCountry()); + toNotify.setIstatCode(institution.getIstatCode()); + toNotify.setCity(institution.getCity().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); + } + return toNotify; + } + + + + private void setInstitutionLocation(InstitutionToNotify toNotify, Institution institution) { + try { + InstitutionProxyInfo institutionProxyInfo = partyRegistryProxyConnector.getInstitutionById(institution.getExternalId()); + toNotify.setIstatCode(institutionProxyInfo.getIstatCode()); + toNotify.setCategory(institutionProxyInfo.getCategory()); + GeographicTaxonomies geographicTaxonomies = partyRegistryProxyConnector.getExtByCode(toNotify.getIstatCode()); + toNotify.setCounty(geographicTaxonomies.getProvinceAbbreviation()); + toNotify.setCountry(geographicTaxonomies.getCountryAbbreviation()); + toNotify.setCity(geographicTaxonomies.getDescription().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); + } catch (MsCoreException | ResourceNotFoundException e) { + log.warn("Error while searching institution {} on IPA, {} ", institution.getExternalId(), e.getMessage()); + toNotify.setIstatCode(null); + } + } +} diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractService.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractService.java index fefab3e69..f2c927536 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractService.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractService.java @@ -1,7 +1,6 @@ package it.pagopa.selfcare.mscore.core; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; @@ -10,28 +9,17 @@ import com.openhtmltopdf.svgsupport.BatikSVGDrawer; import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; -import it.pagopa.selfcare.commons.base.logging.LogUtils; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.commons.utils.crypto.model.SignatureInformation; import it.pagopa.selfcare.commons.utils.crypto.service.PadesSignService; import it.pagopa.selfcare.commons.utils.crypto.service.PadesSignServiceImpl; import it.pagopa.selfcare.commons.utils.crypto.service.Pkcs7HashSignService; import it.pagopa.selfcare.mscore.api.FileStorageConnector; -import it.pagopa.selfcare.mscore.api.InstitutionConnector; -import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; import it.pagopa.selfcare.mscore.config.CoreConfig; import it.pagopa.selfcare.mscore.config.PagoPaSignatureConfig; -import it.pagopa.selfcare.mscore.constant.RelationshipState; -import it.pagopa.selfcare.mscore.core.config.KafkaPropertiesConfig; -import it.pagopa.selfcare.mscore.core.util.InstitutionPaSubunitType; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; -import it.pagopa.selfcare.mscore.exception.MsCoreException; -import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; -import it.pagopa.selfcare.mscore.model.InstitutionToNotify; -import it.pagopa.selfcare.mscore.model.NotificationToSend; -import it.pagopa.selfcare.mscore.model.QueueEvent; -import it.pagopa.selfcare.mscore.model.RootParent; -import it.pagopa.selfcare.mscore.model.institution.*; +import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.institution.InstitutionGeographicTaxonomies; import it.pagopa.selfcare.mscore.model.onboarding.OnboardingRequest; import it.pagopa.selfcare.mscore.model.onboarding.ResourceResponse; import it.pagopa.selfcare.mscore.model.onboarding.Token; @@ -40,12 +28,7 @@ import org.apache.commons.text.StringSubstitutor; import org.jsoup.Jsoup; import org.jsoup.helper.W3CDom; -import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.kafka.support.SendResult; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; import org.springframework.web.multipart.MultipartFile; import java.io.File; @@ -58,7 +41,9 @@ import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.List; +import java.util.Map; +import java.util.UUID; import static it.pagopa.selfcare.mscore.constant.GenericError.GENERIC_ERROR; import static it.pagopa.selfcare.mscore.constant.GenericError.UNABLE_TO_DOWNLOAD_FILE; @@ -68,35 +53,23 @@ @Slf4j @Service public class ContractService { - - static final String DESCRIPTION_TO_REPLACE_REGEX = " - COMUNE"; private final PagoPaSignatureConfig pagoPaSignatureConfig; private final PadesSignService padesSignService; private final FileStorageConnector fileStorageConnector; private final CoreConfig coreConfig; private final SignatureService signatureService; - private final KafkaTemplate kafkaTemplate; - private final KafkaPropertiesConfig kafkaPropertiesConfig; private final ObjectMapper mapper; - private final PartyRegistryProxyConnector partyRegistryProxyConnector; - private final InstitutionConnector institutionConnector; public ContractService(PagoPaSignatureConfig pagoPaSignatureConfig, FileStorageConnector fileStorageConnector, CoreConfig coreConfig, Pkcs7HashSignService pkcs7HashSignService, - SignatureService signatureService, - KafkaTemplate kafkaTemplate, - KafkaPropertiesConfig kafkaPropertiesConfig, - PartyRegistryProxyConnector partyRegistryProxyConnector, - InstitutionConnector institutionConnector) { + SignatureService signatureService) { this.pagoPaSignatureConfig = pagoPaSignatureConfig; this.padesSignService = new PadesSignServiceImpl(pkcs7HashSignService); this.fileStorageConnector = fileStorageConnector; this.coreConfig = coreConfig; this.signatureService = signatureService; - this.kafkaTemplate = kafkaTemplate; - this.kafkaPropertiesConfig = kafkaPropertiesConfig; this.mapper = new ObjectMapper(); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<>() { @@ -106,8 +79,6 @@ public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator } }); mapper.registerModule(simpleModule); - this.partyRegistryProxyConnector = partyRegistryProxyConnector; - this.institutionConnector = institutionConnector; } public File createContractPDF(String contractTemplate, User validManager, List users, Institution institution, OnboardingRequest request, List geographicTaxonomies, InstitutionType institutionType) { @@ -231,148 +202,6 @@ public File getLogoFile() { } } - public void sendDataLakeNotification(Institution institution, Token token, QueueEvent queueEvent) { - log.debug(LogUtils.CONFIDENTIAL_MARKER, "sendDataLakeNotification institution = {}, token = {}, queueEvent = {}", institution, token, queueEvent); - if (institution != null) { - NotificationToSend notification = toNotificationToSend(institution, token, queueEvent); - log.debug(LogUtils.CONFIDENTIAL_MARKER, "Notification to send to the data lake, notification: {}", notification); - try { - String msg = mapper.writeValueAsString(notification); - sendNotification(msg, token.getId()); - } catch (JsonProcessingException e) { - log.warn("error during send dataLake notification for token {}", notification.getId()); - } - } - } - - public NotificationToSend toNotificationToSend(Institution institution, Token token, QueueEvent queueEvent) { - NotificationToSend notification = new NotificationToSend(); - if (queueEvent.equals(QueueEvent.ADD)) { - // When Onboarding.complete event id is the onboarding id - notification.setId(token.getId()); - notification.setState(RelationshipState.ACTIVE.toString()); - // when onboarding complete last update is activated date - notification.setUpdatedAt(Optional.ofNullable(token.getActivatedAt()).orElse(token.getCreatedAt())); - } else { - // New id - notification.setId(UUID.randomUUID().toString()); - notification.setState(token.getStatus() == RelationshipState.DELETED ? "CLOSED" : token.getStatus().toString()); - // when update last update is updated date - notification.setUpdatedAt(Optional.ofNullable(token.getUpdatedAt()).orElse(token.getCreatedAt())); - if (token.getStatus().equals(RelationshipState.DELETED)) { - // Queue.ClosedAt: if token.deleted show closedAt - notification.setClosedAt(Optional.ofNullable(token.getDeletedAt()).orElse(token.getUpdatedAt())); - notification.setUpdatedAt(Optional.ofNullable(token.getDeletedAt()).orElse(token.getUpdatedAt())); - } else { - // when update last update is updated date - notification.setUpdatedAt(Optional.ofNullable(token.getUpdatedAt()).orElse(token.getCreatedAt())); - } - } - // ADD or UPDATE msg event - notification.setNotificationType(queueEvent); - return toNotificationToSend(notification, institution, token); - } - - public NotificationToSend toNotificationToSend(NotificationToSend notification, Institution institution, Token token) { - notification.setInternalIstitutionID(institution.getId()); - notification.setProduct(token.getProductId()); - notification.setFilePath(token.getContractSigned()); - notification.setOnboardingTokenId(token.getId()); - // Queue.CreatedAt: onboarding complete date - notification.setCreatedAt(Optional.ofNullable(token.getActivatedAt()).orElse(token.getCreatedAt())); - - // ADD or UPDATE msg event - notification.setFileName(token.getContractSigned() == null ? "" : Paths.get(token.getContractSigned()).getFileName().toString()); - notification.setContentType(token.getContentType() == null ? "" : token.getContentType()); - - if (token.getProductId() != null && institution.getOnboarding() != null) { - Onboarding onboarding = institution.getOnboarding().stream() - .filter(o -> token.getProductId().equalsIgnoreCase(o.getProductId())) - .findFirst().orElseThrow(() -> new InvalidRequestException(String.format("Product %s not found", token.getProductId()), "0000")); - notification.setPricingPlan(onboarding.getPricingPlan()); - notification.setBilling(onboarding.getBilling() != null ? onboarding.getBilling() : institution.getBilling()); - notification.setInstitution(toInstitutionToNotify(institution)); - } - - return notification; - } - - private InstitutionToNotify toInstitutionToNotify(Institution institution) { - InstitutionToNotify toNotify = new InstitutionToNotify(); - toNotify.setInstitutionType(institution.getInstitutionType()); - toNotify.setDescription(institution.getDescription()); - toNotify.setDigitalAddress(institution.getDigitalAddress() == null? coreConfig.getInstitutionAlternativeEmail(): institution.getDigitalAddress()); - toNotify.setAddress(institution.getAddress()); - toNotify.setTaxCode(institution.getTaxCode()); - toNotify.setOrigin(institution.getOrigin()); - toNotify.setOriginId(institution.getOriginId()); - toNotify.setZipCode(institution.getZipCode()); - toNotify.setPaymentServiceProvider(institution.getPaymentServiceProvider()); - if (institution.getSubunitType() != null && !institution.getSubunitType().equals("EC")) { - try { - InstitutionPaSubunitType.valueOf(institution.getSubunitType()); - toNotify.setSubUnitType(institution.getSubunitType()); - toNotify.setSubUnitCode(institution.getSubunitCode()); - } catch (IllegalArgumentException ignored) { - } - } - RootParent rootParent = new RootParent(); - rootParent.setDescription(institution.getParentDescription()); - if (StringUtils.hasText(institution.getRootParentId())) { - rootParent.setId(institution.getRootParentId()); - Institution rootParentInstitution = institutionConnector.findById(institution.getRootParentId()); - rootParent.setOriginId(Objects.nonNull(rootParentInstitution) ? rootParentInstitution.getOriginId() : null); - toNotify.setRootParent(rootParent); - } - - if (institution.getAttributes() != null && institution.getAttributes().size() > 0) { - toNotify.setCategory(institution.getAttributes().get(0).getCode()); - } - if (institution.getCity() == null) { - setInstitutionLocation(toNotify, institution); - } else { - toNotify.setCounty(institution.getCounty()); - toNotify.setCountry(institution.getCountry()); - toNotify.setIstatCode(institution.getIstatCode()); - toNotify.setCity(institution.getCity().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); - } - return toNotify; - } - - private void sendNotification(String message, String tokenId) { - ListenableFuture> future = - kafkaTemplate.send(kafkaPropertiesConfig.getDatalakeContractsTopic(), message); - - future.addCallback(new ListenableFutureCallback<>() { - - @Override - public void onSuccess(SendResult result) { - log.info("sent dataLake notification for token : {}", tokenId); - } - - @Override - public void onFailure(Throwable ex) { - log.warn("error during send dataLake notification for token {}: {} ", tokenId, ex.getMessage(), ex); - } - }); - - } - - private void setInstitutionLocation(InstitutionToNotify toNotify, Institution institution) { - try { - InstitutionProxyInfo institutionProxyInfo = partyRegistryProxyConnector.getInstitutionById(institution.getExternalId()); - toNotify.setIstatCode(institutionProxyInfo.getIstatCode()); - toNotify.setCategory(institutionProxyInfo.getCategory()); - GeographicTaxonomies geographicTaxonomies = partyRegistryProxyConnector.getExtByCode(toNotify.getIstatCode()); - toNotify.setCounty(geographicTaxonomies.getProvinceAbbreviation()); - toNotify.setCountry(geographicTaxonomies.getCountryAbbreviation()); - toNotify.setCity(geographicTaxonomies.getDescription().replace(DESCRIPTION_TO_REPLACE_REGEX, "")); - } catch (MsCoreException | ResourceNotFoundException e) { - log.warn("Error while searching institution {} on IPA, {} ", institution.getExternalId(), e.getMessage()); - toNotify.setIstatCode(null); - } - } - public String uploadContract(String tokenId, MultipartFile contract) { return fileStorageConnector.uploadContract(tokenId, contract); diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java index c69b9c18b..33339528d 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImpl.java @@ -48,7 +48,7 @@ public class InstitutionServiceImpl implements InstitutionService { private final PartyRegistryProxyConnector partyRegistryProxyConnector; private final UserService userService; private final CoreConfig coreConfig; - private final ContractService contractService; + private final ContractEventNotificationService contractService; private final InstitutionMapper institutionMapper; private final CreateInstitutionStrategyFactory createInstitutionStrategyFactory; @@ -57,7 +57,7 @@ public InstitutionServiceImpl(PartyRegistryProxyConnector partyRegistryProxyConn UserService userService, CoreConfig coreConfig, TokenConnector tokenConnector, UserConnector userConnector, - ContractService contractService, + ContractEventNotificationService contractService, InstitutionMapper institutionMapper, CreateInstitutionStrategyFactory createInstitutionStrategyFactory, UserRegistryConnector userRegistryConnector) { diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java index dc8297859..40d311b68 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java @@ -60,6 +60,7 @@ public class OnboardingServiceImpl implements OnboardingService { private final UserRelationshipService userRelationshipService; private final UserEventService userEventService; private final ContractService contractService; + private final ContractEventNotificationService contractEventNotification; private final MailNotificationService notificationService; private final UserNotificationService userNotificationService; private final PagoPaSignatureConfig pagoPaSignatureConfig; @@ -74,7 +75,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao, UserRelationshipService userRelationshipService, ContractService contractService, UserEventService userEventService, - MailNotificationService notificationService, + ContractEventNotificationService contractEventNotification, MailNotificationService notificationService, UserNotificationService userNotificationService, PagoPaSignatureConfig pagoPaSignatureConfig, OnboardingInstitutionStrategyFactory institutionStrategyFactory, @@ -87,6 +88,7 @@ public OnboardingServiceImpl(OnboardingDao onboardingDao, this.userRelationshipService = userRelationshipService; this.userEventService = userEventService; this.contractService = contractService; + this.contractEventNotification = contractEventNotification; this.notificationService = notificationService; this.userNotificationService = userNotificationService; this.pagoPaSignatureConfig = pagoPaSignatureConfig; @@ -216,7 +218,7 @@ public Institution persistOnboarding(String institutionId, String productId,List token.setStatus(onboarding.getStatus()); token.setContractSigned(onboarding.getContract()); institution.setOnboarding(List.of(onboarding)); - contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD); + contractEventNotification.sendDataLakeNotification(institution, token, QueueEvent.ADD); userEventService.sendLegalTokenUserNotification(token); return institutionUpdated; @@ -269,7 +271,7 @@ public void completeOnboarding(Token token, MultipartFile contract, Consumer page_size_api = Optional.empty(); private Optional page = Optional.empty(); @@ -36,7 +36,7 @@ public class QueueNotificationServiceImpl implements QueueNotificationService { @Autowired - public QueueNotificationServiceImpl(ContractService contractService, + public QueueNotificationServiceImpl(ContractEventNotificationService contractService, UserEventService userEventService, TokenConnector tokenConnector, InstitutionConnector institutionConnector, UserConnector userConnector) { diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/TokenServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/TokenServiceImpl.java index e29d50c88..043ee868e 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/TokenServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/TokenServiceImpl.java @@ -27,13 +27,13 @@ public class TokenServiceImpl implements TokenService { private final UserService userService; private final OnboardingDao onboardingDao; private final InstitutionConnector institutionConnector; - private final ContractService contractService; + private final ContractEventNotificationService contractService; public TokenServiceImpl(TokenConnector tokenConnector, UserService userService, OnboardingDao onboardingDao, InstitutionConnector institutionConnector, - ContractService contractService) { + ContractEventNotificationService contractService) { this.tokenConnector = tokenConnector; this.userService = userService; this.onboardingDao = onboardingDao; diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java index 56ccc50ca..a3df9d3c9 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/strategy/factory/OnboardingInstitutionStrategyFactory.java @@ -40,6 +40,7 @@ public class OnboardingInstitutionStrategyFactory { private final OnboardingDao onboardingDao; private final ContractService contractService; + private final ContractEventNotificationService contractEventNotificationService; private final UserService userService; private final InstitutionService institutionService; private final CoreConfig coreConfig; @@ -49,12 +50,13 @@ public class OnboardingInstitutionStrategyFactory { public OnboardingInstitutionStrategyFactory(OnboardingDao onboardingDao, ContractService contractService, - UserService userService, + ContractEventNotificationService contractEventNotificationService, UserService userService, InstitutionService institutionService, CoreConfig coreConfig, MailNotificationService mailNotificationService, FileStorageConnector fileStorageConnector, UserEventService userEventService) { this.onboardingDao = onboardingDao; this.contractService = contractService; + this.contractEventNotificationService = contractEventNotificationService; this.userService = userService; this.institutionService = institutionService; this.coreConfig = coreConfig; @@ -257,7 +259,7 @@ private Consumer sendEmailWithLogoOrRollback } //[TODO https://pagopa.atlassian.net/wiki/spaces/SCP/pages/710901785/RFC+Proposta+per+gestione+asincrona+degli+eventi] - contractService.sendDataLakeNotification(strategyInput.getOnboardingRollback().getUpdatedInstitution(), strategyInput.getOnboardingRollback().getToken(), QueueEvent.ADD); + contractEventNotificationService.sendDataLakeNotification(strategyInput.getOnboardingRollback().getUpdatedInstitution(), strategyInput.getOnboardingRollback().getToken(), QueueEvent.ADD); userEventService.sendLegalTokenUserNotification(strategyInput.getOnboardingRollback().getToken()); } catch (Exception e) { onboardingDao.rollbackSecondStep(strategyInput.getToUpdate(), strategyInput.getToDelete(), strategyInput.getInstitution().getId(), diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java new file mode 100644 index 000000000..cc80eb648 --- /dev/null +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java @@ -0,0 +1,611 @@ +package it.pagopa.selfcare.mscore.core; + +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.europa.esig.dss.spi.tsl.TrustedListsCertificateSource; +import it.pagopa.selfcare.commons.base.security.PartyRole; +import it.pagopa.selfcare.commons.utils.crypto.service.Pkcs7HashSignService; +import it.pagopa.selfcare.mscore.api.InstitutionConnector; +import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; +import it.pagopa.selfcare.mscore.api.UserRegistryConnector; +import it.pagopa.selfcare.mscore.config.CoreConfig; +import it.pagopa.selfcare.mscore.config.PagoPaSignatureConfig; +import it.pagopa.selfcare.mscore.constant.RelationshipState; +import it.pagopa.selfcare.mscore.core.config.KafkaPropertiesConfig; +import it.pagopa.selfcare.mscore.exception.MsCoreException; +import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; +import it.pagopa.selfcare.mscore.model.Certification; +import it.pagopa.selfcare.mscore.model.CertifiedField; +import it.pagopa.selfcare.mscore.model.NotificationToSend; +import it.pagopa.selfcare.mscore.model.QueueEvent; +import it.pagopa.selfcare.mscore.model.institution.*; +import it.pagopa.selfcare.mscore.model.onboarding.Token; +import it.pagopa.selfcare.mscore.model.onboarding.TokenUser; +import it.pagopa.selfcare.mscore.model.user.User; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.MediaType; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.ProducerFactory; + +import java.time.OffsetDateTime; +import java.util.*; +import java.util.concurrent.ExecutionException; + +import static it.pagopa.selfcare.commons.utils.TestUtils.checkNotNullFields; +import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; + +@ExtendWith(MockitoExtension.class) +public class ContractEventNotificationServiceImplTest { + + + + @InjectMocks + private ContractEventNotificationServiceImpl contractService; + @Mock + private KafkaTemplate kafkaTemplate; + + @Mock + private PartyRegistryProxyConnector partyRegistryProxyConnectorMock; + + @Mock + private KafkaPropertiesConfig kafkaPropertiesConfig; + + @Mock + private InstitutionConnector institutionConnector; + + /** + * Method under test: {@link ContractEventNotificationServiceImpl#sendDataLakeNotification(Institution, Token, QueueEvent)} + */ + @Test + void testSendDataLakeNotification2() throws ExecutionException, InterruptedException { + ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); + when(producerFactory.transactionCapable()).thenReturn(true); + KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + + CoreConfig coreConfig = new CoreConfig(); + + UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); + PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); + InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), + new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + Onboarding onboarding = mockInstance(new Onboarding()); + onboarding.setProductId("prod"); + + Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + + TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); + TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); + + Token token = mockInstance(new Token()); + token.setId(UUID.randomUUID().toString()); + token.setProductId("prod"); + token.setStatus(RelationshipState.ACTIVE); + token.setInstitutionUpdate(institutionUpdate); + token.setDeletedAt(null); + token.setUsers(List.of(tokenUser1, tokenUser2)); + token.setContractSigned("docs/parties".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); + token.setContentType(MediaType.APPLICATION_JSON_VALUE); + + User user1 = new User(); + user1.setId(tokenUser1.getUserId()); + user1.setName(createCertifiedField_certified("User1Name")); + user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); + user1.setFiscalCode("FiscalCode1"); + Map workContacts1 = new HashMap<>(); + workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); + workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); + user1.setWorkContacts(workContacts1); + + User user2 = new User(); + user2.setId(tokenUser1.getUserId()); + user2.setName(createCertifiedField_uncertified("User2Name")); + user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); + user2.setFiscalCode("FiscalCode2"); + Map workContacts2 = new HashMap<>(); + workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); + workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); + workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); + user2.setWorkContacts(workContacts2); + + InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo()); + institutionProxyInfoMock.setTaxCode(institution.getExternalId()); + + GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); + geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); + when(partyRegistryProxyConnector.getInstitutionById(any())) + .thenReturn(institutionProxyInfoMock); + when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); + + assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), + "Topic cannot be null"); + + verify(partyRegistryProxyConnector, times(1)) + .getInstitutionById(institution.getExternalId()); + verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); + } + + @Test + void testSendDataLakeNotification3() { + ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); + when(producerFactory.transactionCapable()).thenReturn(true); + KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + CoreConfig coreConfig = new CoreConfig(); + + UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); + PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); + InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), + new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + + Onboarding onboarding = mockInstance(new Onboarding()); + onboarding.setProductId("prod"); + + Institution institution = mockInstance(new Institution()); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + + TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); + TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); + + Token token = mockInstance(new Token()); + token.setId(UUID.randomUUID().toString()); + token.setProductId("prod"); + token.setStatus(RelationshipState.ACTIVE); + token.setInstitutionUpdate(institutionUpdate); + token.setDeletedAt(null); + token.setUsers(List.of(tokenUser1, tokenUser2)); + token.setContractSigned("docs/parties".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); + token.setContentType(MediaType.APPLICATION_JSON_VALUE); + assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), + "Topic cannot be null"); + + verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); + } + + /** + * Method under test: {@link ContractEventNotificationServiceImpl#sendDataLakeNotification(Institution, Token, QueueEvent)} + */ + @ParameterizedTest + @ValueSource(classes = { + MsCoreException.class, + ResourceNotFoundException.class + }) + void testSendDataLakeNotification_notOnIpa(Class clazz) throws ExecutionException, InterruptedException { + ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); + when(producerFactory.transactionCapable()).thenReturn(true); + KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); + CoreConfig coreConfig = new CoreConfig(); + Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); + SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); + UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); + PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); + InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + + ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), + new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + + Onboarding onboarding = mockInstance(new Onboarding()); + onboarding.setProductId("prod"); + + Institution institution = mockInstance(new Institution(), "setCity"); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + + TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); + TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); + + Token token = mockInstance(new Token()); + token.setProductId("prod"); + token.setStatus(RelationshipState.ACTIVE); + token.setInstitutionUpdate(institutionUpdate); + token.setDeletedAt(null); + token.setUsers(List.of(tokenUser1, tokenUser2)); + token.setContractSigned(null); + + User user1 = new User(); + user1.setId(tokenUser1.getUserId()); + user1.setName(createCertifiedField_certified("User1Name")); + user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); + user1.setFiscalCode("FiscalCode1"); + Map workContacts1 = new HashMap<>(); + workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); + workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); + user1.setWorkContacts(workContacts1); + + User user2 = new User(); + user2.setId(tokenUser1.getUserId()); + user2.setName(createCertifiedField_uncertified("User2Name")); + user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); + user2.setFiscalCode("FiscalCode2"); + Map workContacts2 = new HashMap<>(); + workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); + workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); + workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); + user2.setWorkContacts(workContacts2); + + Exception exceptionMock = (Exception) Mockito.mock(clazz); + + when(partyRegistryProxyConnector.getInstitutionById(any())) + .thenThrow(exceptionMock); + + assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), + "Topic cannot be null"); + + verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); + } + + @Test + void testSendDataLakeNotification_updateQueueEvent() { + ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); + when(producerFactory.transactionCapable()).thenReturn(true); + KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); + CoreConfig coreConfig = new CoreConfig(); + Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); + SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); + UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); + PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); + InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + + ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), + new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + + Onboarding onboarding = mockInstance(new Onboarding()); + onboarding.setProductId("prod"); + + Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + + TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); + TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); + + Token token = mockInstance(new Token()); + token.setProductId("prod"); + token.setStatus(RelationshipState.DELETED); + token.setInstitutionUpdate(institutionUpdate); + token.setDeletedAt(null); + token.setUsers(List.of(tokenUser1, tokenUser2)); + token.setContractSigned(null); + token.setContentType(null); + + User user1 = new User(); + user1.setId(tokenUser1.getUserId()); + user1.setName(createCertifiedField_certified("User1Name")); + user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); + user1.setFiscalCode("FiscalCode1"); + Map workContacts1 = new HashMap<>(); + workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); + workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); + user1.setWorkContacts(workContacts1); + + User user2 = new User(); + user2.setId(tokenUser1.getUserId()); + user2.setName(createCertifiedField_uncertified("User2Name")); + user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); + user2.setFiscalCode("FiscalCode2"); + Map workContacts2 = new HashMap<>(); + workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); + workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); + workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); + user2.setWorkContacts(workContacts2); + + InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo()); + institutionProxyInfoMock.setTaxCode(institution.getExternalId()); + + GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); + geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); + when(partyRegistryProxyConnector.getInstitutionById(any())) + .thenReturn(institutionProxyInfoMock); + when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); + + assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.UPDATE), + "Topic cannot be null"); + + verify(partyRegistryProxyConnector, times(1)) + .getInstitutionById(institution.getExternalId()); + } + + + + /** + * Method under test: {@link ContractEventNotificationServiceImpl#toNotificationToSend(Institution, Token, QueueEvent)} + */ + @Test + void testGenerateMessageActiveWithActivatedAt() throws ExecutionException, InterruptedException { + + String institutionId = "i1"; + String tokenId = "t1"; + + Onboarding onboarding = createOnboarding(tokenId, "prod"); + Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + Token token = createToken(institutionId, tokenId, institutionUpdate, + RelationshipState.ACTIVE, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institution); + + NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.ADD); + + assertNotNull(notification); + assertNull(notification.getClosedAt()); + assertEquals(RelationshipState.ACTIVE.toString(), notification.getState()); + assertEquals(token.getActivatedAt(), notification.getCreatedAt()); + assertEquals(token.getUpdatedAt(), notification.getCreatedAt()); + assertEquals(QueueEvent.ADD, notification.getNotificationType()); + } + + /** + * Method under test: {@link ContractEventNotificationServiceImpl#toNotificationToSend(Institution, Token, QueueEvent)} + */ + @Test + void testGenerateMessageActiveWithoutActivatedAt() { + + String institutionId = "i1"; + String tokenId = "t1"; + + Onboarding onboarding = createOnboarding(tokenId, "prod"); + Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + Token token = createToken(institutionId, tokenId, institutionUpdate, + RelationshipState.ACTIVE, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institution); + + NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.ADD); + + assertNotNull(notification); + assertNull(notification.getClosedAt()); + assertEquals(RelationshipState.ACTIVE.toString(), notification.getState()); + assertEquals(token.getCreatedAt(), notification.getCreatedAt()); + assertEquals(token.getCreatedAt(), notification.getUpdatedAt()); + assertEquals(QueueEvent.ADD, notification.getNotificationType()); + } + + /** + * Method under test: {@link ContractEventNotificationServiceImpl#toNotificationToSend(Institution, Token, QueueEvent)} + */ + @Test + void testGenerateMessageClosedWithoutActivatedAt() { + + String institutionId = "i1"; + String tokenId = "t1"; + + Onboarding onboarding = createOnboarding(tokenId, "prod"); + Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); + InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); + Token token = createToken(institutionId, tokenId, institutionUpdate, + RelationshipState.DELETED, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institution); + when(institutionConnector.findById(any())).thenReturn(null); + + NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.UPDATE); + + assertNotNull(notification); + assertNotNull(notification.getClosedAt()); + assertEquals("CLOSED", notification.getState()); + assertEquals(token.getCreatedAt(), notification.getCreatedAt()); + assertEquals(token.getUpdatedAt(), notification.getUpdatedAt()); + assertEquals(QueueEvent.UPDATE, notification.getNotificationType()); + } + + @Test + void toNotificationToSend_attributesNull() { + //given + final String institutionId = UUID.randomUUID().toString(); + final String tokenId = UUID.randomUUID().toString(); + Institution institutionMock = createInstitution(institutionId, createOnboarding(tokenId, "product")); + institutionMock.setAttributes(null); + institutionMock.setOrigin("SELC"); + institutionMock.setRootParentId(null); + InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo()); + institutionProxyInfoMock.setTaxCode(institutionMock.getTaxCode()); + Token tokenMock = createToken(institutionId, tokenId, null, + RelationshipState.ACTIVE, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + tokenMock.setProductId("product"); + //when + NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); + //then + checkNotNullFields(notificationToSend, "closedAt"); + } + + @Test + void toNotificationToSend_emptyAttributes() { + //given + final String institutionId = UUID.randomUUID().toString(); + final String tokenId = UUID.randomUUID().toString(); + Institution institutionMock = createInstitutionWithoutLocation(institutionId, createOnboarding(tokenId, "product")); + institutionMock.setAttributes(new ArrayList<>()); + institutionMock.setOrigin("IPA"); + institutionMock.setRootParentId(null); + Token tokenMock = createToken(institutionId, tokenId, null, + RelationshipState.ACTIVE, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + tokenMock.setProductId("product"); + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); + //when + NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); + //then + checkNotNullFields(notificationToSend, "closedAt"); + } + + @Test + void toNotificationToSend_nullLocation() { + //given + final String institutionId = UUID.randomUUID().toString(); + final String tokenId = UUID.randomUUID().toString(); + Onboarding onboarding = createOnboarding(tokenId, "prod"); + Institution institutionMock = createInstitutionWithoutLocation(institutionId, onboarding); + institutionMock.setRootParentId(null); + Token tokenMock = createToken(institutionId, tokenId, null, + RelationshipState.DELETED, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + tokenMock.setProductId("prod"); + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); + //when + NotificationToSend notification = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.UPDATE); + //then + assertNotNull(notification.getInstitution().getCategory()); + assertNotNull(notification.getInstitution().getCity()); + verify(partyRegistryProxyConnectorMock, times(1)).getInstitutionById(institutionMock.getExternalId()); + verify(partyRegistryProxyConnectorMock, times(1)).getExtByCode(any()); + } + + @Test + void toNotificationAttributesNotNull() { + //given + final String institutionId = UUID.randomUUID().toString(); + final String tokenId = UUID.randomUUID().toString(); + Institution institutionMock = createInstitution(institutionId, createOnboarding(tokenId, "product")); + Attributes attribute = new Attributes(); + attribute.setCode("code"); + institutionMock.setAttributes(List.of(attribute)); + institutionMock.setOrigin("IPA"); + institutionMock.setCity(null); + institutionMock.setRootParentId(null); + Token tokenMock = createToken(institutionId, tokenId, null, + RelationshipState.ACTIVE, + OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt + null, // activatedAt + OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt + null); // deletedAt + tokenMock.setProductId("product"); + mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); + //when + NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); + //then + checkNotNullFields(notificationToSend, "closedAt"); + + } + + + + private static Institution createInstitution(String institutionId, Onboarding onboarding) { + Institution institution = mockInstance(new Institution()); + institution.setId(institutionId); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + return institution; + } + + private static Onboarding createOnboarding() { + return mockInstance(new Onboarding()); + } + + private static Institution createInstitutionWithoutLocation(String institutionId, Onboarding onboarding) { + Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); + institution.setId(institutionId); + institution.setOrigin("IPA"); + institution.setOnboarding(List.of(onboarding)); + return institution; + } + + + private static Onboarding createOnboarding(String tokenId, String productId) { + Onboarding onboarding = mockInstance(new Onboarding()); + onboarding.setProductId(productId); + onboarding.setTokenId(tokenId); + return onboarding; + } + + private static Token createToken(String institutionId, String tokenId, InstitutionUpdate institutionUpdate, + RelationshipState status, + OffsetDateTime createdAt, OffsetDateTime activatedAt, + OffsetDateTime updatedAt, OffsetDateTime deletedAt) { + TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); + TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); + + Token token = mockInstance(new Token()); + token.setId(tokenId); + token.setInstitutionId(institutionId); + token.setProductId("prod"); + token.setStatus(status); + token.setInstitutionUpdate(institutionUpdate); + token.setCreatedAt(createdAt); + token.setActivatedAt(activatedAt); + token.setUpdatedAt(updatedAt); + token.setDeletedAt(deletedAt); + token.setUsers(List.of(tokenUser1, tokenUser2)); + token.setContractSigned("ContractPath".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); + token.setContentType(MediaType.APPLICATION_JSON_VALUE); + return token; + } + + private static void mockPartyRegistryProxy(PartyRegistryProxyConnector partyRegistryProxyConnector, Institution institution) { + InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo(), "setCity", "setCounty", "setCountry"); + institutionProxyInfoMock.setTaxCode(institution.getExternalId()); + + GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); + geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); + + when(partyRegistryProxyConnector.getInstitutionById(any())) + .thenReturn(institutionProxyInfoMock); + when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); + } + + private WorkContact createWorkContact(String workContactEmail) { + WorkContact workContact = new WorkContact(); + workContact.setEmail(createCertifiedField_certified(workContactEmail)); + return workContact; + } + + private CertifiedField createCertifiedField_certified(String fieldValue) { + CertifiedField certifiedField = new CertifiedField<>(); + certifiedField.setCertification(Certification.SPID); + certifiedField.setValue(fieldValue); + return certifiedField; + } + + private CertifiedField createCertifiedField_uncertified(String fieldValue) { + CertifiedField certifiedField = new CertifiedField<>(); + certifiedField.setCertification(Certification.NONE); + certifiedField.setValue(fieldValue); + return certifiedField; + } +} diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractServiceTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractServiceTest.java index ecf4e5a3b..58182961b 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractServiceTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractServiceTest.java @@ -1,6 +1,5 @@ package it.pagopa.selfcare.mscore.core; -import com.fasterxml.jackson.core.JsonProcessingException; import eu.europa.esig.dss.detailedreport.jaxb.XmlDetailedReport; import eu.europa.esig.dss.diagnostic.jaxb.XmlDiagnosticData; import eu.europa.esig.dss.simplereport.jaxb.XmlSimpleReport; @@ -8,64 +7,43 @@ import eu.europa.esig.dss.validation.SignedDocumentValidator; import eu.europa.esig.dss.validation.reports.Reports; import eu.europa.esig.validationreport.jaxb.ValidationReportType; -import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.commons.utils.crypto.service.Pkcs7HashSignService; import it.pagopa.selfcare.mscore.api.FileStorageConnector; -import it.pagopa.selfcare.mscore.api.InstitutionConnector; -import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; -import it.pagopa.selfcare.mscore.api.UserRegistryConnector; import it.pagopa.selfcare.mscore.config.CoreConfig; import it.pagopa.selfcare.mscore.config.PagoPaSignatureConfig; -import it.pagopa.selfcare.mscore.constant.RelationshipState; -import it.pagopa.selfcare.mscore.core.config.KafkaPropertiesConfig; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; -import it.pagopa.selfcare.mscore.exception.MsCoreException; -import it.pagopa.selfcare.mscore.exception.ResourceNotFoundException; -import it.pagopa.selfcare.mscore.model.Certification; import it.pagopa.selfcare.mscore.model.CertifiedField; -import it.pagopa.selfcare.mscore.model.NotificationToSend; -import it.pagopa.selfcare.mscore.model.QueueEvent; -import it.pagopa.selfcare.mscore.model.institution.*; +import it.pagopa.selfcare.mscore.model.institution.Institution; +import it.pagopa.selfcare.mscore.model.institution.InstitutionGeographicTaxonomies; +import it.pagopa.selfcare.mscore.model.institution.InstitutionUpdate; +import it.pagopa.selfcare.mscore.model.institution.WorkContact; import it.pagopa.selfcare.mscore.model.onboarding.OnboardingRequest; import it.pagopa.selfcare.mscore.model.onboarding.ResourceResponse; import it.pagopa.selfcare.mscore.model.onboarding.Token; -import it.pagopa.selfcare.mscore.model.onboarding.TokenUser; import it.pagopa.selfcare.mscore.model.user.User; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.http.MediaType; -import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.kafka.core.ProducerFactory; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import java.time.OffsetDateTime; -import java.util.*; -import java.util.concurrent.ExecutionException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -import static it.pagopa.selfcare.commons.utils.TestUtils.checkNotNullFields; -import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class ContractServiceTest { - @Mock - private KafkaTemplate kafkaTemplate; - - @Mock - private Pkcs7HashSignService pkcs7HashSignService; @InjectMocks private ContractService contractService; @@ -82,12 +60,6 @@ class ContractServiceTest { @Mock private CoreConfig coreConfig; - @Mock - private PartyRegistryProxyConnector partyRegistryProxyConnectorMock; - - @Mock - private KafkaPropertiesConfig kafkaPropertiesConfig; - @Test void createContractPDF() { String contract = "contract"; @@ -242,555 +214,6 @@ void getLogoFile1() { assertThrows(InvalidRequestException.class, () -> contractService.getLogoFile()); } - /** - * Method under test: {@link ContractService#sendDataLakeNotification(Institution, Token, QueueEvent)} - */ - @Test - void testSendDataLakeNotification2() throws ExecutionException, InterruptedException { - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); - CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - ContractService contractService = new ContractService(pagoPaSignatureConfig, null, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector); - - Onboarding onboarding = mockInstance(new Onboarding()); - onboarding.setProductId("prod"); - - Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - - TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); - TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); - - Token token = mockInstance(new Token()); - token.setId(UUID.randomUUID().toString()); - token.setProductId("prod"); - token.setStatus(RelationshipState.ACTIVE); - token.setInstitutionUpdate(institutionUpdate); - token.setDeletedAt(null); - token.setUsers(List.of(tokenUser1, tokenUser2)); - token.setContractSigned("docs/parties".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); - token.setContentType(MediaType.APPLICATION_JSON_VALUE); - - User user1 = new User(); - user1.setId(tokenUser1.getUserId()); - user1.setName(createCertifiedField_certified("User1Name")); - user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); - user1.setFiscalCode("FiscalCode1"); - Map workContacts1 = new HashMap<>(); - workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); - workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); - user1.setWorkContacts(workContacts1); - - User user2 = new User(); - user2.setId(tokenUser1.getUserId()); - user2.setName(createCertifiedField_uncertified("User2Name")); - user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); - user2.setFiscalCode("FiscalCode2"); - Map workContacts2 = new HashMap<>(); - workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); - workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); - workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); - user2.setWorkContacts(workContacts2); - - InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo()); - institutionProxyInfoMock.setTaxCode(institution.getExternalId()); - - GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); - geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); - when(partyRegistryProxyConnector.getInstitutionById(any())) - .thenReturn(institutionProxyInfoMock); - when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); - - assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), - "Topic cannot be null"); - - verify(partyRegistryProxyConnector, times(1)) - .getInstitutionById(institution.getExternalId()); - verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); - } - - @Test - void testSendDataLakeNotification3() throws ExecutionException, InterruptedException { - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); - CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - ContractService contractService = new ContractService(pagoPaSignatureConfig, null, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector); - - Onboarding onboarding = mockInstance(new Onboarding()); - onboarding.setProductId("prod"); - - Institution institution = mockInstance(new Institution()); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - - TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); - TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); - - Token token = mockInstance(new Token()); - token.setId(UUID.randomUUID().toString()); - token.setProductId("prod"); - token.setStatus(RelationshipState.ACTIVE); - token.setInstitutionUpdate(institutionUpdate); - token.setDeletedAt(null); - token.setUsers(List.of(tokenUser1, tokenUser2)); - token.setContractSigned("docs/parties".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); - token.setContentType(MediaType.APPLICATION_JSON_VALUE); - assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), - "Topic cannot be null"); - - verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); - } - - /** - * Method under test: {@link ContractService#sendDataLakeNotification(Institution, Token, QueueEvent)} - */ - @ParameterizedTest - @ValueSource(classes = { - MsCoreException.class, - ResourceNotFoundException.class - }) - void testSendDataLakeNotification_notOnIpa(Class clazz) throws ExecutionException, InterruptedException { - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); - CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - ContractService contractService = new ContractService(pagoPaSignatureConfig, null, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector); - - Onboarding onboarding = mockInstance(new Onboarding()); - onboarding.setProductId("prod"); - - Institution institution = mockInstance(new Institution(), "setCity"); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - - TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); - TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); - - Token token = mockInstance(new Token()); - token.setProductId("prod"); - token.setStatus(RelationshipState.ACTIVE); - token.setInstitutionUpdate(institutionUpdate); - token.setDeletedAt(null); - token.setUsers(List.of(tokenUser1, tokenUser2)); - token.setContractSigned(null); - - User user1 = new User(); - user1.setId(tokenUser1.getUserId()); - user1.setName(createCertifiedField_certified("User1Name")); - user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); - user1.setFiscalCode("FiscalCode1"); - Map workContacts1 = new HashMap<>(); - workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); - workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); - user1.setWorkContacts(workContacts1); - - User user2 = new User(); - user2.setId(tokenUser1.getUserId()); - user2.setName(createCertifiedField_uncertified("User2Name")); - user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); - user2.setFiscalCode("FiscalCode2"); - Map workContacts2 = new HashMap<>(); - workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); - workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); - workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); - user2.setWorkContacts(workContacts2); - - Exception exceptionMock = (Exception) Mockito.mock(clazz); - - when(partyRegistryProxyConnector.getInstitutionById(any())) - .thenThrow(exceptionMock); - - assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.ADD), - "Topic cannot be null"); - - verifyNoMoreInteractions(userRegistryConnector, partyRegistryProxyConnector); - } - - @Test - void testSendDataLakeNotification_updateQueueEvent() throws ExecutionException, InterruptedException { - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); - CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - ContractService contractService = new ContractService(pagoPaSignatureConfig, null, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector); - - Onboarding onboarding = mockInstance(new Onboarding()); - onboarding.setProductId("prod"); - - Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - - TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); - TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); - - Token token = mockInstance(new Token()); - token.setProductId("prod"); - token.setStatus(RelationshipState.DELETED); - token.setInstitutionUpdate(institutionUpdate); - token.setDeletedAt(null); - token.setUsers(List.of(tokenUser1, tokenUser2)); - token.setContractSigned(null); - token.setContentType(null); - - User user1 = new User(); - user1.setId(tokenUser1.getUserId()); - user1.setName(createCertifiedField_certified("User1Name")); - user1.setFamilyName(createCertifiedField_certified("User1FamilyName")); - user1.setFiscalCode("FiscalCode1"); - Map workContacts1 = new HashMap<>(); - workContacts1.put("NotFoundInstitutionId", createWorkContact("user1workemailNotFound@examepl.com")); - workContacts1.put(institution.getId(), createWorkContact("user1workEmail@example.com")); - user1.setWorkContacts(workContacts1); - - User user2 = new User(); - user2.setId(tokenUser1.getUserId()); - user2.setName(createCertifiedField_uncertified("User2Name")); - user2.setFamilyName(createCertifiedField_certified("User2FamilyName")); - user2.setFiscalCode("FiscalCode2"); - Map workContacts2 = new HashMap<>(); - workContacts2.put(institution.getId(), createWorkContact("user2workEmail@example.com")); - workContacts2.put("NotFoundInstitutionId", createWorkContact("user2workemailNotFound@examepl.com")); - workContacts2.put("NotFoundInstitutionId2", createWorkContact("user2workemailNotFound2@examepl.com")); - user2.setWorkContacts(workContacts2); - - InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo()); - institutionProxyInfoMock.setTaxCode(institution.getExternalId()); - - GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); - geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); - when(partyRegistryProxyConnector.getInstitutionById(any())) - .thenReturn(institutionProxyInfoMock); - when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); - - assertThrows(IllegalArgumentException.class, () -> contractService.sendDataLakeNotification(institution, token, QueueEvent.UPDATE), - "Topic cannot be null"); - - verify(partyRegistryProxyConnector, times(1)) - .getInstitutionById(institution.getExternalId()); - } - - ContractService createContractServiceMock(InstitutionConnector institutionConnector, - PartyRegistryProxyConnector partyRegistryProxyConnector) { - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); - CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - return new ContractService(pagoPaSignatureConfig, null, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector); - - } - - /** - * Method under test: {@link ContractService#toNotificationToSend(Institution, Token, QueueEvent)} - */ - @Test - void testGenerateMessageActiveWithActivatedAt() throws ExecutionException, InterruptedException { - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - ContractService contractService = createContractServiceMock(institutionConnector, partyRegistryProxyConnector); - - String institutionId = "i1"; - String tokenId = "t1"; - - Onboarding onboarding = createOnboarding(tokenId, "prod"); - Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - Token token = createToken(institutionId, tokenId, institutionUpdate, - RelationshipState.ACTIVE, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - - mockPartyRegistryProxy(partyRegistryProxyConnector, institution); - when(institutionConnector.findById(any())).thenReturn(null); - - NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.ADD); - - assertNotNull(notification); - assertNull(notification.getClosedAt()); - assertEquals(RelationshipState.ACTIVE.toString(), notification.getState()); - assertEquals(token.getActivatedAt(), notification.getCreatedAt()); - assertEquals(token.getUpdatedAt(), notification.getCreatedAt()); - assertEquals(QueueEvent.ADD, notification.getNotificationType()); - } - - /** - * Method under test: {@link ContractService#toNotificationToSend(Institution, Token, QueueEvent)} - */ - @Test - void testGenerateMessageActiveWithoutActivatedAt() throws ExecutionException, InterruptedException { - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - ContractService contractService = createContractServiceMock(institutionConnector, partyRegistryProxyConnector); - - String institutionId = "i1"; - String tokenId = "t1"; - - Onboarding onboarding = createOnboarding(tokenId, "prod"); - Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - Token token = createToken(institutionId, tokenId, institutionUpdate, - RelationshipState.ACTIVE, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - - mockPartyRegistryProxy(partyRegistryProxyConnector, institution); - when(institutionConnector.findById(any())).thenReturn(null); - - NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.ADD); - - assertNotNull(notification); - assertNull(notification.getClosedAt()); - assertEquals(RelationshipState.ACTIVE.toString(), notification.getState()); - assertEquals(token.getCreatedAt(), notification.getCreatedAt()); - assertEquals(token.getCreatedAt(), notification.getUpdatedAt()); - assertEquals(QueueEvent.ADD, notification.getNotificationType()); - } - - /** - * Method under test: {@link ContractService#toNotificationToSend(Institution, Token, QueueEvent)} - */ - @Test - void testGenerateMessageClosedWithoutActivatedAt() throws ExecutionException, InterruptedException { - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - ContractService contractService = createContractServiceMock(institutionConnector, partyRegistryProxyConnector); - - String institutionId = "i1"; - String tokenId = "t1"; - - Onboarding onboarding = createOnboarding(tokenId, "prod"); - Institution institution = createInstitutionWithoutLocation(institutionId, onboarding); - InstitutionUpdate institutionUpdate = mockInstance(new InstitutionUpdate()); - Token token = createToken(institutionId, tokenId, institutionUpdate, - RelationshipState.DELETED, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - - mockPartyRegistryProxy(partyRegistryProxyConnector, institution); - when(institutionConnector.findById(any())).thenReturn(null); - - NotificationToSend notification = contractService.toNotificationToSend(institution, token, QueueEvent.UPDATE); - - assertNotNull(notification); - assertNotNull(notification.getClosedAt()); - assertEquals("CLOSED", notification.getState()); - assertEquals(token.getCreatedAt(), notification.getCreatedAt()); - assertEquals(token.getUpdatedAt(), notification.getUpdatedAt()); - assertEquals(QueueEvent.UPDATE, notification.getNotificationType()); - } - - @Test - void toNotificationToSend_attributesNull() throws JsonProcessingException { - //given - final String institutionId = UUID.randomUUID().toString(); - final String tokenId = UUID.randomUUID().toString(); - Institution institutionMock = createInstitution(institutionId, createOnboarding(tokenId, "product")); - institutionMock.setAttributes(null); - institutionMock.setOrigin("SELC"); - institutionMock.setRootParentId(null); - InstitutionProxyInfo institutionProxyInfoMock = createInstitutionProxyMock(); - institutionProxyInfoMock.setTaxCode(institutionMock.getTaxCode()); - Token tokenMock = createToken(institutionId, tokenId, null, - RelationshipState.ACTIVE, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - tokenMock.setProductId("product"); - //when - NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); - //then - checkNotNullFields(notificationToSend, "closedAt"); - } - - @Test - void toNotificationToSend_emptyAttributes() { - //given - final String institutionId = UUID.randomUUID().toString(); - final String tokenId = UUID.randomUUID().toString(); - Institution institutionMock = createInstitutionWithoutLocation(institutionId, createOnboarding(tokenId, "product")); - institutionMock.setAttributes(new ArrayList<>()); - institutionMock.setOrigin("IPA"); - institutionMock.setRootParentId(null); - Token tokenMock = createToken(institutionId, tokenId, null, - RelationshipState.ACTIVE, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - tokenMock.setProductId("product"); - mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); - //when - NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); - //then - checkNotNullFields(notificationToSend, "closedAt"); - } - - @Test - void toNotificationToSend_nullLocation() { - //given - final String institutionId = UUID.randomUUID().toString(); - final String tokenId = UUID.randomUUID().toString(); - Onboarding onboarding = createOnboarding(tokenId, "prod"); - Institution institutionMock = createInstitutionWithoutLocation(institutionId, onboarding); - institutionMock.setRootParentId(null); - Token tokenMock = createToken(institutionId, tokenId, null, - RelationshipState.DELETED, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - tokenMock.setProductId("prod"); - mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); - //when - NotificationToSend notification = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.UPDATE); - //then - assertNotNull(notification.getInstitution().getCategory()); - assertNotNull(notification.getInstitution().getCity()); - verify(partyRegistryProxyConnectorMock, times(1)).getInstitutionById(institutionMock.getExternalId()); - verify(partyRegistryProxyConnectorMock, times(1)).getExtByCode(any()); - } - - @Test - void toNotificationAttributesNotNull() { - //given - final String institutionId = UUID.randomUUID().toString(); - final String tokenId = UUID.randomUUID().toString(); - Institution institutionMock = createInstitution(institutionId, createOnboarding(tokenId, "product")); - Attributes attribute = new Attributes(); - attribute.setCode("code"); - institutionMock.setAttributes(List.of(attribute)); - institutionMock.setOrigin("IPA"); - institutionMock.setCity(null); - institutionMock.setRootParentId(null); - Token tokenMock = createToken(institutionId, tokenId, null, - RelationshipState.ACTIVE, - OffsetDateTime.parse("2020-11-01T10:00:00Z"), // createdAt - null, // activatedAt - OffsetDateTime.parse("2020-11-02T10:00:00Z"), // updatedAt - null); // deletedAt - tokenMock.setProductId("product"); - mockPartyRegistryProxy(partyRegistryProxyConnectorMock, institutionMock); - //when - NotificationToSend notificationToSend = contractService.toNotificationToSend(institutionMock, tokenMock, QueueEvent.ADD); - //then - checkNotNullFields(notificationToSend, "closedAt"); - - } - - private static Institution createInstitution(String institutionId, Onboarding onboarding) { - Institution institution = mockInstance(new Institution()); - institution.setId(institutionId); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - return institution; - } - - private static Onboarding createOnboarding() { - return mockInstance(new Onboarding()); - } - - private static Institution createInstitutionWithoutLocation(String institutionId, Onboarding onboarding) { - Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); - institution.setId(institutionId); - institution.setOrigin("IPA"); - institution.setOnboarding(List.of(onboarding)); - return institution; - } - - - private static Onboarding createOnboarding(String tokenId, String productId) { - Onboarding onboarding = mockInstance(new Onboarding()); - onboarding.setProductId(productId); - onboarding.setTokenId(tokenId); - return onboarding; - } - - private static Token createToken(String institutionId, String tokenId, InstitutionUpdate institutionUpdate, - RelationshipState status, - OffsetDateTime createdAt, OffsetDateTime activatedAt, - OffsetDateTime updatedAt, OffsetDateTime deletedAt) { - TokenUser tokenUser1 = new TokenUser("tokenUserId1", PartyRole.MANAGER); - TokenUser tokenUser2 = new TokenUser("tokenUserId2", PartyRole.DELEGATE); - - Token token = mockInstance(new Token()); - token.setId(tokenId); - token.setInstitutionId(institutionId); - token.setProductId("prod"); - token.setStatus(status); - token.setInstitutionUpdate(institutionUpdate); - token.setCreatedAt(createdAt); - token.setActivatedAt(activatedAt); - token.setUpdatedAt(updatedAt); - token.setDeletedAt(deletedAt); - token.setUsers(List.of(tokenUser1, tokenUser2)); - token.setContractSigned("ContractPath".concat("/").concat(token.getId()).concat("/").concat("fileName.pdf")); - token.setContentType(MediaType.APPLICATION_JSON_VALUE); - return token; - } - - private static void mockPartyRegistryProxy(PartyRegistryProxyConnector partyRegistryProxyConnector, Institution institution) { - InstitutionProxyInfo institutionProxyInfoMock = mockInstance(new InstitutionProxyInfo(), "setCity", "setCounty", "setCountry"); - institutionProxyInfoMock.setTaxCode(institution.getExternalId()); - - GeographicTaxonomies geographicTaxonomiesMock = mockInstance(new GeographicTaxonomies()); - geographicTaxonomiesMock.setIstatCode(institutionProxyInfoMock.getIstatCode()); - - when(partyRegistryProxyConnector.getInstitutionById(any())) - .thenReturn(institutionProxyInfoMock); - when(partyRegistryProxyConnector.getExtByCode(any())).thenReturn(geographicTaxonomiesMock); - } - @Test void extractTemplate() { when(fileStorageConnector.getTemplateFile(any())).thenReturn("value"); @@ -806,20 +229,15 @@ void testExtractTemplate2() { FileStorageConnector fileStorageConnector = mock(FileStorageConnector.class); when(fileStorageConnector.getTemplateFile((String) any())).thenReturn("Template File"); - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); CoreConfig coreConfig = new CoreConfig(); Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + assertEquals("Template File", (new ContractService(pagoPaSignatureConfig, fileStorageConnector, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector)).extractTemplate("Path")); + pkcs7HashSignService, signatureService)).extractTemplate("Path")); verify(fileStorageConnector).getTemplateFile((String) any()); - verify(producerFactory).transactionCapable(); } @Test @@ -832,7 +250,7 @@ void getFile() { * Method under test: {@link ContractService#getFile(String)} */ @Test - void testGetFile2() throws UnsupportedEncodingException { + void testGetFile2() { ResourceResponse resourceResponse = new ResourceResponse(); resourceResponse.setData("AXAXAXAX".getBytes(StandardCharsets.UTF_8)); @@ -840,19 +258,15 @@ void testGetFile2() throws UnsupportedEncodingException { resourceResponse.setMimetype("Mimetype"); FileStorageConnector fileStorageConnector = mock(FileStorageConnector.class); when(fileStorageConnector.getFile((String) any())).thenReturn(resourceResponse); - ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); - when(producerFactory.transactionCapable()).thenReturn(true); - KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); + PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); CoreConfig coreConfig = new CoreConfig(); Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); - InstitutionConnector institutionConnector = mock(InstitutionConnector.class); + assertSame(resourceResponse, (new ContractService(pagoPaSignatureConfig, fileStorageConnector, coreConfig, - pkcs7HashSignService, signatureService, kafkaTemplate, new KafkaPropertiesConfig(), partyRegistryProxyConnector, institutionConnector)).getFile("Path")); + pkcs7HashSignService, signatureService)).getFile("Path")); verify(fileStorageConnector).getFile((String) any()); - verify(producerFactory).transactionCapable(); } @Test @@ -881,35 +295,11 @@ void deleteContract() { assertDoesNotThrow(() -> contractService.deleteContract("fileName", "tokenId")); } - private static InstitutionProxyInfo createInstitutionProxyMock() { - return mockInstance(new InstitutionProxyInfo()); - } - @Test void uploadContract() { when(fileStorageConnector.uploadContract(any(), any())).thenReturn("fileName"); MultipartFile file = mock(MultipartFile.class); assertDoesNotThrow(() -> contractService.uploadContract("fileName", file)); } - - private WorkContact createWorkContact(String workContactEmail) { - WorkContact workContact = new WorkContact(); - workContact.setEmail(createCertifiedField_certified(workContactEmail)); - return workContact; - } - - private CertifiedField createCertifiedField_certified(String fieldValue) { - CertifiedField certifiedField = new CertifiedField<>(); - certifiedField.setCertification(Certification.SPID); - certifiedField.setValue(fieldValue); - return certifiedField; - } - - private CertifiedField createCertifiedField_uncertified(String fieldValue) { - CertifiedField certifiedField = new CertifiedField<>(); - certifiedField.setCertification(Certification.NONE); - certifiedField.setValue(fieldValue); - return certifiedField; - } } diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java index 1f4ad1908..bf9fe7c39 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/InstitutionServiceImplTest.java @@ -62,7 +62,7 @@ class InstitutionServiceImplTest { private CoreConfig coreConfig; @Mock - private ContractService contractService; + private ContractEventNotificationService contractService; @Mock private TokenConnector tokenConnector; diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java index 22334b979..473800619 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java @@ -66,6 +66,9 @@ class OnboardingServiceImplTest { @Mock private ContractService contractService; + @Mock + private ContractEventNotificationService contractEventNotificationService; + @Mock private UserService userService; @Mock 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 e38ba06ed..8ecb84ea3 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 @@ -33,7 +33,7 @@ class QueueNotificationServiceTest { @InjectMocks private QueueNotificationServiceImpl schedulerService; @Mock - private ContractService contractService; + private ContractEventNotificationService contractService; @Mock private UserConnector userConnector; diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/TokenServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/TokenServiceImplTest.java index 5eaa5b798..9616482d3 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/TokenServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/TokenServiceImplTest.java @@ -42,7 +42,7 @@ @ExtendWith(MockitoExtension.class) class TokenServiceImplTest { @Mock - private ContractService contractService; + private ContractEventNotificationService contractService; @Mock private UserService userService; diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java index 3bb693f5f..61c693b52 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/strategy/OnboardingInstitutionStrategyTest.java @@ -46,6 +46,8 @@ class OnboardingInstitutionStrategyTest { @Mock private ContractService contractService; @Mock + private ContractEventNotificationService contractEventNotificationService; + @Mock private UserEventService userEventService; @Mock private UserService userService; @@ -62,7 +64,7 @@ class OnboardingInstitutionStrategyTest { @BeforeEach void beforeAll() { strategyFactory = new OnboardingInstitutionStrategyFactory(onboardingDao, - contractService,userService, institutionService, coreConfig, mailNotificationService, fileStorageConnector, userEventService); + contractService, contractEventNotificationService, userService, institutionService, coreConfig, mailNotificationService, fileStorageConnector, userEventService); } diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index b8de871cf..1016f1c69 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -37,3 +37,4 @@ configEnvSpecific: APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL: "OFF" EXTERNAL_API_LOG_LEVEL: "DEBUG" CORE_USER_EVENT_SERVICE_TYPE: "send" + CORE_CONTRACT_EVENT_SERVICE_TYPE: "send" diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 145068a6d..5989aac6b 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -42,3 +42,4 @@ configEnvSpecific: APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL: "OFF" EXTERNAL_API_LOG_LEVEL: "INFO" CORE_USER_EVENT_SERVICE_TYPE: "send" + CORE_CONTRACT_EVENT_SERVICE_TYPE: "send" diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 4a2b63a41..ee54a022b 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -35,3 +35,4 @@ configEnvSpecific: APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL: "OFF" EXTERNAL_API_LOG_LEVEL: "DEBUG" CORE_USER_EVENT_SERVICE_TYPE: "send" + CORE_CONTRACT_EVENT_SERVICE_TYPE: "send" From f8c33b6a5dfae7b91db1c8b83410cd06d569a392 Mon Sep 17 00:00:00 2001 From: manuraf Date: Mon, 5 Feb 2024 17:38:32 +0100 Subject: [PATCH 2/4] object mapper --- .../ContractEventNotificationServiceImpl.java | 21 +++++++++++++++++-- ...tractEventNotificationServiceImplTest.java | 15 ++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java index ae6b20545..eb24c1b37 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java @@ -1,7 +1,11 @@ package it.pagopa.selfcare.mscore.core; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; import it.pagopa.selfcare.commons.base.logging.LogUtils; import it.pagopa.selfcare.mscore.api.InstitutionConnector; import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; @@ -29,7 +33,10 @@ import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; +import java.io.IOException; import java.nio.file.Paths; +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -48,13 +55,23 @@ public class ContractEventNotificationServiceImpl implements ContractEventNotifi private final InstitutionConnector institutionConnector; private final CoreConfig coreConfig; - public ContractEventNotificationServiceImpl(KafkaTemplate kafkaTemplate, KafkaPropertiesConfig kafkaPropertiesConfig, ObjectMapper mapper, PartyRegistryProxyConnector partyRegistryProxyConnector, InstitutionConnector institutionConnector, CoreConfig coreConfig) { + public ContractEventNotificationServiceImpl(KafkaTemplate kafkaTemplate, KafkaPropertiesConfig kafkaPropertiesConfig, PartyRegistryProxyConnector partyRegistryProxyConnector, InstitutionConnector institutionConnector, CoreConfig coreConfig) { this.kafkaTemplate = kafkaTemplate; this.kafkaPropertiesConfig = kafkaPropertiesConfig; - this.mapper = mapper; this.partyRegistryProxyConnector = partyRegistryProxyConnector; this.institutionConnector = institutionConnector; this.coreConfig = coreConfig; + + + this.mapper = new ObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<>() { + @Override + public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetDateTime)); + } + }); + mapper.registerModule(simpleModule); } @Override diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java index cc80eb648..d2f46c07b 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java @@ -68,7 +68,7 @@ public class ContractEventNotificationServiceImplTest { * Method under test: {@link ContractEventNotificationServiceImpl#sendDataLakeNotification(Institution, Token, QueueEvent)} */ @Test - void testSendDataLakeNotification2() throws ExecutionException, InterruptedException { + void testSendDataLakeNotification2() { ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); when(producerFactory.transactionCapable()).thenReturn(true); KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); @@ -79,7 +79,7 @@ void testSendDataLakeNotification2() throws ExecutionException, InterruptedExcep PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); InstitutionConnector institutionConnector = mock(InstitutionConnector.class); ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), - new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + partyRegistryProxyConnector, institutionConnector, coreConfig); Onboarding onboarding = mockInstance(new Onboarding()); onboarding.setProductId("prod"); @@ -151,7 +151,7 @@ void testSendDataLakeNotification3() { PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); InstitutionConnector institutionConnector = mock(InstitutionConnector.class); ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), - new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + partyRegistryProxyConnector, institutionConnector, coreConfig); Onboarding onboarding = mockInstance(new Onboarding()); onboarding.setProductId("prod"); @@ -201,7 +201,7 @@ void testSendDataLakeNotification_notOnIpa(Class clazz) throws ExecutionExcep InstitutionConnector institutionConnector = mock(InstitutionConnector.class); ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), - new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + partyRegistryProxyConnector, institutionConnector, coreConfig); Onboarding onboarding = mockInstance(new Onboarding()); onboarding.setProductId("prod"); @@ -260,16 +260,13 @@ void testSendDataLakeNotification_updateQueueEvent() { ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); when(producerFactory.transactionCapable()).thenReturn(true); KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); + CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); - UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); InstitutionConnector institutionConnector = mock(InstitutionConnector.class); ContractEventNotificationService contractService = new ContractEventNotificationServiceImpl(kafkaTemplate, new KafkaPropertiesConfig(), - new ObjectMapper(), partyRegistryProxyConnector, institutionConnector, coreConfig); + partyRegistryProxyConnector, institutionConnector, coreConfig); Onboarding onboarding = mockInstance(new Onboarding()); onboarding.setProductId("prod"); From c09bd172e26972a5024ff12f6b326bd65f211175 Mon Sep 17 00:00:00 2001 From: manuraf Date: Tue, 6 Feb 2024 09:25:03 +0100 Subject: [PATCH 3/4] fix conditional property --- .../mscore/core/ContractEventNotificationServiceIgnore.java | 2 +- .../mscore/core/ContractEventNotificationServiceImpl.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java index efc0e12e3..024fec740 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceIgnore.java @@ -11,7 +11,7 @@ @Slf4j @Service @ConditionalOnProperty( - value="core.user-event-service.type", + value="core.contract-event-service.type", havingValue = "ignore", matchIfMissing = true) public class ContractEventNotificationServiceIgnore implements ContractEventNotificationService { diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java index eb24c1b37..856a4dcd2 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImpl.java @@ -26,6 +26,7 @@ import it.pagopa.selfcare.mscore.model.institution.Onboarding; import it.pagopa.selfcare.mscore.model.onboarding.Token; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.stereotype.Service; @@ -43,6 +44,9 @@ @Slf4j @Service +@ConditionalOnProperty( + value="core.contract-event-service.type", + havingValue = "send") public class ContractEventNotificationServiceImpl implements ContractEventNotificationService { From e2fad3124a686639d8abaa79faf433cf11c45118 Mon Sep 17 00:00:00 2001 From: manuraf Date: Tue, 6 Feb 2024 09:59:34 +0100 Subject: [PATCH 4/4] remove unused code --- ...tractEventNotificationServiceImplTest.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java index d2f46c07b..f909f5de1 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/ContractEventNotificationServiceImplTest.java @@ -1,14 +1,10 @@ package it.pagopa.selfcare.mscore.core; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.europa.esig.dss.spi.tsl.TrustedListsCertificateSource; import it.pagopa.selfcare.commons.base.security.PartyRole; -import it.pagopa.selfcare.commons.utils.crypto.service.Pkcs7HashSignService; import it.pagopa.selfcare.mscore.api.InstitutionConnector; import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector; import it.pagopa.selfcare.mscore.api.UserRegistryConnector; import it.pagopa.selfcare.mscore.config.CoreConfig; -import it.pagopa.selfcare.mscore.config.PagoPaSignatureConfig; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.core.config.KafkaPropertiesConfig; import it.pagopa.selfcare.mscore.exception.MsCoreException; @@ -35,15 +31,12 @@ import java.time.OffsetDateTime; import java.util.*; -import java.util.concurrent.ExecutionException; import static it.pagopa.selfcare.commons.utils.TestUtils.checkNotNullFields; import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import static org.mockito.Mockito.times; @ExtendWith(MockitoExtension.class) public class ContractEventNotificationServiceImplTest { @@ -188,14 +181,12 @@ void testSendDataLakeNotification3() { MsCoreException.class, ResourceNotFoundException.class }) - void testSendDataLakeNotification_notOnIpa(Class clazz) throws ExecutionException, InterruptedException { + void testSendDataLakeNotification_notOnIpa(Class clazz) { ProducerFactory producerFactory = (ProducerFactory) mock(ProducerFactory.class); when(producerFactory.transactionCapable()).thenReturn(true); KafkaTemplate kafkaTemplate = new KafkaTemplate<>(producerFactory); - PagoPaSignatureConfig pagoPaSignatureConfig = new PagoPaSignatureConfig(); CoreConfig coreConfig = new CoreConfig(); - Pkcs7HashSignService pkcs7HashSignService = mock(Pkcs7HashSignService.class); - SignatureService signatureService = new SignatureService(new TrustedListsCertificateSource()); + UserRegistryConnector userRegistryConnector = mock(UserRegistryConnector.class); PartyRegistryProxyConnector partyRegistryProxyConnector = mock(PartyRegistryProxyConnector.class); InstitutionConnector institutionConnector = mock(InstitutionConnector.class); @@ -332,7 +323,7 @@ void testSendDataLakeNotification_updateQueueEvent() { * Method under test: {@link ContractEventNotificationServiceImpl#toNotificationToSend(Institution, Token, QueueEvent)} */ @Test - void testGenerateMessageActiveWithActivatedAt() throws ExecutionException, InterruptedException { + void testGenerateMessageActiveWithActivatedAt() { String institutionId = "i1"; String tokenId = "t1"; @@ -521,8 +512,6 @@ void toNotificationAttributesNotNull() { } - - private static Institution createInstitution(String institutionId, Onboarding onboarding) { Institution institution = mockInstance(new Institution()); institution.setId(institutionId); @@ -531,10 +520,6 @@ private static Institution createInstitution(String institutionId, Onboarding on return institution; } - private static Onboarding createOnboarding() { - return mockInstance(new Onboarding()); - } - private static Institution createInstitutionWithoutLocation(String institutionId, Onboarding onboarding) { Institution institution = mockInstance(new Institution(), "setCity", "setCounty", "setCountry"); institution.setId(institutionId);