Search in sources :

Example 21 with WebClientResponse

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");
}
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 22 with WebClientResponse

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(), "*");
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 23 with WebClientResponse

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");
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 24 with WebClientResponse

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());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Test(org.junit.jupiter.api.Test)

Example 25 with WebClientResponse

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>"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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