response.setContent(html.getBytes()); response.setStatusCode(stringHttpResponse.statusCode()); response.setContentType(stringHttpResponse.getHeader("Content-Type"));
@Test @KnotxApplyConfiguration("io/knotx/server/test-server.json") public void whenRequestingPostGlobalPathAndActionDoRedirect_expectRedirectResponse( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleFailingKnot(vertx, "A-post-engine", HttpResponseStatus.MOVED_PERMANENTLY.code(), MultiMap.caseInsensitiveMultiMap().add("location", "/content/failed.html")); testPostRequest(context, vertx, "/content/local/simple.html", resp -> { assertEquals(HttpResponseStatus.MOVED_PERMANENTLY.code(), resp.statusCode()); assertEquals("/content/failed.html", resp.getHeader("location")); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); }); }
private void testGetRequest(VertxTestContext context, Vertx vertx, String url, String expectedResult) { WebClient client = WebClient.create(vertx); Single<HttpResponse<Buffer>> httpResponseSingle = client .get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url).rxSend(); subscribeToResult_shouldSucceed(context, httpResponseSingle, resp -> { assertEquals(expectedResult, resp.body().toString(), "Wrong engines processed request, expected " + expectedResult); assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); }); }
@Test @KnotxApplyConfiguration("io/knotx/server/test-server-csrf.json") public void whenRequestingGetLocalPath_expectLocalAC( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleKnot(vertx, "some-knot", "test", null); WebClient client = WebClient.create(vertx); Single<HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> httpResponseSingle = client .get(KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, "/content/local/simple.html") .rxSend(); subscribeToResult_shouldSucceed(context, httpResponseSingle, response -> { assertEquals(HttpResponseStatus.OK.code(), response.statusCode()); assertTrue(response.getHeader(EXPECTED_RESPONSE_HEADER) != null); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, response.getHeader(EXPECTED_RESPONSE_HEADER)); assertTrue(response.cookies().stream() .anyMatch(cookie -> cookie.contains(CSRFHandler.DEFAULT_COOKIE_NAME))); }); }
@Test @KnotxApplyConfiguration("io/knotx/server/test-server.json") public void whenRequestingPostGlobalPath_expectGlobalBC( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleKnot(vertx, "B-engine", "+B", "go-c"); createSimpleKnot(vertx, "C-engine", "+C", null); testPostRequest(context, vertx, "/content/simple.html", resp -> { assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals("global+B+C", resp.bodyAsString(), "Wrong engines processed request, expected 'global+B+C'"); }); }
@Test @KnotxApplyConfiguration("io/knotx/server/test-server.json") public void whenRequestingPostLocalPathWithAlternateTransition_expectLocalApostC( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleKnot(vertx, "A-post-engine", "+Apost", "go-c"); createSimpleKnot(vertx, "C-engine", "+C", null); testPostRequest(context, vertx, "/content/local/simple.html", resp -> { assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals("local+Apost+C", resp.bodyAsString(), "Wrong engines processed request, expected " + "local+Apost+C"); }); }
@Test @KnotxApplyConfiguration("io/knotx/server/test-server.json") public void whenRequestingPostLocalPathWithFirstTransition_expectLocalApostBC( VertxTestContext context, Vertx vertx) { createPassThroughKnot(vertx, "test-splitter"); createPassThroughKnot(vertx, "test-assembler"); createSimpleKnot(vertx, "A-post-engine", "+Apost", "go-b"); createSimpleKnot(vertx, "B-engine", "+B", "go-c"); createSimpleKnot(vertx, "C-engine", "+C", null); testPostRequest(context, vertx, "/content/local/simple.html", resp -> { assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); assertNotNull(resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals(EXPECTED_XSERVER_HEADER_VALUE, resp.getHeader(EXPECTED_RESPONSE_HEADER)); assertEquals("local+Apost+B+C", resp.bodyAsString(), "Wrong engines processed request, expected " + "local+Apost+B+C"); }); }