Skip to content

Commit

Permalink
fix: nav2iuv with multiple '_' PAGOPA-2316 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoRuzzier authored Oct 25, 2024
2 parents c1da73f + 1e0bb30 commit bba84bc
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 10 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-wisp-converter
description: A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, interfacing them with GPD system
type: application
version: 0.244.0
appVersion: 0.4.15
version: 0.246.0
appVersion: 0.4.15-2-PAGOPA-2316
dependencies:
- name: microservice-chart
version: 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "0.4.15"
tag: "0.4.15-2-PAGOPA-2316"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "0.4.15"
tag: "0.4.15-2-PAGOPA-2316"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart: &microservice-chart
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-wisp-converter
tag: "0.4.15"
tag: "0.4.15-2-PAGOPA-2316"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion openapi/openapi_redirect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.1",
"info": {
"title": "WISP-Converter-redirect",
"version": "0.4.15"
"version": "0.4.15-2-PAGOPA-2316"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>wisp-converter</artifactId>
<version>0.4.15</version>
<version>0.4.15-2-PAGOPA-2316</version>
<name>pagoPA WISP Converter</name>
<description>A service that permits to handle nodoInviaRPT and nodoInviaCarrelloRPT request from WISP, converting them in NMU payments.</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public CachedKeysMapping getCachedMappingFromNavToIuv(String creditorInstitution
}

// trying to split key on underscore character
String[] splitKey = keyWithIUV.split("_");
if (splitKey.length != 3) {
String[] splitKey = keyWithIUV.split("_", 3);
if (splitKey.length < 3) {
throw new AppException(AppErrorCodeMessageEnum.PERSISTENCE_MAPPING_NAV_TO_IUV_ERROR, mappingKey);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package it.gov.pagopa.wispconverter.service;

import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum;
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.repository.CacheRepository;
import it.gov.pagopa.wispconverter.repository.ReceiptDeadLetterRepository;
import it.gov.pagopa.wispconverter.secondary.IdempotencyKeyRepositorySecondary;
import it.gov.pagopa.wispconverter.secondary.RTRepositorySecondary;
import it.gov.pagopa.wispconverter.secondary.ReEventRepositorySecondary;
import it.gov.pagopa.wispconverter.service.model.CachedKeysMapping;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@ActiveProfiles(profiles = "test")
@SpringBootTest
class DecouplerServiceTest {

@Autowired
private DecouplerService decouplerService;

@MockBean
private CacheRepository cacheRepository;

@MockBean
private ReceiptDeadLetterRepository receiptDeadLetterRepository;

@MockBean
private RTRepositorySecondary rtRepositorySecondary;

@MockBean
private ReEventRepositorySecondary reEventRepositorySecondary;

@MockBean
private IdempotencyKeyRepositorySecondary idempotencyKeyRepositorySecondary;

private static final String DOMAIN_ID = "12345678910";

private static final String NAV = "350000000000000000";

@ParameterizedTest
@CsvSource({"wisp_nav2iuv_123456IUVMOCK1,123456IUVMOCK1", "wisp_nav2iuv_123456IUVMOCK1_123456IUVMOCK2,123456IUVMOCK1_123456IUVMOCK2"})
@SneakyThrows
void getCachedMappingFromNavToIuvTestOK(String nav2iuv, String iuv) {

// mocking decoupler cached keys
when(cacheRepository.read(anyString(), any())).thenReturn(nav2iuv);

CachedKeysMapping result = decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV);
Assertions.assertEquals(iuv, result.getIuv());

}

@Test
@SneakyThrows
void getCachedMappingFromNavToIuvTestKONullKey() {

// mocking decoupler cached keys
when(cacheRepository.read(anyString(), any())).thenReturn(null);

try {
decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV);
fail();
} catch (AppException e) {
assertEquals(AppErrorCodeMessageEnum.PERSISTENCE_REQUESTID_CACHING_ERROR, e.getError());
}
}

@Test
@SneakyThrows
void getCachedMappingFromNavToIuvTestKOWrongKey() {

// mocking decoupler cached keys
when(cacheRepository.read(anyString(), any())).thenReturn("wrong_string");

try {
decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV);
fail();
} catch (AppException e) {
assertEquals(AppErrorCodeMessageEnum.PERSISTENCE_MAPPING_NAV_TO_IUV_ERROR, e.getError());
}
}
}

0 comments on commit bba84bc

Please sign in to comment.