Search in sources :

Example 1 with WebClientResponse

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

the class MainTest method testMicrometer.

@Test
@Order(4)
void testMicrometer() {
    WebClientResponse response = webClient.get().path("/micrometer").request().await();
    Assertions.assertEquals(200, response.status().code());
    String output = response.content().as(String.class).await();
    String expected = Main.ALL_GETS_TIMER_NAME + "_seconds_count " + expectedAllGets;
    Assertions.assertTrue(output.contains(expected), // all gets; the put
    "Unable to find expected all-gets timer count " + expected + "; output is " + output);
    // is not counted
    Assertions.assertTrue(output.contains(Main.ALL_GETS_TIMER_NAME + "_seconds_sum"), "Unable to find expected all-gets timer sum");
    expected = Main.PERSONALIZED_GETS_COUNTER_NAME + "_total " + expectedPersonalizedGets;
    Assertions.assertTrue(output.contains(expected), "Unable to find expected counter result " + expected + "; output is " + output);
    response.close();
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 2 with WebClientResponse

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

the class MainTest method testHelloWorld.

@Test
public void testHelloWorld() {
    JsonObject jsonObject;
    WebClientResponse response;
    jsonObject = webClient.get().path("/greet").request(JsonObject.class).await();
    assertEquals("Hello World!", jsonObject.getString("message"));
    jsonObject = webClient.get().path("/greet/Joe").request(JsonObject.class).await();
    assertEquals("Hello Joe!", jsonObject.getString("message"));
    response = webClient.put().path("/greet/greeting").submit(TEST_JSON_OBJECT).await();
    assertEquals(204, response.status().code());
    jsonObject = webClient.get().path("/greet/Joe").request(JsonObject.class).await();
    assertEquals("Hola Joe!", jsonObject.getString("message"));
    response = webClient.get().path("/metrics").request().await();
    assertEquals(200, response.status().code());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) JsonObject(jakarta.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 3 with WebClientResponse

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

the class MainTest method testMetrics.

@Test
public void testMetrics() {
    WebClientResponse response;
    String get = webClient.get().path("/greet").request(String.class).await();
    assertThat("Response from generic greeting", get, containsString("Hello World!"));
    get = webClient.get().path("/greet/Joe").request(String.class).await();
    assertThat("Response body from personalized greeting", get, containsString("Hello Joe!"));
    String openMetricsOutput = webClient.get().path("/metrics/" + KPI_REGISTRY_TYPE.getName()).request(String.class).await();
    assertThat("Returned metrics output", openMetricsOutput, chooseMatcher());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 4 with WebClientResponse

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

the class TestCORS method testNamedGreetWithCors.

// Run after CORS test changes greeting to Cheers.
@Order(12)
@Test
void testNamedGreetWithCors() {
    WebClientRequestBuilder builder = client.get();
    Headers headers = builder.headers();
    headers.add("Origin", "http://foo.com");
    headers.add("Host", "here.com");
    WebClientResponse r = getResponse("/greet/Maria", builder);
    assertThat("HTTP response", r.status().code(), is(200));
    assertThat(fromPayload(r), containsString("Cheers Maria"));
    headers = r.headers();
    Optional<String> allowOrigin = headers.value(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
    assertThat("Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " presence check", allowOrigin.isPresent(), is(true));
    assertThat(allowOrigin.get(), is("*"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 5 with WebClientResponse

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

the class TestCORS method testAnonymousGreetWithCors.

// Run after the non-CORS tests (so the greeting is Hola) but before the CORS test that changes the greeting again.
@Order(10)
@Test
void testAnonymousGreetWithCors() {
    WebClientRequestBuilder builder = client.get();
    Headers headers = builder.headers();
    headers.add("Origin", "http://foo.com");
    headers.add("Host", "here.com");
    WebClientResponse r = getResponse("/greet", builder);
    assertThat("HTTP response", r.status().code(), is(200));
    String payload = fromPayload(r);
    assertThat("HTTP response payload", payload, is("Hola World!"));
    headers = r.headers();
    Optional<String> allowOrigin = headers.value(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
    assertThat("Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " is present", allowOrigin.isPresent(), is(true));
    assertThat("CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin.get(), is("*"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

WebClientResponse (io.helidon.webclient.WebClientResponse)120 Test (org.junit.jupiter.api.Test)85 WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)38 Headers (io.helidon.common.http.Headers)24 WebClient (io.helidon.webclient.WebClient)24 JsonObject (jakarta.json.JsonObject)22 Order (org.junit.jupiter.api.Order)16 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)16 Http (io.helidon.common.http.Http)15 DataChunk (io.helidon.common.http.DataChunk)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Single (io.helidon.common.reactive.Single)7 WebServer (io.helidon.webserver.WebServer)7 Logger (java.util.logging.Logger)7 Context (io.helidon.common.context.Context)6 MediaType (io.helidon.common.http.MediaType)6 URI (java.net.URI)6 Optional (java.util.Optional)6 Contexts (io.helidon.common.context.Contexts)5 Multi (io.helidon.common.reactive.Multi)5