Search in sources :

Example 1 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class HttpClientFacadeTest method whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest.

@Test
@KnotxConfiguration("knotx-action-adapter-http-test.json")
public void whenServiceRequestedWithoutPathParam_expectNoServiceRequestAndBadRequest(TestContext context) throws Exception {
    Async async = context.async();
    // given
    final WebClient mockedWebClient = PowerMockito.spy(webClient());
    HttpClientFacade clientFacade = new HttpClientFacade(mockedWebClient, getConfiguration());
    // when
    Single<ClientResponse> result = clientFacade.process(new AdapterRequest().setParams(new JsonObject()).setRequest(clientRequest), HttpMethod.POST);
    // then
    result.doOnError(error -> {
        context.assertEquals("Parameter `path` was not defined in `params`!", error.getMessage());
        Mockito.verify(mockedWebClient, Mockito.times(0)).request(Matchers.any(), Matchers.anyInt(), Matchers.anyString(), Matchers.anyString());
    }).subscribe(response -> context.fail("Error should occur!"), error -> async.complete());
}
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) AdapterRequest(io.knotx.dataobjects.AdapterRequest) 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 2 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class HttpServiceAdapterProxyTest method callExistingService_expectOKResponseWithServiceDataProvidedByService1.

@Test
@KnotxConfiguration("knotx-service-adapter-http-test.json")
public void callExistingService_expectOKResponseWithServiceDataProvidedByService1(TestContext context) throws Exception {
    final String expected = FileReader.readText("first-response.json");
    callAdapterServiceWithAssertions(context, "/service/mock/first.json", adapterResponse -> {
        context.assertTrue(adapterResponse.getResponse().getStatusCode() == HttpResponseStatus.OK.code());
        JsonObject serviceResponse = new JsonObject(adapterResponse.getResponse().getBody().toString());
        JsonObject expectedResponse = new JsonObject(expected);
        context.assertEquals(serviceResponse, expectedResponse);
    }, error -> context.fail(error.getMessage()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration)

Example 3 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class ActionKnotProxyVerticleTest method callPostWithActionFragmentWithIncorrectSnippetId_expectStatusCode500.

@Test
@KnotxConfiguration("knotx-test.json")
public void callPostWithActionFragmentWithIncorrectSnippetId_expectStatusCode500(TestContext context) throws Exception {
    KnotContext knotContext = createKnotContext("fragment_form_redirect_in.txt");
    knotContext.getClientRequest().setMethod(HttpMethod.POST).setFormAttributes(MultiMap.caseInsensitiveMultiMap().add(HIDDEN_INPUT_TAG_NAME, "snippet_id_not_exists"));
    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 4 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class ActionKnotProxyVerticleTest method callGetWithNoActionFragments_expectResponseOkNoFragmentChanges.

@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithNoActionFragments_expectResponseOkNoFragmentChanges(TestContext context) throws Exception {
    String expectedTemplatingFragment = FileReader.readText("fragment_templating_out.txt");
    KnotContext knotContext = createKnotContext(FIRST_FRAGMENT, LAST_FRAGMENT, "fragment_templating_in.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(FIRST_FRAGMENT.content(), fragments.get(0).content());
        context.assertEquals(expectedTemplatingFragment, fragments.get(1).content());
        context.assertEquals(LAST_FRAGMENT.content(), fragments.get(2).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 5 with KnotxConfiguration

use of io.knotx.junit.rule.KnotxConfiguration in project knotx by Cognifide.

the class ActionKnotProxyVerticleTest method callGetWithTwoActionFragments_expectResponseOkTwoFragmentChanges.

@Test
@KnotxConfiguration("knotx-test.json")
public void callGetWithTwoActionFragments_expectResponseOkTwoFragmentChanges(TestContext context) throws Exception {
    String expectedRedirectFormFragment = FileReader.readText("fragment_form_redirect_out.txt");
    String expectedSelfFormFragment = FileReader.readText("fragment_form_self_out.txt");
    KnotContext knotContext = createKnotContext(FIRST_FRAGMENT, LAST_FRAGMENT, "fragment_form_redirect_in.txt", "fragment_form_self_in.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(FIRST_FRAGMENT.content(), fragments.get(0).content());
        context.assertEquals(clean(expectedRedirectFormFragment), clean(fragments.get(1).content()));
        context.assertEquals(clean(expectedSelfFormFragment), clean(fragments.get(2).content()));
        context.assertEquals(LAST_FRAGMENT.content(), fragments.get(3).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)

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