From d4ab45bb0a46c1d702c73f0ddb0fdffe2f58ed14 Mon Sep 17 00:00:00 2001 From: "angelo.minisci" Date: Thu, 7 Nov 2024 18:39:13 +0100 Subject: [PATCH] fix test deleghe --- .../it/pn/frontend/e2e/config/CustomHttpClient.java | 6 +++--- src/main/java/it/pn/frontend/e2e/rest/RestContact.java | 3 +-- .../java/it/pn/frontend/e2e/rest/RestDelegation.java | 10 ++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/it/pn/frontend/e2e/config/CustomHttpClient.java b/src/main/java/it/pn/frontend/e2e/config/CustomHttpClient.java index 94ee3fd5a..7e2e41af6 100644 --- a/src/main/java/it/pn/frontend/e2e/config/CustomHttpClient.java +++ b/src/main/java/it/pn/frontend/e2e/config/CustomHttpClient.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; @Slf4j @Component @@ -98,7 +99,7 @@ public static CustomHttpClient getInstance() { return (CustomHttpClient) instance; } **/ - +/** public static CustomHttpClient getInstanceWithApiKey(String apiKey) { if (instance == null) { synchronized (CustomHttpClient.class) { @@ -109,10 +110,9 @@ public static CustomHttpClient getInstanceWithApiKey(String apiKey } return (CustomHttpClient) instance; } - +**/ public ResponseType sendHttpPostRequest(String endpoint, Map headers, RequestType requestObject, Class responseType) throws IOException { String apiUrl = baseUrlApi + endpoint; - try (CloseableHttpClient client = HttpClients.createDefault()) { ObjectMapper objectMapper = new ObjectMapper(); String jsonBody = objectMapper.writeValueAsString(requestObject); diff --git a/src/main/java/it/pn/frontend/e2e/rest/RestContact.java b/src/main/java/it/pn/frontend/e2e/rest/RestContact.java index 80610be48..1405f8f49 100644 --- a/src/main/java/it/pn/frontend/e2e/rest/RestContact.java +++ b/src/main/java/it/pn/frontend/e2e/rest/RestContact.java @@ -33,7 +33,6 @@ public class RestContact { private final Map headers = new HashMap<>(); // Carica il token all'avvio della classe - @Autowired private WebDriverConfig webDriverConfig; @Autowired @@ -45,7 +44,7 @@ public class RestContact { public RestContact(WebDriverConfig webDriverConfig, CustomHttpClient httpClient) { this.httpClient = httpClient; this.webDriverConfig = webDriverConfig; - this.httpClient.setBaseUrlApi("https://webapi." + webDriverConfig.getEnvironment() + ".notifichedigitali.it"); + this.httpClient.setBaseUrlApi("https://webapi." + this.webDriverConfig.getEnvironment() + ".notifichedigitali.it"); String token = System.getProperty("token"); if (token != null) { diff --git a/src/main/java/it/pn/frontend/e2e/rest/RestDelegation.java b/src/main/java/it/pn/frontend/e2e/rest/RestDelegation.java index 396e87a75..cc036f315 100644 --- a/src/main/java/it/pn/frontend/e2e/rest/RestDelegation.java +++ b/src/main/java/it/pn/frontend/e2e/rest/RestDelegation.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import java.io.IOException; @@ -31,8 +32,8 @@ public class RestDelegation { private static final Logger logger = LoggerFactory.getLogger(RestDelegation.class); - @Value("${environment}") - private String environment; + + private WebDriverConfig webDriverConfig; private final Map headers = new HashMap<>(); @@ -42,9 +43,10 @@ public class RestDelegation { @Autowired - public RestDelegation(CustomHttpClient httpClientPF, CustomHttpClient httpClientPG) { + public RestDelegation( WebDriverConfig webDriverConfig, CustomHttpClient httpClientPF, CustomHttpClient httpClientPG) { this.httpClientPF = httpClientPF; this.httpClientPG = httpClientPG; + this.webDriverConfig = webDriverConfig; initializeHeaders(); setupHttpClients(); } @@ -59,7 +61,7 @@ private void initializeHeaders() { } private void setupHttpClients() { - String baseUrl = "https://webapi." + environment + ".notifichedigitali.it"; + String baseUrl = "https://webapi." + webDriverConfig.getEnvironment() + ".notifichedigitali.it"; httpClientPF.setBaseUrlApi(baseUrl); httpClientPG.setBaseUrlApi(baseUrl); }