From 92f568d72929716d6def64ea21ec4748d9bbbad0 Mon Sep 17 00:00:00 2001 From: AngeloCaporaso Date: Fri, 30 Aug 2024 17:50:55 +0200 Subject: [PATCH] [PAGOPA-2066] fix: Add key suffix when GenericPair is 1 --- .../java/it/gov/pagopa/authorizer/util/Utility.java | 1 + .../pagopa/authorizer/service/CacheServiceTest.java | 10 +++++----- .../it/gov/pagopa/authorizer/util/UtilityTest.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/gov/pagopa/authorizer/util/Utility.java b/src/main/java/it/gov/pagopa/authorizer/util/Utility.java index b35aaa3..939c11b 100644 --- a/src/main/java/it/gov/pagopa/authorizer/util/Utility.java +++ b/src/main/java/it/gov/pagopa/authorizer/util/Utility.java @@ -43,6 +43,7 @@ public static String extractMetadataAsString(@NonNull List metadata) { List content = singleMetadata.getContent(); if (content.size() == 1) { GenericPair metadataPair = content.get(0); + builder.append(metadataPair.getKey()).append(":"); builder.append(getMetadataValueAsString(metadataPair)); } else { Iterator it = content.iterator(); diff --git a/src/test/java/it/gov/pagopa/authorizer/service/CacheServiceTest.java b/src/test/java/it/gov/pagopa/authorizer/service/CacheServiceTest.java index 74ef1de..e7172c6 100644 --- a/src/test/java/it/gov/pagopa/authorizer/service/CacheServiceTest.java +++ b/src/test/java/it/gov/pagopa/authorizer/service/CacheServiceTest.java @@ -45,15 +45,15 @@ class CacheServiceTest { @SneakyThrows @ParameterizedTest @CsvSource(delimiterString = "/", value = { - "0/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}", - "1/{\"key\":\"domain_1\",\"value\":\"entity1#entity2|sub-entity\",\"metadata\":\"_o=pagoPA;;\"}", + "0/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}", + "1/{\"key\":\"domain_1\",\"value\":\"entity1#entity2|sub-entity\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}", "3/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"\"}" }) void addAuthConfigurationToAPIMAuthorizer_OK(int id, String subkeyDomainAsString) { // Mocking passed values SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(id); - //String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}"; + //String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}"; MockHttpResponse mockedHttpResponse = MockHttpResponse.builder().statusCode(200).uri(new URI("")).build(); // Mocking execution for service's internal component @@ -76,7 +76,7 @@ void addAuthConfigurationToAPIMAuthorizer_OK_noAuthorizationEntities() { // Mocking passed values SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(0); subkeyDomain.setAuthorizedEntities(List.of()); - String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"\",\"metadata\":\"_o=pagoPA;;\"}"; + String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}"; MockHttpResponse mockedHttpResponse = MockHttpResponse.builder().statusCode(200).uri(new URI("")).build(); // Mocking execution for service's internal component @@ -98,7 +98,7 @@ void addAuthConfigurationToAPIMAuthorizer_KO_communicationError() { // Mocking passed values SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(0); - String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}"; + String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}"; // Mocking execution for service's internal component HttpClient realHttpClient = spy(HttpClient.newHttpClient()); diff --git a/src/test/java/it/gov/pagopa/authorizer/util/UtilityTest.java b/src/test/java/it/gov/pagopa/authorizer/util/UtilityTest.java index ec55de6..8b47971 100644 --- a/src/test/java/it/gov/pagopa/authorizer/util/UtilityTest.java +++ b/src/test/java/it/gov/pagopa/authorizer/util/UtilityTest.java @@ -64,7 +64,7 @@ void convertListToString_KO_nullParameter() { @Test void extractMetadataAsString_OK() { - String expectedResult = "_md1=single-value;;_md2=value1,value2;;_md3=multiple-object-1:single-value;multiple-object-2:value1,value2;;"; + String expectedResult = "_md1=single-object:single-value;;_md2=single-object-with-multiple-values:value1,value2;;_md3=multiple-object-1:single-value;multiple-object-2:value1,value2;;"; String result = Utility.extractMetadataAsString(getMetadataList()); assertEquals(expectedResult, result); }