use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class MainTest 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");
assertEquals(200, r.status().code(), "HTTP response1");
assertEquals("Hello World!", fromPayload(r).getMessage(), "default message");
r = getResponse("/greet/Joe");
assertEquals(200, r.status().code(), "HTTP response2");
assertEquals("Hello Joe!", fromPayload(r).getMessage(), "hello Joe message");
r = putResponse("/greet/greeting", new GreetingMessage("Hola"));
assertEquals(204, r.status().code(), "HTTP response3");
r = getResponse("/greet/Jose");
assertEquals(200, r.status().code(), "HTTP response4");
assertEquals("Hola Jose!", fromPayload(r).getMessage(), "hola Jose message");
r = getResponse("/health");
assertEquals(200, r.status().code(), "HTTP response2");
r = getResponse("/metrics");
assertEquals(200, r.status().code(), "HTTP response2");
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class MainTest method testNamedGreetWithCors.
// Run after CORS test changes greeting to Cheers.
@Order(12)
@Test
void testNamedGreetWithCors() {
WebClientRequestBuilder builder = webClient.get();
Headers headers = builder.headers();
headers.add("Origin", "http://foo.com");
headers.add("Host", "here.com");
WebClientResponse r = getResponse("/greet/Maria", builder);
assertEquals(200, r.status().code(), "HTTP response");
assertTrue(fromPayload(r).getMessage().contains("Cheers Maria"));
headers = r.headers();
Optional<String> allowOrigin = headers.value(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertTrue(allowOrigin.isPresent(), "Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " is absent");
assertEquals(allowOrigin.get(), "*");
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class MainTest method testGreetingChangeWithCorsAndOtherOrigin.
// After all other tests so we can rely on deterministic greetings.
@Order(100)
@Test
void testGreetingChangeWithCorsAndOtherOrigin() {
WebClientRequestBuilder builder = webClient.put();
Headers headers = builder.headers();
headers.add("Origin", "http://other.com");
headers.add("Host", "here.com");
WebClientResponse r = putResponse("/greet/greeting", new GreetingMessage("Ahoy"), builder);
// Result depends on whether we are using overrides or not.
boolean isOverriding = Config.create().get("cors").exists();
assertEquals(isOverriding ? 204 : 403, r.status().code(), "HTTP response3");
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class MainTest method testHealth.
@Test
public void testHealth() {
WebClientResponse response = webClient.get().path("/health").request().await();
assertEquals(Http.Status.OK_200, response.status());
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class BasicExampleTest method testPublic.
// now for the tests
@Test
public void testPublic() {
// Must be accessible without authentication
WebClientResponse response = client.get().uri(getServerBase() + "/public").request().await(10, TimeUnit.SECONDS);
assertThat(response.status(), is(Http.Status.OK_200));
String entity = response.content().as(String.class).await(10, TimeUnit.SECONDS);
assertThat(entity, containsString("<ANONYMOUS>"));
}
Aggregations