use of io.knotx.adapter.common.http.HttpClientFacade in project knotx by Cognifide.
the class HttpClientFacadeTest method whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
// when
Single<ClientResponse> result = clientFacade.process(new AdapterRequest().setParams(new JsonObject()).setRequest(clientRequest), HttpMethod.POST);
// then
result.doOnError(error -> {
context.assertEquals("Parameter `path` was not defined in `params`!", error.getMessage());
Mockito.verify(mockedWebClient, Mockito.times(0)).request(Matchers.any(), Matchers.anyInt(), Matchers.anyString(), Matchers.anyString());
}).subscribe(response -> context.fail("Error should occur!"), error -> async.complete());
}
use of io.knotx.adapter.common.http.HttpClientFacade in project knotx by Cognifide.
the class HttpClientFacadeTest method whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenSupportedStaticPathServiceRequested_expectRequestExecutedAndResponseOKWithBody(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
final JsonObject expectedResponse = new JsonObject(FileReader.readText("first-response.json"));
// when
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", REQUEST_PATH), clientRequest), HttpMethod.POST);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(expectedResponse, response.getBody().toJsonObject());
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.POST, PORT, DOMAIN, REQUEST_PATH);
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
use of io.knotx.adapter.common.http.HttpClientFacade in project knotx by Cognifide.
the class HttpClientFacadeTest method whenSupportedDynamicPathServiceRequested_expectRequestExecutedAndResponseOKWithBody.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenSupportedDynamicPathServiceRequested_expectRequestExecutedAndResponseOKWithBody(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
final JsonObject expectedResponse = new JsonObject(FileReader.readText("first-response.json"));
// FIXME - params to request
MultiMap requestParams = MultiMap.caseInsensitiveMultiMap().add("dynamicValue", "first");
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", "/services/mock/{param.dynamicValue}.json"), clientRequest.setParams(requestParams)), HttpMethod.POST);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(expectedResponse, response.getBody().toJsonObject());
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.POST, PORT, DOMAIN, REQUEST_PATH);
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
use of io.knotx.adapter.common.http.HttpClientFacade in project knotx by Cognifide.
the class HttpClientFacadeTest method whenUnsupportedPathServiceRequested_expectNoServiceRequestAndBadRequest.
@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenUnsupportedPathServiceRequested_expectNoServiceRequestAndBadRequest(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
// when
Single<ClientResponse> result = clientFacade.process(payloadMessage(new JsonObject().put("path", "/not/supported/path"), clientRequest), HttpMethod.POST);
// then
result.doOnError(error -> {
context.assertEquals(UnsupportedServiceException.class, error.getClass());
Mockito.verify(mockedWebClient, Mockito.times(0)).request(Matchers.any(), Matchers.anyInt(), Matchers.anyString(), Matchers.anyString());
}).subscribe(response -> context.fail("Error should occur!"), error -> async.complete());
}
use of io.knotx.adapter.common.http.HttpClientFacade in project knotx by Cognifide.
the class HttpClientFacadeTest method whenServiceEmptyResponse_expectNoFailure.
@Test
@KnotxConfiguration("knotx-service-adapter-http-test.json")
public void whenServiceEmptyResponse_expectNoFailure(TestContext context) throws Exception {
Async async = context.async();
// given
final WebClient mockedWebClient = PowerMockito.spy(webClient());
HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
// when
Single<ClientResponse> result = clientFacade.process(payloadMessage("/services/mock/empty.json", new ClientRequest()), HttpMethod.GET);
// then
result.doOnSuccess(response -> {
context.assertEquals(HttpResponseStatus.OK.code(), response.getStatusCode());
context.assertEquals(0, Integer.valueOf(response.getHeaders().get("Content-Length")));
Mockito.verify(mockedWebClient, Mockito.times(1)).request(HttpMethod.GET, PORT, DOMAIN, "/services/mock/empty.json");
}).subscribe(response -> async.complete(), error -> context.fail(error.getMessage()));
}
Aggregations