Skip to content

Commit

Permalink
add other unit tests for ProductServiceCacheable
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Jan 25, 2024
1 parent dd3b05c commit b1c7310
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit b1c7310

Please sign in to comment.