use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class KnotxServerRoutingTest method whenRequestingPostLocalPathWithFirstTransition_expectLocalApostBC.
@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingPostLocalPathWithFirstTransition_expectLocalApostBC(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("A-post-engine", "+Apost", "go-b");
createSimpleKnot("B-engine", "+B", "go-c");
createSimpleKnot("C-engine", "+C", null);
testPostRequest("/content/local/simple.html", resp -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER));
resp.bodyHandler(body -> {
try {
context.assertEquals(body.toString(), "local+Apost+B+C", "Wrong engines processed request, expected " + "local+Apost+B+C");
} catch (Exception e) {
context.fail(e);
}
async.complete();
});
});
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class KnotxServerRoutingTest method whenRequestingPostGlobalPath_expectGlobalBC.
@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingPostGlobalPath_expectGlobalBC(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("B-engine", "+B", "go-c");
createSimpleKnot("C-engine", "+C", null);
testPostRequest("/content/simple.html", resp -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
context.assertTrue(resp.getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER));
resp.bodyHandler(body -> {
try {
context.assertEquals(body.toString(), "global+B+C", "Wrong engines processed request, expected " + "global+B+C");
} catch (Exception e) {
context.fail(e);
}
async.complete();
});
});
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class KnotxServerRoutingTest method whenRequestingWithInvalidQuery_expectBadRequest.
@Test
@KnotxConfiguration("test-server.json")
public void whenRequestingWithInvalidQuery_expectBadRequest(TestContext context) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
client.getNow(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html?q=~!@\\||$%^&*()_=-%22;;%27%22:%3C%3E/?]}{", resp -> {
context.assertEquals(HttpResponseStatus.BAD_REQUEST.code(), resp.statusCode());
client.close();
async.complete();
});
}
use of io.knotx.junit.rule.KnotxConfiguration 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.junit.rule.KnotxConfiguration 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()));
}
Aggregations