From 6e20d35252aa6aa81e48315585f8ef8df1d42fb4 Mon Sep 17 00:00:00 2001 From: empassaro Date: Wed, 11 Dec 2024 08:53:12 +0100 Subject: [PATCH] [SELC-6062] test: added junit tests for RegistryManagerSELC --- .../registry/RegistryManagerSELCTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/entity/registry/RegistryManagerSELCTest.java diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/entity/registry/RegistryManagerSELCTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/entity/registry/RegistryManagerSELCTest.java new file mode 100644 index 000000000..6295545f6 --- /dev/null +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/entity/registry/RegistryManagerSELCTest.java @@ -0,0 +1,66 @@ +package it.pagopa.selfcare.onboarding.entity.registry; + +import io.smallrye.mutiny.Uni; +import it.pagopa.selfcare.onboarding.common.Origin; +import it.pagopa.selfcare.onboarding.common.WorkflowType; +import it.pagopa.selfcare.onboarding.entity.Institution; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.exception.InvalidRequestException; +import it.pagopa.selfcare.product.entity.Product; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class RegistryManagerSELCTest { + + private Onboarding onboarding; + private RegistryManagerSELC registryManagerSELC; + + @BeforeEach + void setUp() { + onboarding = mock(Onboarding.class); + registryManagerSELC = new RegistryManagerSELC(onboarding); + } + + @Test + void retrieveInstitution_shouldSetDefaultOriginAndOriginId() { + var institution = mock(Institution.class); + when(onboarding.getInstitution()).thenReturn(institution); + when(institution.getTaxCode()).thenReturn("123456"); + + registryManagerSELC.retrieveInstitution(); + + verify(institution).setOriginId("123456"); + verify(institution).setOrigin(Origin.SELC); + } + + @ParameterizedTest + @EnumSource(value = WorkflowType.class, names = {"FOR_APPROVE", "IMPORT", "FOR_APPROVE_PT"}) + void customValidation_shouldReturnOnboarding_whenWorkflowTypeAllowed(WorkflowType workflowType) { + when(onboarding.getWorkflowType()).thenReturn(workflowType); + + Uni result = registryManagerSELC.customValidation(mock(Product.class)); + + assertEquals(onboarding, result.await().indefinitely()); + } + + @Test + void customValidation_shouldThrowInvalidRequestException_whenWorkflowTypeNotAllowed() { + when(onboarding.getWorkflowType()).thenReturn(WorkflowType.CONFIRMATION); + + Uni result = registryManagerSELC.customValidation(mock(Product.class)); + + assertThrows(InvalidRequestException.class, () -> result.await().indefinitely()); + } + + @Test + void isValid_shouldReturnTrue() { + Uni result = registryManagerSELC.isValid(); + + assertTrue(result.await().indefinitely()); + } +} \ No newline at end of file