Search in sources :

Example 6 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 7 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();
    assertTrue(get.contains("Hello World!"));
    get = webClient.get().path("/greet/Joe").request(String.class).await();
    assertTrue(get.contains("Hello Joe!"));
    String openMetricsOutput = webClient.get().path("/metrics/application").request(String.class).await();
    LineNumberReader reader = new LineNumberReader(new StringReader(openMetricsOutput));
    List<String> returnedLines = reader.lines().collect(Collectors.toList());
    List<String> expected = List.of(">> skip to timer total >>", "# TYPE application_" + GreetService.TIMER_FOR_GETS + "_mean_seconds gauge", valueMatcher("mean"), ">> end of output >>");
    assertLinesMatch(expected, returnedLines, GreetService.TIMER_FOR_GETS + "_mean_seconds TYPE and value");
    expected = List.of(">> skip to max >>", "# TYPE application_" + GreetService.TIMER_FOR_GETS + "_max_seconds gauge", valueMatcher("max"), ">> end of output >>");
    assertLinesMatch(expected, returnedLines, GreetService.TIMER_FOR_GETS + "_max_seconds TYPE and value");
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) StringReader(java.io.StringReader) LineNumberReader(java.io.LineNumberReader) Test(org.junit.jupiter.api.Test)

Example 8 with WebClientResponse

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

the class FileServiceTest method testList.

@Test
@Order(3)
public void testList() {
    WebClientResponse response = webClient.get().contentType(MediaType.APPLICATION_JSON).request().await();
    assertThat(response.status().code(), Matchers.is(200));
    JsonObject json = response.content().as(JsonObject.class).await();
    assertThat(json, Matchers.is(notNullValue()));
    List<String> files = json.getJsonArray("files").getValuesAs(v -> ((JsonString) v).getString());
    assertThat(files, hasItem("foo.txt"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) JsonObject(jakarta.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonString(jakarta.json.JsonString) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 9 with WebClientResponse

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

the class FileServiceTest method testDownload.

@Test
@Order(4)
public void testDownload() {
    WebClientResponse response = webClient.get().path("foo.txt").accept(MediaType.APPLICATION_OCTET_STREAM).request().await();
    assertThat(response.status().code(), is(200));
    assertThat(response.headers().first("Content-Disposition").orElse(null), containsString("filename=\"foo.txt\""));
    byte[] bytes = response.content().as(byte[].class).await();
    assertThat(new String(bytes, StandardCharsets.UTF_8), Matchers.is("bar\n"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JsonString(jakarta.json.JsonString) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 10 with WebClientResponse

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

the class TestCORS method testHelloWorld.

// Make sure this runs before the greeting message changes so responses are deterministic.
@Order(1)
@Test
public void testHelloWorld() {
    WebClientResponse r = getResponse("/greet");
    assertThat("HTTP response1", r.status().code(), is(200));
    assertThat("default message", fromPayload(r), is("Hello World!"));
    r = getResponse("/greet/Joe");
    assertThat("HTTP response2", r.status().code(), is(200));
    assertThat("Hello Joe message", fromPayload(r), is("Hello Joe!"));
    r = putResponse("/greet/greeting", "Hola");
    assertThat("HTTP response3", r.status().code(), is(204));
    r = getResponse("/greet/Jose");
    assertThat("HTTP response4", r.status().code(), is(200));
    assertThat("Hola Jose message", fromPayload(r), is("Hola Jose!"));
    r = getResponse("/health");
    assertThat("HTTP response health", r.status().code(), is(200));
    r = getResponse("/metrics");
    assertThat("HTTP response metrics", r.status().code(), is(200));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) 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