Search in sources :

Example 21 with TestResponse

use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.

the class MainTest method organiseCode.

@Test
public void organiseCode() throws Exception {
    // List
    TestResponse response = createClient(Main::organiseCode).path("/catalog-context-path").get();
    assertEquals(200, response.status().code());
    assertEquals("1, 2, 3, 4, 5", response.asString().get());
    // Get by id
    response = createClient(Main::organiseCode).path("/catalog-context-path/aaa").get();
    assertEquals(200, response.status().code());
    assertEquals("Item: aaa", response.asString().get());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 22 with TestResponse

use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.

the class PrometheusSupportTest method doTestRequest.

private TestResponse doTestRequest(String nameQuery) throws Exception {
    TestRequest request = TestClient.create(routing).path("/metrics");
    if (nameQuery != null && !nameQuery.isEmpty()) {
        request.queryParameter("name[]", nameQuery);
    }
    TestResponse response = request.get();
    assertThat(response.status(), is(Http.Status.OK_200));
    return response;
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) TestRequest(io.helidon.webserver.testsupport.TestRequest)

Example 23 with TestResponse

use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.

the class PrometheusSupportTest method filter.

@Test
public void filter() throws Exception {
    TestResponse response = doTestRequest("alpha");
    assertThat(response.status(), is(Http.Status.OK_200));
    String body = response.asString().get(5, TimeUnit.SECONDS);
    assertThat(body, not(containsString("# TYPE beta")));
    assertThat(body, not(containsString("beta 3.0")));
    assertThat(body, containsString("# TYPE alpha counter"));
    assertThat(body, containsString("alpha{method=\"bar\",} 6.0"));
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Example 24 with TestResponse

use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.

the class JsonSupportTest method explicitJsonSupportRegistrationMissingJsonProperty.

@Test
public void explicitJsonSupportRegistrationMissingJsonProperty() throws Exception {
    Routing routing = Routing.builder().post("/foo", Handler.create(JsonObject.class, (req, res, json) -> res.send(json))).build();
    JsonObject json = createJson();
    TestResponse response = TestClient.create(routing).path("/foo").post(MediaPublisher.create(MediaType.APPLICATION_JSON.withCharset("UTF-8"), json.toString()));
    assertThat(response.status(), is(equalTo(Http.Status.INTERNAL_SERVER_ERROR_500)));
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Routing(io.helidon.webserver.Routing) JsonObject(jakarta.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 25 with TestResponse

use of io.helidon.webserver.testsupport.TestResponse in project helidon by oracle.

the class TestJsonBindingSupport method genericType.

@Test
public void genericType() throws Exception {
    GenericType<List<Person>> personsType = new GenericType<>() {
    };
    final Routing routing = Routing.builder().post("/foo", (req, res) -> {
        req.content().as(personsType).thenAccept(res::send);
    }).build();
    final String personsJson = "[{\"name\":\"Frank\"},{\"name\":\"John\"}]";
    final TestResponse response = TestClient.create(routing, JsonbSupport.create()).path("/foo").post(MediaPublisher.create(MediaType.APPLICATION_JSON.withCharset("UTF-8"), personsJson));
    assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), is(MediaType.APPLICATION_JSON.toString()));
    final String json = response.asString().get(10, TimeUnit.SECONDS);
    assertThat(json, is(personsJson));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TestResponse(io.helidon.webserver.testsupport.TestResponse) TestClient(io.helidon.webserver.testsupport.TestClient) GenericType(io.helidon.common.GenericType) MediaType(io.helidon.common.http.MediaType) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) MediaPublisher(io.helidon.webserver.testsupport.MediaPublisher) Handler(io.helidon.webserver.Handler) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Http(io.helidon.common.http.Http) Routing(io.helidon.webserver.Routing) GenericType(io.helidon.common.GenericType) TestResponse(io.helidon.webserver.testsupport.TestResponse) Routing(io.helidon.webserver.Routing) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

TestResponse (io.helidon.webserver.testsupport.TestResponse)26 Test (org.junit.jupiter.api.Test)25 Routing (io.helidon.webserver.Routing)10 JsonObject (jakarta.json.JsonObject)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 TestClient (io.helidon.webserver.testsupport.TestClient)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 GenericType (io.helidon.common.GenericType)1 Http (io.helidon.common.http.Http)1 MediaType (io.helidon.common.http.MediaType)1 Handler (io.helidon.webserver.Handler)1 WebServer (io.helidon.webserver.WebServer)1 MediaPublisher (io.helidon.webserver.testsupport.MediaPublisher)1 TestRequest (io.helidon.webserver.testsupport.TestRequest)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1