use of io.vertx.reactivex.core.http.HttpClientResponse in project knotx by Cognifide.
the class KnotxServerRoutingTest method request.
private static Observable<HttpClientResponse> request(HttpClient client, HttpMethod method, int port, String domain, String uri, Action1<HttpClientRequest> requestBuilder) {
return Observable.unsafeCreate(subscriber -> {
HttpClientRequest req = client.request(method, port, domain, uri);
Observable<HttpClientResponse> resp = req.toObservable();
resp.subscribe(subscriber);
requestBuilder.call(req);
req.end();
});
}
use of io.vertx.reactivex.core.http.HttpClientResponse in project knotx by Cognifide.
the class SampleApplicationTest method testPostRequest.
private void testPostRequest(TestContext context, String url, Map<String, String> formData, String expectedResponseFile, boolean ajaxCall) {
HttpClient client = Vertx.newInstance(vertx.vertx()).createHttpClient();
Async async = context.async();
Observable<HttpClientResponse> request = request(client, HttpMethod.POST, KNOTX_SERVER_PORT, KNOTX_SERVER_ADDRESS, url, req -> {
String bodyForm = formData.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).reduce((p1, p2) -> p1 + "&" + p2).get();
req.headers().set("content-length", String.valueOf(bodyForm.length()));
req.headers().set("content-type", "application/x-www-form-urlencoded");
if (ajaxCall) {
req.headers().set("X-Requested-With", "XMLHttpRequest");
}
req.write(bodyForm);
});
request.subscribe(resp -> resp.bodyHandler(body -> {
context.assertEquals(resp.statusCode(), HttpResponseStatus.OK.code());
try {
context.assertEquals(Jsoup.parse(body.toString()).body().html(), Jsoup.parse(FileReader.readText(expectedResponseFile)).body().html());
} catch (Exception e) {
context.fail(e);
}
async.complete();
}));
}
Aggregations