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());
}
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");
}
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"));
}
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"));
}
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));
}
Aggregations