Search in sources :

Example 11 with KnotxConfiguration

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()));
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 12 with KnotxConfiguration

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()));
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) Fragment(io.knotx.dataobjects.Fragment) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 13 with KnotxConfiguration

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()));
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 14 with KnotxConfiguration

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()));
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 15 with KnotxConfiguration

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();
        }
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) KnotContext(io.knotx.dataobjects.KnotContext) RunWith(org.junit.runner.RunWith) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Logback(io.knotx.junit.rule.Logback) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Action1(rx.functions.Action1) WebClient(io.vertx.reactivex.ext.web.client.WebClient) RuleChain(org.junit.rules.RuleChain) MultiMap(io.vertx.reactivex.core.MultiMap) Vertx(io.vertx.reactivex.core.Vertx) List(java.util.List) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) CSRFHandler(io.vertx.ext.web.handler.CSRFHandler) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) Async(io.vertx.ext.unit.Async) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Aggregations

KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)22 Test (org.junit.Test)22 Async (io.vertx.ext.unit.Async)14 MultiMap (io.vertx.reactivex.core.MultiMap)9 WebClient (io.vertx.reactivex.ext.web.client.WebClient)9 KnotContext (io.knotx.dataobjects.KnotContext)8 Logback (io.knotx.junit.rule.Logback)6 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)6 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)6 JsonObject (io.vertx.core.json.JsonObject)6 TestContext (io.vertx.ext.unit.TestContext)6 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)6 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)6 Vertx (io.vertx.reactivex.core.Vertx)6 List (java.util.List)6 Rule (org.junit.Rule)6 RuleChain (org.junit.rules.RuleChain)6 RunWith (org.junit.runner.RunWith)6 Lists (com.google.common.collect.Lists)5 UnsupportedServiceException (io.knotx.adapter.common.exception.UnsupportedServiceException)5