From b1c731084cd1144af15896caf6bceab47a1f1e25 Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo Date: Thu, 25 Jan 2024 16:47:23 +0100 Subject: [PATCH] add other unit tests for ProductServiceCacheable --- .../service/ProductServiceCacheableTest.java | 37 +++++++++++++++++++ .../service}/ProductServiceDefaultTest.java | 2 + 2 files changed, 39 insertions(+) rename libs/onboarding-sdk-product/src/test/java/{ => it/pagopa/selfcare/product/service}/ProductServiceDefaultTest.java (99%) diff --git a/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceCacheableTest.java b/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceCacheableTest.java index 68509b120..3199c31a8 100644 --- a/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceCacheableTest.java +++ b/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceCacheableTest.java @@ -1,6 +1,7 @@ package it.pagopa.selfcare.product.service; import com.azure.storage.blob.models.BlobProperties; +import com.fasterxml.jackson.core.JsonProcessingException; import it.pagopa.selfcare.azurestorage.AzureBlobClient; import it.pagopa.selfcare.onboarding.common.PartyRole; import it.pagopa.selfcare.product.entity.Product; @@ -26,6 +27,11 @@ class ProductServiceCacheableTest { "{\"id\":\"prod-test\", \"parentId\":\"prod-test-parent\",\"status\":\"ACTIVE\"}," + "{\"id\":\"prod-inactive\",\"status\":\"INACTIVE\"}]"; + final private String PRODUCT_JSON_STRING_WITH_ROLEMAPPING = "[{\"id\":\"prod-test-parent\",\"status\":\"ACTIVE\"}," + + "{\"id\":\"prod-test\", \"parentId\":\"prod-test-parent\",\"status\":\"ACTIVE\", \"roleMappings\" : {\"MANAGER\":{\"roles\":[{\"code\":\"operatore\"}]}}}," + + "{\"id\":\"prod-inactive\",\"status\":\"INACTIVE\"}]"; + + final private String PRODUCT_JSON_STRING_EMPTY = "[]"; @Test @@ -176,6 +182,37 @@ void getProduct_notFoundInactive() { assertThrows(ProductNotFoundException.class, executable); } + @Test + void validateProductRoleWithoutRole() { + final String filePath = "filePath"; + ProductServiceCacheable productServiceCacheable = mockProductService(PRODUCT_JSON_STRING, filePath); + assertThrows(IllegalArgumentException.class, () -> productServiceCacheable.validateProductRole("prod-test", "productRole", null)); + } + + + @Test + void validateProductRoleOk() { + final String filePath = "filePath"; + ProductServiceCacheable productServiceCacheable = mockProductService(PRODUCT_JSON_STRING_WITH_ROLEMAPPING, filePath); + assertDoesNotThrow(() -> productServiceCacheable.validateProductRole("prod-test", "operatore", PartyRole.MANAGER)); + } + + + @Test + void validateProductRoleWithProductRoleMappingNotFound() { + final String filePath = "filePath"; + ProductServiceCacheable productServiceCacheable = mockProductService(PRODUCT_JSON_STRING_WITH_ROLEMAPPING, filePath); + assertThrows(IllegalArgumentException.class, () -> productServiceCacheable.validateProductRole("prod-test", "productRole", PartyRole.DELEGATE)); + } + + + @Test + void validateProductRoleOkWithProductRoleNotFound() { + final String filePath = "filePath"; + ProductServiceCacheable productServiceCacheable = mockProductService(PRODUCT_JSON_STRING_WITH_ROLEMAPPING, filePath); + assertThrows(IllegalArgumentException.class, () -> productServiceCacheable.validateProductRole("prod-test", "amministratore", PartyRole.MANAGER)); + } + private ProductServiceCacheable mockProductService(String productJson, String filePath) { AzureBlobClient azureBlobClient = mock(AzureBlobClient.class); BlobProperties blobPropertiesMock = mock(BlobProperties.class); diff --git a/libs/onboarding-sdk-product/src/test/java/ProductServiceDefaultTest.java b/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceDefaultTest.java similarity index 99% rename from libs/onboarding-sdk-product/src/test/java/ProductServiceDefaultTest.java rename to libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceDefaultTest.java index 3da4f7af9..ce1b11631 100644 --- a/libs/onboarding-sdk-product/src/test/java/ProductServiceDefaultTest.java +++ b/libs/onboarding-sdk-product/src/test/java/it/pagopa/selfcare/product/service/ProductServiceDefaultTest.java @@ -1,3 +1,5 @@ +package it.pagopa.selfcare.product.service; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import it.pagopa.selfcare.onboarding.common.PartyRole;