mirror of https://github.com/dapr/java-sdk.git
Fixing and finishing unit tests (#97)
* Fixing and finishing unit tests * Fixing styling Issues and adding new test
This commit is contained in:
parent
a0250fd002
commit
192b37e4c0
|
@ -36,18 +36,38 @@ public class DaprHttpTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invokePostMethod() throws IOException {
|
public void invokeMethod() throws IOException {
|
||||||
|
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put("content-type", "text/html");
|
||||||
|
headers.put("header1", "value1");
|
||||||
|
|
||||||
mockInterceptor.addRule()
|
mockInterceptor.addRule()
|
||||||
.post("http://localhost:3500/v1.0/state")
|
.post("http://localhost:3500/v1.0/state")
|
||||||
.respond(EXPECTED_RESULT);
|
.respond(EXPECTED_RESULT);
|
||||||
|
|
||||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||||
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST", "v1.0/state", null, (byte[])null, headers);
|
||||||
|
|
||||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST","v1.0/state",null, null);
|
|
||||||
DaprHttp.Response response = mono.block();
|
DaprHttp.Response response = mono.block();
|
||||||
String body = serializer.deserialize(response.getBody(), String.class);
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
assertEquals(EXPECTED_RESULT,body);
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invokePostMethod() throws IOException {
|
||||||
|
|
||||||
|
mockInterceptor.addRule()
|
||||||
|
.post("http://localhost:3500/v1.0/state")
|
||||||
|
.respond(EXPECTED_RESULT)
|
||||||
|
.addHeader("Header","Value");
|
||||||
|
|
||||||
|
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||||
|
|
||||||
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST","v1.0/state",null,"", null);
|
||||||
|
DaprHttp.Response response = mono.block();
|
||||||
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +80,10 @@ public class DaprHttpTest {
|
||||||
|
|
||||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||||
|
|
||||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("DELETE","v1.0/state", null, null);
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("DELETE","v1.0/state", null, (String) null,null);
|
||||||
DaprHttp.Response response = mono.block();
|
DaprHttp.Response response = mono.block();
|
||||||
String body = serializer.deserialize(response.getBody(), String.class);
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
assertEquals(EXPECTED_RESULT,body);
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +99,7 @@ public class DaprHttpTest {
|
||||||
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get",null, null);
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("GET","v1.0/get",null, null);
|
||||||
DaprHttp.Response response = mono.block();
|
DaprHttp.Response response = mono.block();
|
||||||
String body = serializer.deserialize(response.getBody(), String.class);
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
assertEquals(EXPECTED_RESULT,body);
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,39 +107,86 @@ public class DaprHttpTest {
|
||||||
public void invokeMethodWithHeaders() throws IOException {
|
public void invokeMethodWithHeaders() throws IOException {
|
||||||
|
|
||||||
Map<String, String> headers = new HashMap<>();
|
Map<String, String> headers = new HashMap<>();
|
||||||
headers.put("header","value");
|
headers.put("header", "value");
|
||||||
headers.put("header1","value1");
|
headers.put("header1", "value1");
|
||||||
|
|
||||||
|
Map<String, String> urlParameters = new HashMap<>();
|
||||||
|
urlParameters.put("orderId", "41");
|
||||||
|
|
||||||
mockInterceptor.addRule()
|
mockInterceptor.addRule()
|
||||||
.get("http://localhost:3500/v1.0/get?header1=value1&header=value")
|
.get("http://localhost:3500/v1.0/state/order?orderId=41")
|
||||||
.respond(EXPECTED_RESULT);
|
.respond(EXPECTED_RESULT);
|
||||||
DaprHttp daprHttp = new DaprHttp(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/state/order", urlParameters, headers);
|
||||||
DaprHttp.Response response = mono.block();
|
DaprHttp.Response response = mono.block();
|
||||||
String body = serializer.deserialize(response.getBody(), String.class);
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
assertEquals(EXPECTED_RESULT,body);
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
@Test(expected = RuntimeException.class)
|
||||||
public void invokeMethodRuntimeException() throws IOException {
|
public void invokePostMethodRuntime() throws IOException {
|
||||||
|
|
||||||
Map<String, String> headers = new HashMap<>();
|
|
||||||
headers.put("header","value");
|
|
||||||
headers.put("header1","value1");
|
|
||||||
|
|
||||||
mockInterceptor.addRule()
|
mockInterceptor.addRule()
|
||||||
.get("http://localhost:3500/v1.0/get")
|
.post("http://localhost:3500/v1.0/state")
|
||||||
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
.respond(500);
|
||||||
"{\"errorCode\":\"500\",\"message\":\"Error\"}"));
|
|
||||||
|
|
||||||
DaprHttp daprHttp = new DaprHttp(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("POST","v1.0/state",null, null);
|
||||||
DaprHttp.Response response = mono.block();
|
DaprHttp.Response response = mono.block();
|
||||||
String body = serializer.deserialize(response.getBody(), String.class);
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
assertEquals(EXPECTED_RESULT,body);
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void invokePostDaprError() throws IOException {
|
||||||
|
|
||||||
|
mockInterceptor.addRule()
|
||||||
|
.post("http://localhost:3500/v1.0/state")
|
||||||
|
.respond(500, ResponseBody.create(MediaType.parse("text"),
|
||||||
|
"{\"errorCode\":null,\"message\":null}"));
|
||||||
|
|
||||||
|
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||||
|
|
||||||
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST","v1.0/state",null, null);
|
||||||
|
DaprHttp.Response response = mono.block();
|
||||||
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void invokePostMethodUnknownError() throws IOException {
|
||||||
|
|
||||||
|
mockInterceptor.addRule()
|
||||||
|
.post("http://localhost:3500/v1.0/state")
|
||||||
|
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
||||||
|
"{\"errorCode\":\"null\",\"message\":\"null\"}"));
|
||||||
|
|
||||||
|
DaprHttp daprHttp = new DaprHttp(3500,okHttpClient);
|
||||||
|
|
||||||
|
Mono<DaprHttp.Response> mono = daprHttp.invokeAPI("POST","v1.0/state",null, null);
|
||||||
|
DaprHttp.Response response = mono.block();
|
||||||
|
String body = serializer.deserialize(response.getBody(), String.class);
|
||||||
|
assertEquals(EXPECTED_RESULT, body);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getHeadersAndStatus(){
|
||||||
|
|
||||||
|
mockInterceptor.addRule()
|
||||||
|
.post("http://localhost:3500/v1.0/state")
|
||||||
|
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
||||||
|
"{\"errorCode\":\"null\",\"message\":\"null\"}"));
|
||||||
|
|
||||||
|
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||||
|
|
||||||
|
System.out.println(daprHttp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue