Search in sources :

Example 16 with KnotxConfiguration

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();
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 17 with KnotxConfiguration

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();
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 18 with KnotxConfiguration

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();
    });
}
Also used : Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.reactivex.core.http.HttpClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 19 with KnotxConfiguration

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()));
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Matchers(org.mockito.Matchers) UnsupportedServiceException(io.knotx.adapter.common.exception.UnsupportedServiceException) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Single(io.reactivex.Single) ClientResponse(io.knotx.dataobjects.ClientResponse) Vertx(io.vertx.reactivex.core.Vertx) Lists(com.google.common.collect.Lists) AdapterRequest(io.knotx.dataobjects.AdapterRequest) FileReader(io.knotx.junit.util.FileReader) ClientRequest(io.knotx.dataobjects.ClientRequest) JsonObject(io.vertx.core.json.JsonObject) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) PowerMockito(org.powermock.api.mockito.PowerMockito) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) HttpAdapterConfiguration(io.knotx.adapter.common.http.HttpAdapterConfiguration) WebClient(io.vertx.reactivex.ext.web.client.WebClient) RuleChain(org.junit.rules.RuleChain) Mockito(org.mockito.Mockito) MultiMap(io.vertx.reactivex.core.MultiMap) List(java.util.List) Rule(org.junit.Rule) ServiceMetadata(io.knotx.adapter.common.http.ServiceMetadata) HttpMethod(io.vertx.core.http.HttpMethod) Pattern(java.util.regex.Pattern) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) Async(io.vertx.ext.unit.Async) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) JsonObject(io.vertx.core.json.JsonObject) WebClient(io.vertx.reactivex.ext.web.client.WebClient) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 20 with KnotxConfiguration

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()));
}
Also used : ClientResponse(io.knotx.dataobjects.ClientResponse) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Matchers(org.mockito.Matchers) UnsupportedServiceException(io.knotx.adapter.common.exception.UnsupportedServiceException) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Single(io.reactivex.Single) ClientResponse(io.knotx.dataobjects.ClientResponse) Vertx(io.vertx.reactivex.core.Vertx) Lists(com.google.common.collect.Lists) AdapterRequest(io.knotx.dataobjects.AdapterRequest) FileReader(io.knotx.junit.util.FileReader) ClientRequest(io.knotx.dataobjects.ClientRequest) JsonObject(io.vertx.core.json.JsonObject) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) PowerMockito(org.powermock.api.mockito.PowerMockito) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) HttpAdapterConfiguration(io.knotx.adapter.common.http.HttpAdapterConfiguration) WebClient(io.vertx.reactivex.ext.web.client.WebClient) RuleChain(org.junit.rules.RuleChain) Mockito(org.mockito.Mockito) MultiMap(io.vertx.reactivex.core.MultiMap) List(java.util.List) Rule(org.junit.Rule) ServiceMetadata(io.knotx.adapter.common.http.ServiceMetadata) HttpMethod(io.vertx.core.http.HttpMethod) Pattern(java.util.regex.Pattern) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) MultiMap(io.vertx.reactivex.core.MultiMap) Async(io.vertx.ext.unit.Async) HttpClientFacade(io.knotx.adapter.common.http.HttpClientFacade) JsonObject(io.vertx.core.json.JsonObject) 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