diff --git a/.env.sample b/.env.sample
index 60c3889..2f543ce 100644
--- a/.env.sample
+++ b/.env.sample
@@ -11,4 +11,6 @@ PAA_PASSWORD=PAA_PASSWORD
NCRON_SCHEDULE_BATCH=*/45 * * * * *
MAX_RETRY_QUEUING= 5
QUEUE_RETENTION_SEC= 86400
-QUEUE_DELAY_SEC= 3600
\ No newline at end of file
+QUEUE_DELAY_SEC= 3600
+CACHE_CLIENT_HOST=https://localhost:8080
+CACHE_API_KEY=yyy
\ No newline at end of file
diff --git a/local.settings.json.example b/local.settings.json.example
index 685d2b2..d9c1410 100644
--- a/local.settings.json.example
+++ b/local.settings.json.example
@@ -15,6 +15,8 @@
"PAA_PASSWORD":"PAA_PASSWORD",
"MAX_RETRY_QUEUING": 5,
"QUEUE_RETENTION_SEC": 86400,
- "QUEUE_DELAY_SEC": 3600
+ "QUEUE_DELAY_SEC": 3600,
+ "CACHE_CLIENT_HOST": "https://localhost:8080",
+ "CACHE_API_KEY": "yyy"
}
}
diff --git a/pom.xml b/pom.xml
index d1c8e99..46ddf2f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,7 @@
12.11.3
com.microsoft.azure-20220215182005862
3.15.3.Final
+ 2.0.1
@@ -150,6 +151,18 @@
2.13.1
+
+ com.google.api-client
+ google-api-client-gson
+ ${google-api-client.version}
+
+
+
+ com.google.http-client
+ google-http-client-jackson2
+ 1.42.3
+
+
diff --git a/src/main/java/it/gov/pagopa/reporting/RetrieveFlows.java b/src/main/java/it/gov/pagopa/reporting/RetrieveFlows.java
index 8ad3ae2..481f028 100644
--- a/src/main/java/it/gov/pagopa/reporting/RetrieveFlows.java
+++ b/src/main/java/it/gov/pagopa/reporting/RetrieveFlows.java
@@ -6,17 +6,27 @@
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.QueueTrigger;
import com.sun.xml.ws.client.ClientTransportException;
+import it.gov.pagopa.reporting.client.ApiConfigClient;
+import it.gov.pagopa.reporting.exception.Cache4XXException;
+import it.gov.pagopa.reporting.exception.Cache5XXException;
import it.gov.pagopa.reporting.models.OrganizationsMessage;
+import it.gov.pagopa.reporting.models.cache.CacheResponse;
+import it.gov.pagopa.reporting.models.cache.CreditorInstitutionStation;
+import it.gov.pagopa.reporting.models.cache.Station;
import it.gov.pagopa.reporting.service.FlowsService;
import it.gov.pagopa.reporting.service.NodoChiediElencoFlussi;
import it.gov.pagopa.reporting.service.OrganizationsService;
import it.gov.pagopa.reporting.servicewsdl.FaultBean;
import it.gov.pagopa.reporting.servicewsdl.TipoElencoFlussiRendicontazione;
-import java.time.LocalDateTime;
+import java.io.IOException;
+import java.time.LocalDate;
import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
/**
* Azure Functions with Azure Queue trigger.
@@ -32,6 +42,8 @@ public class RetrieveFlows {
private final String initialVisibilityDelayInSeconds = System.getenv("QUEUE_DELAY_SEC");
private final String maxRetryQueuing = System.getenv("MAX_RETRY_QUEUING");
+ private static CacheResponse cacheContent;
+
/**
* This function will be invoked when a new message is detected in the queue
*/
@@ -41,10 +53,16 @@ public void run(
final ExecutionContext context) {
Logger logger = context.getLogger();
- logger.log(Level.INFO, () -> String.format("[RetrieveOrganizationsTrigger START] processed the message: %s at %s", message, LocalDateTime.now()));
+ logger.log(Level.INFO, () -> String.format("[RetrieveOrganizationsTrigger START] processed the message: %s at %s", message, LocalDate.now()));
NodoChiediElencoFlussi nodeClient = this.getNodeClientInstance(logger);
FlowsService flowsService = this.getFlowsServiceInstance(logger);
+ ApiConfigClient cacheClient = this.getCacheClientInstance();
+ if(cacheContent == null || (cacheContent.getRetrieveDate() != null && cacheContent.getRetrieveDate().isBefore(LocalDate.now()))) {
+ synchronized (RetrieveFlows.class) {
+ setCache(cacheClient, logger);
+ }
+ }
try {
OrganizationsMessage organizationsMessage = new ObjectMapper().readValue(message, OrganizationsMessage.class);
@@ -52,8 +70,12 @@ public void run(
Arrays.stream(organizationsMessage.getIdPA())
.forEach((organization -> {
try {
+ Station stationBroker = getPAStationIntermediario(organization)
+ .orElseThrow(() -> new RuntimeException(String.format("No data present in api config database for PA %s", organization)));
+ String idStation = stationBroker.getStationCode();
+ String idBroker = stationBroker.getBrokerCode();
// call NODO dei pagamenti
- nodeClient.nodoChiediElencoFlussiRendicontazione(organization);
+ nodeClient.nodoChiediElencoFlussiRendicontazione(organization, idBroker, idStation);
// retrieve result
FaultBean faultBean = nodeClient.getNodoChiediElencoFlussiRendicontazioneFault();
@@ -83,6 +105,10 @@ public void run(
}
}
+ public ApiConfigClient getCacheClientInstance() {
+ return ApiConfigClient.getInstance();
+ }
+
public NodoChiediElencoFlussi getNodeClientInstance(Logger logger) {
return new NodoChiediElencoFlussi(logger);
}
@@ -94,4 +120,37 @@ public FlowsService getFlowsServiceInstance(Logger logger) {
public OrganizationsService getOrganizationsServiceInstance(Logger logger) {
return new OrganizationsService(this.storageConnectionString, this.organizationsTable, this.organizationsQueue, Integer.parseInt(timeToLiveInSeconds), Integer.parseInt(initialVisibilityDelayInSeconds), logger);
}
+
+ public Optional getPAStationIntermediario(String idPa) {
+ List stationPa = getStations(idPa);
+ return cacheContent.getStations().stream()
+ .filter(station -> stationPa.contains(station.getStationCode()))
+ .filter(Station::getEnabled)
+ .findFirst();
+ }
+
+ public List getStations(String idPa) {
+ return cacheContent.getCreditorInstitutionStations().stream()
+ .filter(creditorInstitutionStation -> creditorInstitutionStation.getCreditorInstitutionCode().equals(idPa))
+ .map(CreditorInstitutionStation::getStationCode).collect(Collectors.toList());
+ }
+
+ public synchronized void setCache(ApiConfigClient cacheClient, Logger logger) {
+ try {
+ if(cacheContent == null) {
+ cacheContent = cacheClient.getCache();
+ cacheContent.setRetrieveDate(LocalDate.now());
+ }
+ } catch (Cache4XXException | Cache5XXException e) {
+ cacheContent = null;
+ logger.log(Level.SEVERE, e.getMessage());
+ } catch (IOException e) {
+ cacheContent = null;
+ logger.log(Level.SEVERE, e.getMessage());
+ throw new RuntimeException(e.getMessage());
+ } catch (Exception e) {
+ cacheContent = null;
+ logger.log(Level.SEVERE, e.getMessage());
+ }
+ }
}
diff --git a/src/main/java/it/gov/pagopa/reporting/client/ApiConfigClient.java b/src/main/java/it/gov/pagopa/reporting/client/ApiConfigClient.java
new file mode 100644
index 0000000..3218b98
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/client/ApiConfigClient.java
@@ -0,0 +1,134 @@
+package it.gov.pagopa.reporting.client;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.api.client.http.*;
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.JsonObjectParser;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.client.util.ExponentialBackOff;
+import com.google.gson.reflect.TypeToken;
+import it.gov.pagopa.reporting.exception.Cache4XXException;
+import it.gov.pagopa.reporting.exception.Cache5XXException;
+import it.gov.pagopa.reporting.models.cache.CacheResponse;
+import it.gov.pagopa.reporting.models.cache.CreditorInstitutionStation;
+import it.gov.pagopa.reporting.models.cache.Station;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ApiConfigClient {
+
+ private static ApiConfigClient instance = null;
+
+ private final HttpTransport httpTransport = new NetHttpTransport();
+ private final JsonFactory jsonFactory = new GsonFactory();
+ private final String apiConfigCacheHost = System.getenv("CACHE_CLIENT_HOST"); // es: https://api.xxx.platform.pagopa.it
+ private final String getCacheDetails =
+ System.getenv("CACHE_PATH") != null ? System.getenv("CACHE_PATH") : "/cache?keys=creditorInstitutionStations,stations";
+ private final String apiKey = System.getenv("CACHE_API_KEY");
+
+
+ // Retry ExponentialBackOff config
+ private final boolean enableRetry =
+ System.getenv("ENABLE_CLIENT_RETRY") != null ? Boolean.parseBoolean(System.getenv("ENABLE_CLIENT_RETRY")) : Boolean.FALSE;
+ private final int initialIntervalMillis =
+ System.getenv("INITIAL_INTERVAL_MILLIS") != null ? Integer.parseInt(System.getenv("INITIAL_INTERVAL_MILLIS")) : 500;
+ private final int maxElapsedTimeMillis =
+ System.getenv("MAX_ELAPSED_TIME_MILLIS") != null ? Integer.parseInt(System.getenv("MAX_ELAPSED_TIME_MILLIS")) : 1000;
+ private final int maxIntervalMillis =
+ System.getenv("MAX_INTERVAL_MILLIS") != null ? Integer.parseInt(System.getenv("MAX_INTERVAL_MILLIS")) : 1000;
+ private final double multiplier =
+ System.getenv("MULTIPLIER") != null ? Double.parseDouble(System.getenv("MULTIPLIER")) : 1.5;
+ private final double randomizationFactor =
+ System.getenv("RANDOMIZATION_FACTOR") != null ? Double.parseDouble(System.getenv("RANDOMIZATION_FACTOR")) : 0.5;
+
+ public static ApiConfigClient getInstance() {
+ if (instance == null) {
+ instance = new ApiConfigClient();
+ }
+ return instance;
+ }
+
+ public CacheResponse getCache() throws IOException, IllegalArgumentException, Cache5XXException, Cache4XXException {
+ GenericUrl url = new GenericUrl(apiConfigCacheHost + getCacheDetails);
+ HttpRequest request = this.buildGetRequestToApiConfigCache(url);
+
+ if (enableRetry) {
+ this.setRequestRetry(request);
+ }
+
+ return this.executeCallToApiConfigCache(request);
+ }
+
+ public HttpRequest buildGetRequestToApiConfigCache(GenericUrl url) throws IOException {
+
+ HttpRequestFactory requestFactory = httpTransport.createRequestFactory(
+ (HttpRequest request) ->
+ request.setParser(new JsonObjectParser(jsonFactory))
+ );
+
+ HttpRequest request = requestFactory.buildGetRequest(url);
+ HttpHeaders headers = request.getHeaders();
+ headers.set("Ocp-Apim-Subscription-Key", apiKey);
+ return request;
+ }
+
+ public void setRequestRetry(HttpRequest request) {
+ /**
+ * Retry section config
+ */
+ ExponentialBackOff backoff = new ExponentialBackOff.Builder()
+ .setInitialIntervalMillis(initialIntervalMillis)
+ .setMaxElapsedTimeMillis(maxElapsedTimeMillis)
+ .setMaxIntervalMillis(maxIntervalMillis)
+ .setMultiplier(multiplier)
+ .setRandomizationFactor(randomizationFactor)
+ .build();
+
+ // Exponential Backoff is turned off by default in HttpRequest -> it's necessary include an instance of HttpUnsuccessfulResponseHandler to the HttpRequest to activate it
+ // The default back-off on anabnormal HTTP response is BackOffRequired.ON_SERVER_ERROR (5xx)
+ request.setUnsuccessfulResponseHandler(
+ new HttpBackOffUnsuccessfulResponseHandler(backoff));
+ }
+
+ public CacheResponse executeCallToApiConfigCache(HttpRequest request) throws IOException, IllegalArgumentException, Cache5XXException, Cache4XXException {
+
+ Type type = new TypeToken>() {}.getType();
+
+ ObjectMapper mapper = new ObjectMapper();
+ CacheResponse cacheResponse = CacheResponse.builder().build();
+ List creditorInstitutionStationList = new ArrayList<>();
+ List stationList = new ArrayList<>();
+ try {
+ InputStream resIs = request.execute().getContent();
+ Map responseMap = mapper.readValue(resIs, HashMap.class);
+ Map creditorInstitutionStations = (HashMap) responseMap.get("creditorInstitutionStations");
+ for (Map.Entry creditorInstitutionStation : creditorInstitutionStations.entrySet()) {
+ creditorInstitutionStationList.add(mapper.readValue(mapper.writeValueAsString(creditorInstitutionStation.getValue()), CreditorInstitutionStation.class));
+ }
+ Map stations = (HashMap) responseMap.get("stations");
+ for (Map.Entry station : stations.entrySet()) {
+ stationList.add(mapper.readValue(mapper.writeValueAsString(station.getValue()), Station.class));
+ }
+ cacheResponse.setStations(stationList);
+ cacheResponse.setCreditorInstitutionStations(creditorInstitutionStationList);
+ } catch (HttpResponseException e) {
+ if (e.getStatusCode() / 100 == 4) {
+ String message = String.format("Error %s calling the service URL %s", e.getStatusCode(), request.getUrl());
+ throw new Cache4XXException(message);
+
+ } else if (e.getStatusCode() / 100 == 5) {
+ String message = String.format("Error %s calling the service URL %s", e.getStatusCode(), request.getUrl());
+ throw new Cache5XXException(message);
+
+ }
+ }
+ return cacheResponse;
+ }
+}
diff --git a/src/main/java/it/gov/pagopa/reporting/exception/AppException.java b/src/main/java/it/gov/pagopa/reporting/exception/AppException.java
new file mode 100644
index 0000000..9d3d4aa
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/exception/AppException.java
@@ -0,0 +1,18 @@
+package it.gov.pagopa.reporting.exception;
+
+public class AppException extends Exception {
+
+ /**
+ * generated serialVersionUID
+ */
+ private static final long serialVersionUID = -7564079264281462536L;
+
+ public AppException() {
+ super();
+ }
+
+ public AppException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/it/gov/pagopa/reporting/exception/Cache4XXException.java b/src/main/java/it/gov/pagopa/reporting/exception/Cache4XXException.java
new file mode 100644
index 0000000..8f5bb1a
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/exception/Cache4XXException.java
@@ -0,0 +1,18 @@
+package it.gov.pagopa.reporting.exception;
+
+public class Cache4XXException extends Exception {
+
+ /**
+ * generated serialVersionUID
+ */
+ private static final long serialVersionUID = -7564079264281462536L;
+
+ public Cache4XXException() {
+ super();
+ }
+
+ public Cache4XXException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/it/gov/pagopa/reporting/exception/Cache5XXException.java b/src/main/java/it/gov/pagopa/reporting/exception/Cache5XXException.java
new file mode 100644
index 0000000..be50275
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/exception/Cache5XXException.java
@@ -0,0 +1,18 @@
+package it.gov.pagopa.reporting.exception;
+
+public class Cache5XXException extends Exception {
+
+ /**
+ * generated serialVersionUID
+ */
+ private static final long serialVersionUID = -7564079264281462536L;
+
+ public Cache5XXException() {
+ super();
+ }
+
+ public Cache5XXException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/it/gov/pagopa/reporting/models/cache/CacheResponse.java b/src/main/java/it/gov/pagopa/reporting/models/cache/CacheResponse.java
new file mode 100644
index 0000000..07e0312
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/models/cache/CacheResponse.java
@@ -0,0 +1,27 @@
+package it.gov.pagopa.reporting.models.cache;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.*;
+
+import java.time.LocalDate;
+import java.util.List;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Getter
+@Setter
+@ToString
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Builder
+public class CacheResponse {
+
+ @JsonProperty(value = "stations")
+ private List stations;
+
+ @JsonProperty(value = "creditorInstitutionStations")
+ private List creditorInstitutionStations;
+
+ private LocalDate retrieveDate;
+
+}
\ No newline at end of file
diff --git a/src/main/java/it/gov/pagopa/reporting/models/cache/CreditorInstitutionStation.java b/src/main/java/it/gov/pagopa/reporting/models/cache/CreditorInstitutionStation.java
new file mode 100644
index 0000000..2eea2d6
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/models/cache/CreditorInstitutionStation.java
@@ -0,0 +1,22 @@
+package it.gov.pagopa.reporting.models.cache;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.*;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Getter
+@Setter
+@ToString
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Builder
+public class CreditorInstitutionStation {
+
+ @JsonProperty(value = "creditor_institution_code")
+ private String creditorInstitutionCode;
+
+ @JsonProperty(value = "station_code")
+ private String stationCode;
+}
diff --git a/src/main/java/it/gov/pagopa/reporting/models/cache/Station.java b/src/main/java/it/gov/pagopa/reporting/models/cache/Station.java
new file mode 100644
index 0000000..cf262cc
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/reporting/models/cache/Station.java
@@ -0,0 +1,24 @@
+package it.gov.pagopa.reporting.models.cache;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.*;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Getter
+@Setter
+@ToString
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Builder
+public class Station {
+
+ @JsonProperty(value = "station_code")
+ private String stationCode;
+
+ @JsonProperty(value = "enabled")
+ private Boolean enabled;
+
+ @JsonProperty(value = "broker_code")
+ private String brokerCode;
+}
\ No newline at end of file
diff --git a/src/main/java/it/gov/pagopa/reporting/service/NodoChiediElencoFlussi.java b/src/main/java/it/gov/pagopa/reporting/service/NodoChiediElencoFlussi.java
index 4423de7..e4ed8d2 100644
--- a/src/main/java/it/gov/pagopa/reporting/service/NodoChiediElencoFlussi.java
+++ b/src/main/java/it/gov/pagopa/reporting/service/NodoChiediElencoFlussi.java
@@ -17,11 +17,6 @@ public class NodoChiediElencoFlussi {
private PagamentiTelematiciRPT port;
private Holder nodoChiediElencoFlussiRendicontazioneFault;
private Holder nodoChiediElencoFlussiRendicontazione;
-
- private final String nodoChiediElencoFlussiRendicontazioneIdentificativoIntermediarioPA = System
- .getenv("PAA_ID_INTERMEDIARIO");
- private final String nodoChiediElencoFlussiRendicontazioneIdentificativoStazioneIntermediarioPA = System
- .getenv("PAA_STAZIONE_INT");
private final String nodoChiediElencoFlussiRendicontazionePassword = System.getenv("PAA_PASSWORD");
public NodoChiediElencoFlussi(Logger logger) {
@@ -51,13 +46,16 @@ public TipoElencoFlussiRendicontazione getNodoChiediElencoFlussiRendicontazione(
: null;
}
- public void nodoChiediElencoFlussiRendicontazione(String idPa) throws ClientTransportException {
+ public void nodoChiediElencoFlussiRendicontazione(String idPa,
+ String idIntermediarioPA,
+ String idStazioneIntermediarioPA) throws ClientTransportException {
var nodoChiediElencoFlussiRendicontazioneFaultLocal = new Holder();
var nodoChiediElencoFlussiRendicontazioneElencoFlussiRendicontazioneLocal = new Holder();
- port.nodoChiediElencoFlussiRendicontazione(nodoChiediElencoFlussiRendicontazioneIdentificativoIntermediarioPA,
- nodoChiediElencoFlussiRendicontazioneIdentificativoStazioneIntermediarioPA,
+ port.nodoChiediElencoFlussiRendicontazione(
+ idIntermediarioPA,
+ idStazioneIntermediarioPA,
nodoChiediElencoFlussiRendicontazionePassword, idPa, null,
nodoChiediElencoFlussiRendicontazioneFaultLocal,
nodoChiediElencoFlussiRendicontazioneElencoFlussiRendicontazioneLocal);
diff --git a/src/main/resources/wsdl/NodoPerPa.wsdl b/src/main/resources/wsdl/NodoPerPa.wsdl
index 2bc8e3e..f405af0 100644
--- a/src/main/resources/wsdl/NodoPerPa.wsdl
+++ b/src/main/resources/wsdl/NodoPerPa.wsdl
@@ -19,14 +19,14 @@
- Identificativo univoco della chiamata.
- Nel caso di pagamento multi beneficiario (parametro multiBeneficario=true) deve essere necessariamente essere composto
- 'idDominio(11)numeroAvviso(18)-(1)-Progressivo(5)'
+ Identificativo univoco della chiamata.
+ Nel caso di pagamento multi beneficiario (parametro multiBeneficario=true) deve essere necessariamente essere composto
+ 'idDominio(11)numeroAvviso(18)-(1)-Progressivo(5)'
-
- Nei casi dove il carrello contiene il pagamento di più posizioni debitorie ( non multi beneficiarie ) è possibile utilizzare la seguente sintassi
+
+ Nei casi dove il carrello contiene il pagamento di più posizioni debitorie ( non multi beneficiarie ) è possibile utilizzare la seguente sintassi
'Anno(4)idDominio(11)codiceSorgente(2)Progressivo(18)'
-
+
@@ -869,4 +869,4 @@
-
+
\ No newline at end of file
diff --git a/src/test/java/it/gov/pagopa/reporting/NodoChiediElencoFlussiTest.java b/src/test/java/it/gov/pagopa/reporting/NodoChiediElencoFlussiTest.java
index ffc1596..191cccc 100644
--- a/src/test/java/it/gov/pagopa/reporting/NodoChiediElencoFlussiTest.java
+++ b/src/test/java/it/gov/pagopa/reporting/NodoChiediElencoFlussiTest.java
@@ -52,7 +52,9 @@ void nodoChiediElencoFlussiTestSettersTest() throws Exception {
keyField.set(nodoChiediElencoFlussi, myPort);
String idPa = "12345";
- nodoChiediElencoFlussi.nodoChiediElencoFlussiRendicontazione(idPa);
+ String idBroker = "123456";
+ String idStazione = "123456_00";
+ nodoChiediElencoFlussi.nodoChiediElencoFlussiRendicontazione(idPa, idBroker, idStazione);
assertTrue(Boolean.TRUE);
}
diff --git a/src/test/java/it/gov/pagopa/reporting/RetrieveFlowsTest.java b/src/test/java/it/gov/pagopa/reporting/RetrieveFlowsTest.java
index 5518684..a0736b2 100644
--- a/src/test/java/it/gov/pagopa/reporting/RetrieveFlowsTest.java
+++ b/src/test/java/it/gov/pagopa/reporting/RetrieveFlowsTest.java
@@ -1,6 +1,10 @@
package it.gov.pagopa.reporting;
import com.microsoft.azure.functions.ExecutionContext;
+import it.gov.pagopa.reporting.client.ApiConfigClient;
+import it.gov.pagopa.reporting.models.cache.CacheResponse;
+import it.gov.pagopa.reporting.models.cache.CreditorInstitutionStation;
+import it.gov.pagopa.reporting.models.cache.Station;
import it.gov.pagopa.reporting.service.FlowsService;
import it.gov.pagopa.reporting.service.NodoChiediElencoFlussi;
import it.gov.pagopa.reporting.servicewsdl.ObjectFactory;
@@ -15,8 +19,10 @@
import javax.xml.datatype.DatatypeFactory;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.time.LocalDate;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
@@ -36,6 +42,9 @@ class RetrieveFlowsTest {
@Mock
NodoChiediElencoFlussi nodeClient;
+ @Mock
+ ApiConfigClient cacheClient;
+
@Mock
FlowsService flowsService;
@@ -59,7 +68,6 @@ void runOkTest() throws Exception {
DatatypeFactory.newInstance().newXMLGregorianCalendar(cal1).toGregorianCalendar()));
elencoFlussi.getIdRendicontazione().add(e1);
-
// general var
Logger logger = Logger.getLogger("testlogging");
@@ -68,22 +76,47 @@ void runOkTest() throws Exception {
doReturn(nodeClient).when(function).getNodeClientInstance(logger);
doReturn(flowsService).when(function).getFlowsServiceInstance(logger);
+ doReturn(cacheClient).when(function).getCacheClientInstance();
- doNothing().when(nodeClient).nodoChiediElencoFlussiRendicontazione(anyString());
+ doNothing().when(nodeClient).nodoChiediElencoFlussiRendicontazione(anyString(), anyString(), anyString());
when(nodeClient.getNodoChiediElencoFlussiRendicontazioneFault()).thenReturn(null);
- when(nodeClient.getNodoChiediElencoFlussiRendicontazione()).thenReturn(elencoFlussi);
- // test
+ when(nodeClient.getNodoChiediElencoFlussiRendicontazione()).thenReturn(elencoFlussi);// test
String message = "{\"idPA\":[\"9000000001\",\"9000000002\",\"9000000003\"]}";
function.run(message, context);
// Asserts
verify(context, times(1)).getLogger();
- verify(nodeClient, times(3)).nodoChiediElencoFlussiRendicontazione(anyString());
+ verify(nodeClient, times(3)).nodoChiediElencoFlussiRendicontazione(anyString(), anyString(), anyString());
}
@Test
void runKoTest() throws Exception {
+ List stations = List.of(Station.builder()
+ .stationCode("12345_00")
+ .brokerCode("12345")
+ .enabled(true)
+ .build());
+ List creditorInstitutionStations = List.of(
+ CreditorInstitutionStation.builder()
+ .creditorInstitutionCode("9000000001")
+ .stationCode("12345_00")
+ .build(),
+ CreditorInstitutionStation.builder()
+ .creditorInstitutionCode("9000000002")
+ .stationCode("12345_00")
+ .build(),
+ CreditorInstitutionStation.builder()
+ .creditorInstitutionCode("9000000003")
+ .stationCode("12345_00")
+ .build()
+ );
+ CacheResponse cacheResponse = CacheResponse.builder()
+ .retrieveDate(LocalDate.now())
+ .creditorInstitutionStations(creditorInstitutionStations)
+ .stations(stations)
+ .build();
+
// general var
Logger logger = Logger.getLogger("testlogging");
@@ -92,19 +125,21 @@ void runKoTest() throws Exception {
doReturn(nodeClient).when(function).getNodeClientInstance(logger);
doReturn(flowsService).when(function).getFlowsServiceInstance(logger);
+ doReturn(cacheClient).when(function).getCacheClientInstance();
// doNothing().when(nodeClient).setSslContext();
- doNothing().when(nodeClient).nodoChiediElencoFlussiRendicontazione(anyString());
+ doNothing().when(nodeClient).nodoChiediElencoFlussiRendicontazione(anyString(), anyString(), anyString());
when(nodeClient.getNodoChiediElencoFlussiRendicontazioneFault()).thenReturn(objectFactory.createFaultBean());
when(nodeClient.getNodoChiediElencoFlussiRendicontazione()).thenReturn(null);
+ when(cacheClient.getCache()).thenReturn(cacheResponse);
// test
String message = "{\"idPA\":[\"9000000001\",\"9000000002\",\"9000000003\"]}";
function.run(message, context);
// Asserts
verify(context, times(1)).getLogger();
- verify(nodeClient, times(3)).nodoChiediElencoFlussiRendicontazione(anyString());
+ verify(nodeClient, times(3)).nodoChiediElencoFlussiRendicontazione(anyString(), anyString(), anyString());
}
@Test