Search in sources :

Example 11 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class KnotxSplitterHandler method handle.

@Override
public void handle(RoutingContext context) {
    KnotContext knotContext = context.get(KnotContext.KEY);
    splitter.rxProcess(knotContext).doOnSuccess(this::traceMessage).subscribe(ctx -> {
        if (ctx.getClientResponse().getStatusCode() == HttpResponseStatus.OK.code()) {
            context.put(KnotContext.KEY, ctx);
            context.next();
        } else {
            context.fail(ctx.getClientResponse().getStatusCode());
        }
    }, error -> {
        LOGGER.error("Error happened while communicating with {} engine", error, configuration.getDefaultFlow().splitterAddress());
        context.fail(error);
    });
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext)

Example 12 with KnotContext

use of io.knotx.dataobjects.KnotContext in project knotx by Cognifide.

the class ActionKnotProxyImpl method processError.

@Override
protected KnotContext processError(KnotContext context, Throwable error) {
    LOGGER.error("Could not process template [{}]", error, context.getClientRequest().getPath());
    KnotContext errorResponse = new KnotContext().setClientResponse(context.getClientResponse());
    errorResponse.getClientResponse().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
    return errorResponse;
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext)

Example 13 with KnotContext

use of io.knotx.dataobjects.KnotContext 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 14 with KnotContext

use of io.knotx.dataobjects.KnotContext 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 15 with KnotContext

use of io.knotx.dataobjects.KnotContext 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)

Aggregations

KnotContext (io.knotx.dataobjects.KnotContext)21 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)10 Test (org.junit.Test)10 ClientResponse (io.knotx.dataobjects.ClientResponse)6 Vertx (io.vertx.reactivex.core.Vertx)6 Fragment (io.knotx.dataobjects.Fragment)4 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 Logback (io.knotx.junit.rule.Logback)3 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)3 KnotxServerConfiguration (io.knotx.server.configuration.KnotxServerConfiguration)3 Handler (io.vertx.core.Handler)3 Logger (io.vertx.core.logging.Logger)3 LoggerFactory (io.vertx.core.logging.LoggerFactory)3 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 MultiMap (io.vertx.reactivex.core.MultiMap)3 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)3