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