Search in sources :

Example 46 with WebClientResponse

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

the class TestDefaultCorsSupport method testGetWithoutCors.

@Test
void testGetWithoutCors() throws ExecutionException, InterruptedException {
    WebServer server = null;
    WebClient client;
    try {
        server = WebServer.create(prepRouting(false)).start().toCompletableFuture().get();
        client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
        WebClientResponse response = client.get().path("/greet").submit().toCompletableFuture().get();
        String greeting = response.content().as(String.class).toCompletableFuture().get();
        assertThat(greeting, is("Hello World!"));
    } finally {
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebServer(io.helidon.webserver.WebServer) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 47 with WebClientResponse

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

the class TestTwoCorsConfigs method test1PreFlightAllowedOriginOtherGreeting.

@Test
void test1PreFlightAllowedOriginOtherGreeting() throws ExecutionException, InterruptedException {
    WebClientResponse res = runTest1PreFlightAllowedOrigin();
    Http.ResponseStatus status = res.status();
    assertThat(status.code(), is(Http.Status.FORBIDDEN_403.code()));
    assertThat(status.reasonPhrase(), is("CORS origin is denied"));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Http(io.helidon.common.http.Http) Test(org.junit.jupiter.api.Test)

Example 48 with WebClientResponse

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

the class AbstractCorsTest method testSimple.

@Test
public void testSimple() throws Exception {
    WebClientResponse response = client().get().path(contextRoot()).accept(MediaType.TEXT_PLAIN).request().toCompletableFuture().get();
    Http.ResponseStatus result = response.status();
    assertThat(result.code(), is(Http.Status.OK_200.code()));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Http(io.helidon.common.http.Http) Test(org.junit.jupiter.api.Test)

Example 49 with WebClientResponse

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

the class AbstractCorsTest method test2ErrorResponse.

@Test
void test2ErrorResponse() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().get().path(path(SERVICE_2) + "/notfound").contentType(MediaType.TEXT_PLAIN);
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    WebClientResponse res = reqBuilder.submit().toCompletableFuture().get();
    assertThat(res.status(), is(not(Http.Status.OK_200)));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), is(Optional.empty()));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 50 with WebClientResponse

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

the class AbstractCorsTest method test1PreFlightAllowedHeaders2.

@Test
void test1PreFlightAllowedHeaders2() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().options().path(path(SERVICE_1));
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    headers.add(ACCESS_CONTROL_REQUEST_HEADERS, "X-foo, X-bar");
    WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("http://foo.bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_METHODS), present(is("PUT")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-foo")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_MAX_AGE), present(is("3600")));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) 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