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());
}
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()));
}
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()));
}
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()));
}
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()));
}
Aggregations