use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callPostWithActionFragmentWithoutRequestedFragmentIdentifier_expectStatusCode500.
@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithActionFragmentWithoutRequestedFragmentIdentifier_expectStatusCode500(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_incorrect_identifier_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.POST);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), clientResponse.getClientResponse().getStatusCode());
context.assertFalse(clientResponse.getFragments() != null);
context.assertFalse(clientResponse.getTransition() != null);
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callGetWithActionFragmentWithoutIdentifier_expectResponseOkWithOneFragmentChanges.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithActionFragmentWithoutIdentifier_expectResponseOkWithOneFragmentChanges(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_no_identifier_in.txt");
String expectedFragmentHtml = FileReader.readText("fragment_form_no_identifier_out.txt");
knotContext.getClientRequest().setMethod(HttpMethod.GET);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.OK.code(), clientResponse.getClientResponse().getStatusCode());
context.assertTrue(clientResponse.getTransition() != null);
context.assertEquals(KNOT_TRANSITION, clientResponse.getTransition());
context.assertTrue(clientResponse.getFragments() != null);
List<Fragment> fragments = clientResponse.getFragments();
context.assertEquals(fragments.size(), 1);
context.assertEquals(clean(expectedFragmentHtml), clean(fragments.get(0).content()));
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callPostWithTwoActionFragments_expectResponseOkWithTransitionStep2.
@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithTwoActionFragments_expectResponseOkWithTransitionStep2(TestContext context) throws Exception {
createMockAdapter("address-redirect", "", "step2");
KnotContext knotContext = createKnotContext("fragment_form_redirect_in.txt", "fragment_form_self_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.POST).setFormAttributes(MultiMap.caseInsensitiveMultiMap().add(HIDDEN_INPUT_TAG_NAME, FRAGMENT_REDIRECT_IDENTIFIER));
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.MOVED_PERMANENTLY.code(), clientResponse.getClientResponse().getStatusCode());
context.assertEquals("/content/form/step2.html", clientResponse.getClientResponse().getHeaders().get("Location"));
context.assertFalse(clientResponse.getTransition() != null);
context.assertFalse(clientResponse.getFragments() != null);
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method callGetWithActionFragmentActionHandlerNotExists_expectStatusCode500.
@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithActionFragmentActionHandlerNotExists_expectStatusCode500(TestContext context) throws Exception {
KnotContext knotContext = createKnotContext("fragment_form_actionhandler_not_exists_in.txt");
knotContext.getClientRequest().setMethod(HttpMethod.GET);
callActionKnotWithAssertions(context, knotContext, clientResponse -> {
context.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), clientResponse.getClientResponse().getStatusCode());
context.assertFalse(clientResponse.getTransition() != null);
context.assertFalse(clientResponse.getFragments() != null);
}, error -> context.fail(error.getMessage()));
}
use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.
the class KnotxServerCsrfTest method whenRequestingGetLocalPath_expectLocalAC.
@Test
@KnotxConfiguration("test-server-csrf.json")
public void whenRequestingGetLocalPath_expectLocalAC(TestContext context) {
Async async = context.async();
createPassThroughKnot("test-splitter");
createPassThroughKnot("test-assembler");
createSimpleKnot("some-knot", "test", null);
WebClient client = WebClient.create(Vertx.newInstance(vertx.vertx()));
client.get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html").send(ar -> {
if (ar.succeeded()) {
context.assertEquals(HttpResponseStatus.OK.code(), ar.result().statusCode());
context.assertTrue(ar.result().getHeader(EXPECTED_RESPONSE_HEADER) != null);
context.assertEquals(EXPECTED_XSERVER_HEADER_VALUE, ar.result().getHeader(EXPECTED_RESPONSE_HEADER));
context.assertTrue(ar.result().cookies().stream().anyMatch(cookie -> cookie.contains(CSRFHandler.DEFAULT_COOKIE_NAME)));
client.close();
async.complete();
} else {
context.fail(ar.cause());
async.complete();
}
});
}
Aggregations