use of io.helidon.webclient.WebClient in project helidon by oracle.
the class TracingTest method testTracingNoServerSuccess.
@Test
void testTracingNoServerSuccess() throws ExecutionException, InterruptedException {
MockTracer mockTracer = new MockTracer();
String uri = "http://localhost:" + webServer.port() + "/greet";
Context context = Context.builder().id("tracing-unit-test").build();
context.register(mockTracer);
WebClient client = WebClient.builder().baseUri(uri).context(context).addMediaSupport(JsonpSupport.create()).config(CONFIG.get("client")).build();
WebClientResponse response = client.get().request().toCompletableFuture().get();
// we must fully read entity for tracing to finish
response.content().as(JsonObject.class).toCompletableFuture().get();
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertThat(mockSpans, iterableWithSize(1));
MockSpan theSpan = mockSpans.get(0);
assertThat(theSpan.operationName(), is("GET-" + uri));
List<MockSpan.LogEntry> logEntries = theSpan.logEntries();
assertThat(logEntries, empty());
Map<String, Object> tags = theSpan.tags();
assertThat(tags.get(Tags.HTTP_STATUS.getKey()), is(200));
assertThat(tags.get(Tags.HTTP_METHOD.getKey()), is("GET"));
assertThat(tags.get(Tags.HTTP_URL.getKey()), is(uri));
assertThat(tags.get(Tags.COMPONENT.getKey()), is("helidon-webclient"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class TracingTest method testTracingNoServerFailure.
@Test
void testTracingNoServerFailure() throws ExecutionException, InterruptedException {
MockTracer mockTracer = new MockTracer();
Context context = Context.builder().id("tracing-unit-test").build();
context.register(mockTracer);
WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").context(context).addMediaSupport(JsonpSupport.create()).config(CONFIG.get("client")).build();
WebClientResponse response = client.get().path("/error").request().toCompletableFuture().get();
// we must fully read entity, as otherwise tracing does not finish
response.content().as(String.class).toCompletableFuture().get();
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertThat(mockSpans, iterableWithSize(1));
MockSpan theSpan = mockSpans.get(0);
assertThat(theSpan.operationName(), is("GET-http://localhost:" + webServer.port() + "/greet/error"));
List<MockSpan.LogEntry> logEntries = theSpan.logEntries();
assertThat(logEntries, iterableWithSize(1));
MockSpan.LogEntry logEntry = logEntries.get(0);
Map<String, ?> fields = logEntry.fields();
assertThat(fields.get("event"), is("error"));
assertThat(fields.get("message"), is("Response HTTP status: 404"));
assertThat(fields.get("error.kind"), is("ClientError"));
Map<String, Object> tags = theSpan.tags();
assertThat(tags.get(Tags.HTTP_STATUS.getKey()), is(404));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class UriPartTest method testQueryNotDecoded.
@Test
public void testQueryNotDecoded() {
WebClient webClient = createNewClient(request -> {
assertThat(request.query(), is("first&second%26=val&ue%26"));
return Single.just(request);
});
String response = webClient.get().queryParam("first&second%26", "val&ue%26").skipUriEncoding().request(String.class).await();
assertThat(response.trim(), is("{\"message\":\"Hello World!\"}"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class UriPartTest method testPathNotDecoded.
@Test
public void testPathNotDecoded() {
WebClient webClient = createNewClient(request -> {
assertThat(request.path().toRawString(), is("/greet/path%26"));
return Single.just(request);
});
assertThrows(CompletionException.class, () -> webClient.get().path("path%26").skipUriEncoding().request(String.class).await());
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class WebclientServiceValuePropagationTest method testUriPartsPropagation.
@Test
public void testUriPartsPropagation() {
WebClient webClient = WebClient.builder().baseUri("http://invalid").addService(new UriChangingService()).build();
String response = webClient.get().path("replace/me").request(String.class).await();
assertThat(response, is("Hi Test"));
}
Aggregations