fix(client/util): replaced hardcoded values with configService-based impl
This commit is contained in:
parent
c214eff502
commit
5d199e9a33
3 changed files with 8 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package client.utils.server;
|
package client.utils.server;
|
||||||
|
|
||||||
|
import client.utils.ConfigService;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
@ -13,6 +14,7 @@ import org.glassfish.jersey.client.ClientConfig;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
|
@ -27,14 +29,16 @@ public class ServerUtils {
|
||||||
private Logger logger = Logger.getLogger(ServerUtils.class.getName());
|
private Logger logger = Logger.getLogger(ServerUtils.class.getName());
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
private final ConfigService configService;
|
||||||
private final int statusOK = 200;
|
private final int statusOK = 200;
|
||||||
|
|
||||||
private final Endpoints endpoints;
|
private final Endpoints endpoints;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServerUtils(HttpClient client, Endpoints endpoints) {
|
public ServerUtils(HttpClient client, Endpoints endpoints, ConfigService configService) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.endpoints = endpoints;
|
this.endpoints = endpoints;
|
||||||
|
this.configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,7 +68,7 @@ public class ServerUtils {
|
||||||
*/
|
*/
|
||||||
public List<Recipe> getRecipesFiltered(String filter, List<String> locales) throws IOException, InterruptedException {
|
public List<Recipe> getRecipesFiltered(String filter, List<String> locales) throws IOException, InterruptedException {
|
||||||
//TODO add limit integration
|
//TODO add limit integration
|
||||||
String uri = SERVER + "/recipes?search=" + filter + "&locales=" + String.join(",", locales);
|
String uri = configService.getConfig().getServerUrl() + "/recipes?search=" + filter + "&locales=" + String.join(",", locales);
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(uri))
|
.uri(URI.create(uri))
|
||||||
.GET()
|
.GET()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class ServerUtilsMockTest {
|
||||||
var endpoints = new Endpoints(configService);
|
var endpoints = new Endpoints(configService);
|
||||||
|
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
serverUtils = new ServerUtils(HttpClient.newHttpClient(), endpoints);
|
serverUtils = new ServerUtils(HttpClient.newHttpClient(), endpoints, configService);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class ServerUtilsTest {
|
||||||
configService.getConfig().setServerUrl("http://localhost:8080");
|
configService.getConfig().setServerUrl("http://localhost:8080");
|
||||||
|
|
||||||
var endpoints = new Endpoints(configService);
|
var endpoints = new Endpoints(configService);
|
||||||
dv = new ServerUtils(HttpClient.newHttpClient(), endpoints);
|
dv = new ServerUtils(HttpClient.newHttpClient(), endpoints, configService);
|
||||||
|
|
||||||
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
|
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue