use of io.knotx.dataobjects.AdapterRequest 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.dataobjects.AdapterRequest in project knotx by Cognifide.
the class HttpServiceAdapterProxyTest method callAdapterServiceWithAssertions.
private void callAdapterServiceWithAssertions(TestContext context, String servicePath, Action1<AdapterResponse> onSuccess, Consumer<Throwable> onError) {
AdapterRequest message = payloadMessage(servicePath);
Async async = context.async();
AdapterProxy service = AdapterProxy.createProxy(new Vertx(vertx.vertx()), ADAPTER_ADDRESS);
service.rxProcess(message).doOnSuccess(onSuccess::call).subscribe(success -> async.complete(), onError);
}
use of io.knotx.dataobjects.AdapterRequest in project knotx by Cognifide.
the class ActionKnotProxyImpl method prepareAdapterRequest.
private AdapterRequest prepareAdapterRequest(KnotContext knotContext, FormEntity formEntity) {
AdapterMetadata metadata = formEntity.adapter();
ClientRequest request = new ClientRequest().setPath(knotContext.getClientRequest().getPath()).setMethod(knotContext.getClientRequest().getMethod()).setFormAttributes(knotContext.getClientRequest().getFormAttributes()).setHeaders(getFilteredHeaders(knotContext.getClientRequest().getHeaders(), metadata.getAllowedRequestHeaders()));
AdapterRequest adapterRequest = new AdapterRequest().setRequest(request).setParams(new JsonObject(metadata.getParams())).setAdapterParams(formEntity.adapterParams());
LOGGER.info("Adapter [{}] call with request [{}]", metadata.getAddress(), adapterRequest);
return adapterRequest;
}
use of io.knotx.dataobjects.AdapterRequest in project knotx by Cognifide.
the class ActionKnotProxyVerticleTest method createMockAdapter.
private void createMockAdapter(String address, String addToBody, String signal, Map<String, List<String>> headers) {
Func1<AdapterRequest, AdapterResponse> adapter = adapterRequest -> {
ClientResponse response = new ClientResponse();
response.setStatusCode(HttpResponseStatus.OK.code());
response.setBody(Buffer.buffer().appendString(addToBody));
response.setHeaders(headers.keySet().stream().collect(MultiMapCollector.toMultiMap(o -> o, headers::get)));
return new AdapterResponse().setResponse(response).setSignal(signal);
};
new ServiceBinder(vertx.vertx()).setAddress(address).register(AdapterProxy.class, new MockAdapterImpl(adapter));
}
Aggregations