Search in sources :

Example 36 with WebClientResponse

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

the class WebSecurityBuilderGateDefaultsTest method testForbidden.

private void testForbidden(String uri, String username, String password) throws ExecutionException, InterruptedException {
    WebClientResponse response = callProtected(uri, username, password);
    assertThat(uri + " for user " + username + " should be forbidden", response.status(), is(Http.Status.FORBIDDEN_403));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse)

Example 37 with WebClientResponse

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

the class WebSecurityBuilderGateDefaultsTest method testProtected.

private void testProtected(String uri, String username, String password, Set<String> expectedRoles, Set<String> invalidRoles) throws ExecutionException, InterruptedException {
    WebClientResponse response = callProtected(uri, username, password);
    assertThat(response.status(), is(Http.Status.OK_200));
    response.content().as(String.class).thenAccept(it -> {
        // check login
        assertThat(it, containsString("id='" + username + "'"));
        // check roles
        expectedRoles.forEach(role -> assertThat(it, containsString(":" + role)));
        invalidRoles.forEach(role -> assertThat(it, not(containsString(":" + role))));
    }).toCompletableFuture().get();
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 38 with WebClientResponse

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

the class WebSecurityBuilderGateDefaultsTest method basicTest401.

@Test
public void basicTest401() throws ExecutionException, InterruptedException {
    // here we call the endpoint
    webClient.get().uri(serverBaseUri + "/noRoles").request().thenAccept(it -> {
        assertThat(it.status(), is(Http.Status.UNAUTHORIZED_401));
        it.headers().first(Http.Header.WWW_AUTHENTICATE).ifPresentOrElse(header -> assertThat(header.toLowerCase(), is("basic realm=\"mic\"")), () -> {
            throw new IllegalStateException("Header " + Http.Header.WWW_AUTHENTICATE + " is" + " not present in response!");
        });
    }).toCompletableFuture().get();
    WebClientResponse webClientResponse = callProtected(serverBaseUri + "/noRoles", "invalidUser", "invalidPassword");
    assertThat(webClientResponse.status(), is(Http.Status.UNAUTHORIZED_401));
    webClientResponse.headers().first(Http.Header.WWW_AUTHENTICATE).ifPresentOrElse(header -> assertThat(header.toLowerCase(), is("basic realm=\"mic\"")), () -> {
        throw new IllegalStateException("Header " + Http.Header.WWW_AUTHENTICATE + " is" + " not present in response!");
    });
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Test(org.junit.jupiter.api.Test)

Example 39 with WebClientResponse

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

the class LifeCycleExtension method shutdown.

/**
 * Shutdown test application
 */
public void shutdown() {
    WebClient testClient = WebClient.builder().baseUri(String.format("http://localhost:%d", HelidonProcessRunner.HTTP_PORT)).build();
    WebClientResponse response = testClient.get().path("/Exit").submit().await(1, TimeUnit.MINUTES);
    LOGGER.info(() -> String.format("Status: %s", response.status()));
    LOGGER.info(() -> String.format("Response: %s", response.content().as(String.class).await(1, TimeUnit.MINUTES)));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebClient(io.helidon.webclient.WebClient)

Example 40 with WebClientResponse

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

the class ContextCheckTest method testContextCheck.

@Test
void testContextCheck() {
    WebClient webClient = createNewClient();
    WebClientResponse r = webClient.get().path("/contextCheck").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, "jack").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, "password").request().await();
    assertThat(r.status().code(), is(Http.Status.OK_200.code()));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebClient(io.helidon.webclient.WebClient) 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