Search in sources :

Example 41 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class MediaContextTest method testMediaSupportDefaults.

@Test
public void testMediaSupportDefaults() throws Exception {
    WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").build();
    client.get().request(String.class).thenAccept(it -> assertThat(it, is(JSON_GREETING.toString()))).toCompletableFuture().get();
}
Also used : WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 42 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class MetricsTest method testCounter.

@Test
public void testCounter() {
    WebClientService serviceCounterAll = WebClientMetrics.counter().nameFormat("counter.%1$s.%2$s").build();
    WebClientService serviceCounterGet = WebClientMetrics.counter().methods(Http.Method.GET).nameFormat("counter.get.%1$s.%2$s").build();
    WebClientService serviceCounterError = WebClientMetrics.counter().nameFormat("counter.error.%1$s.%2$s").success(false).build();
    WebClientService serviceCounterSuccess = WebClientMetrics.counter().nameFormat("counter.success.%1$s.%2$s").errors(false).build();
    WebClient webClient = createNewClient(serviceCounterAll, serviceCounterGet, serviceCounterError, serviceCounterSuccess);
    Counter counterAll = FACTORY.counter("counter.GET.localhost");
    Counter counterGet = FACTORY.counter("counter.get.GET.localhost");
    Counter counterError = FACTORY.counter("counter.error.GET.localhost");
    Counter counterSuccess = FACTORY.counter("counter.success.GET.localhost");
    assertThat(counterAll.getCount(), is(0L));
    assertThat(counterGet.getCount(), is(0L));
    assertThat(counterError.getCount(), is(0L));
    assertThat(counterSuccess.getCount(), is(0L));
    try {
        webClient.get().request(String.class).toCompletableFuture().get();
        assertThat(counterAll.getCount(), is(1L));
        assertThat(counterGet.getCount(), is(1L));
        assertThat(counterError.getCount(), is(0L));
        assertThat(counterSuccess.getCount(), is(1L));
        webClient.get().path("/error").request().thenCompose(WebClientResponse::close).toCompletableFuture().get();
        assertThat(counterAll.getCount(), is(2L));
        assertThat(counterGet.getCount(), is(2L));
        assertThat(counterError.getCount(), is(1L));
        assertThat(counterSuccess.getCount(), is(1L));
    } catch (Exception e) {
        fail(e);
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Counter(org.eclipse.microprofile.metrics.Counter) WebClientService(io.helidon.webclient.spi.WebClientService) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 43 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class MetricsTest method testMeter.

@Test
public void testMeter() {
    WebClientService serviceMeterAll = WebClientMetrics.meter().nameFormat("meter.%1$s.%2$s").build();
    WebClientService serviceMeterGet = WebClientMetrics.meter().methods(Http.Method.GET).nameFormat("meter.get.%1$s.%2$s").build();
    WebClientService serviceMeterError = WebClientMetrics.meter().nameFormat("meter.error.%1$s.%2$s").success(false).build();
    WebClientService serviceMeterSuccess = WebClientMetrics.meter().nameFormat("meter.success.%1$s.%2$s").errors(false).build();
    WebClient webClient = createNewClient(serviceMeterAll, serviceMeterGet, serviceMeterError, serviceMeterSuccess);
    Meter meterAll = FACTORY.meter("meter.GET.localhost");
    Meter meterGet = FACTORY.meter("meter.get.GET.localhost");
    Meter meterError = FACTORY.meter("meter.error.GET.localhost");
    Meter meterSuccess = FACTORY.meter("meter.success.GET.localhost");
    assertThat(meterAll.getCount(), is(0L));
    assertThat(meterGet.getCount(), is(0L));
    assertThat(meterError.getCount(), is(0L));
    assertThat(meterSuccess.getCount(), is(0L));
    try {
        webClient.get().request(String.class).toCompletableFuture().get();
        assertThat(meterAll.getCount(), is(1L));
        assertThat(meterGet.getCount(), is(1L));
        assertThat(meterError.getCount(), is(0L));
        assertThat(meterSuccess.getCount(), is(1L));
        webClient.get().path("/error").request().thenCompose(WebClientResponse::close).toCompletableFuture().get();
        assertThat(meterAll.getCount(), is(2L));
        assertThat(meterGet.getCount(), is(2L));
        assertThat(meterError.getCount(), is(1L));
        assertThat(meterSuccess.getCount(), is(1L));
    } catch (Exception e) {
        fail(e);
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Meter(org.eclipse.microprofile.metrics.Meter) WebClientService(io.helidon.webclient.spi.WebClientService) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 44 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class MetricsTest method testGaugeInProgress.

@Test
public void testGaugeInProgress() throws Exception {
    ConcurrentGauge progressAll = FACTORY.concurrentGauge("gauge.GET.localhost");
    ConcurrentGauge progressPut = FACTORY.concurrentGauge("gauge.put.PUT.localhost");
    ConcurrentGauge progressGet = FACTORY.concurrentGauge("gauge.get.GET.localhost");
    WebClientService inProgressAll = WebClientMetrics.gaugeInProgress().nameFormat("gauge.%1$s.%2$s").build();
    WebClientService inProgressPut = WebClientMetrics.gaugeInProgress().methods(Http.Method.PUT).nameFormat("gauge.put.%1$s.%2$s").build();
    WebClientService inProgressGet = WebClientMetrics.gaugeInProgress().methods(Http.Method.GET).nameFormat("gauge.get.%1$s.%2$s").build();
    WebClientService clientService = request -> {
        request.whenSent().thenAccept(clientServiceRequest -> {
            assertThat(progressAll.getCount(), is(1L));
            assertThat(progressGet.getCount(), is(1L));
            assertThat(progressPut.getCount(), is(0L));
        });
        return Single.just(request);
    };
    WebClient webClient = createNewClient(inProgressAll, inProgressPut, inProgressGet, clientService);
    assertThat(progressAll.getCount(), is(0L));
    assertThat(progressGet.getCount(), is(0L));
    assertThat(progressPut.getCount(), is(0L));
    webClient.get().request().thenCompose(WebClientResponse::close).toCompletableFuture().get();
    assertThat(progressAll.getCount(), is(0L));
    assertThat(progressGet.getCount(), is(0L));
    assertThat(progressPut.getCount(), is(0L));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) WebClient(io.helidon.webclient.WebClient) WebClientService(io.helidon.webclient.spi.WebClientService) WebClientResponse(io.helidon.webclient.WebClientResponse) Meter(org.eclipse.microprofile.metrics.Meter) Test(org.junit.jupiter.api.Test) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) Counter(org.eclipse.microprofile.metrics.Counter) Single(io.helidon.common.reactive.Single) Matchers.is(org.hamcrest.Matchers.is) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Http(io.helidon.common.http.Http) RegistryFactory(io.helidon.metrics.RegistryFactory) WebClientMetrics(io.helidon.webclient.metrics.WebClientMetrics) WebClientResponse(io.helidon.webclient.WebClientResponse) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) WebClientService(io.helidon.webclient.spi.WebClientService) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 45 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class MutualTlsTest method testNoClientCert.

@Test
public void testNoClientCert() {
    WebClient webClient = createWebClient(CONFIG.get("no-client-cert"));
    CompletionException exception = assertThrows(CompletionException.class, () -> executeRequest(webClient, "https", webServer.port("secured")));
    assertThat(exception.getCause().getMessage(), containsString("Received fatal alert: bad_certificate"));
}
Also used : CompletionException(java.util.concurrent.CompletionException) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Aggregations

WebClient (io.helidon.webclient.WebClient)58 Test (org.junit.jupiter.api.Test)42 WebClientResponse (io.helidon.webclient.WebClientResponse)21 JsonObject (jakarta.json.JsonObject)15 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 Http (io.helidon.common.http.Http)11 Config (io.helidon.config.Config)11 Collections (java.util.Collections)10 WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)9 WebClientService (io.helidon.webclient.spi.WebClientService)9 Json (jakarta.json.Json)9 JsonBuilderFactory (jakarta.json.JsonBuilderFactory)8 IOException (java.io.IOException)8 DataChunk (io.helidon.common.http.DataChunk)7 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)7 CompletionException (java.util.concurrent.CompletionException)7 Context (io.helidon.common.context.Context)6 List (java.util.List)6 TimeUnit (java.util.concurrent.TimeUnit)6 Counter (org.eclipse.microprofile.metrics.Counter)6