mirror of https://github.com/dapr/java-sdk.git
Fixing DaprHttp and its tests. (#93)
This commit is contained in:
parent
880cd92515
commit
80ed8bf0c1
|
@ -84,7 +84,7 @@ public class DaprClientBuilder {
|
|||
synchronized (DaprClientBuilder.class) {
|
||||
if (this.daprHttClient == null) {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
||||
DaprHttp daprHtt = new DaprHttp(Constants.DEFAULT_BASE_HTTP_URL, port, okHttpClient);
|
||||
DaprHttp daprHtt = new DaprHttp(port, okHttpClient);
|
||||
this.daprHttClient = new DaprClientHttpAdapter(daprHtt);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,9 +74,9 @@ class DaprHttp {
|
|||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* The base url used for form urls. This is typically "http://localhost:3500".
|
||||
* Port used to communicate to Dapr's HTTP endpoint.
|
||||
*/
|
||||
private final String baseUrl;
|
||||
private final int port;
|
||||
|
||||
/**
|
||||
* Http client used for all API calls.
|
||||
|
@ -91,12 +91,11 @@ class DaprHttp {
|
|||
/**
|
||||
* Creates a new instance of {@link DaprHttp}.
|
||||
*
|
||||
* @param baseUrl Base url calling Dapr (e.g. http://localhost)
|
||||
* @param port Port for calling Dapr. (e.g. 3500)
|
||||
* @param httpClient RestClient used for all API calls in this new instance.
|
||||
*/
|
||||
DaprHttp(String baseUrl, int port, OkHttpClient httpClient) {
|
||||
this.baseUrl = String.format("%s:%d/", baseUrl, port);
|
||||
DaprHttp(int port, OkHttpClient httpClient) {
|
||||
this.port = port;
|
||||
this.httpClient = httpClient;
|
||||
this.pool = Executors.newWorkStealingPool();
|
||||
}
|
||||
|
@ -148,7 +147,7 @@ class DaprHttp {
|
|||
body = RequestBody.Companion.create(content, mediaType);
|
||||
}
|
||||
HttpUrl.Builder urlBuilder = new HttpUrl.Builder();
|
||||
urlBuilder.host(this.baseUrl).addPathSegment(urlString);
|
||||
urlBuilder.scheme("http").host(Constants.DEFAULT_HOSTNAME).port(this.port).addPathSegments(urlString);
|
||||
Optional.ofNullable(urlParameters).orElse(Collections.emptyMap()).entrySet().stream()
|
||||
.forEach(urlParameter -> urlBuilder.addQueryParameter(urlParameter.getKey(), urlParameter.getValue()));
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class DaprHttpStub extends DaprHttp {
|
|||
* Instantiates a stub for DaprHttp
|
||||
*/
|
||||
public DaprHttpStub() {
|
||||
super("http://localhost", 3000, null);
|
||||
super(3000, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ public class DaprHttpTest {
|
|||
.post("http://localhost:3500/v1.0/state")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST","v1.0/state",null, null);
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -58,7 +58,7 @@ public class DaprHttpTest {
|
|||
.delete("http://localhost:3500/v1.0/state")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("DELETE","v1.0/state", null, null);
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -74,7 +74,7 @@ public class DaprHttpTest {
|
|||
.get("http://localhost:3500/v1.0/get")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get",null, null);
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -91,11 +91,11 @@ public class DaprHttpTest {
|
|||
headers.put("header1","value1");
|
||||
|
||||
mockInterceptor.addRule()
|
||||
.get("http://localhost:3500/v1.0/get")
|
||||
.get("http://localhost:3500/v1.0/get?header1=value1&header=value")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get",headers, null);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get", headers, null);
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
assertEquals(EXPECTED_RESULT,body);
|
||||
|
@ -114,7 +114,7 @@ public class DaprHttpTest {
|
|||
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
||||
"{\"errorCode\":\"500\",\"message\":\"Error\"}"));
|
||||
|
||||
DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get", headers, null);
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
|
Loading…
Reference in New Issue