Search in sources :

Example 1 with TestResponse

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

the class MainTest method supports.

@Test
public void supports() throws Exception {
    // Jersey
    TestResponse response = createClient(Main::supports).path("/api/hw").get();
    assertEquals(200, response.status().code());
    assertEquals("Hello world!", response.asString().get());
    // Static content
    response = createClient(Main::supports).path("/index.html").get();
    assertEquals(200, response.status().code());
    assertEquals(MediaType.TEXT_HTML.toString(), response.headers().first(Http.Header.CONTENT_TYPE).orElse(null));
    // JSON
    response = createClient(Main::supports).path("/hello/Europe").get();
    assertEquals(200, response.status().code());
    assertEquals("{\"message\":\"Hello Europe\"}", response.asString().get());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 2 with TestResponse

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

the class MainTest method routingAsFilter.

@Test
public void routingAsFilter() throws Exception {
    // POST
    TestResponse response = createClient(Main::routingAsFilter).path("/post-endpoint").post();
    assertEquals(201, response.status().code());
    // GET
    response = createClient(Main::routingAsFilter).path("/get-endpoint").get();
    assertEquals(204, response.status().code());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 3 with TestResponse

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

the class MainTest method parametersAndHeaders.

@Test
public void parametersAndHeaders() throws Exception {
    TestResponse response = createClient(Main::parametersAndHeaders).path("/context/aaa").queryParameter("bar", "bbb").header("foo", "ccc").get();
    assertEquals(200, response.status().code());
    String s = response.asString().get();
    assertTrue(s.contains("id: aaa"));
    assertTrue(s.contains("bar: bbb"));
    assertTrue(s.contains("foo: ccc"));
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 4 with TestResponse

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

the class MainTest method readContentEntity.

@Test
public void readContentEntity() throws Exception {
    // foo
    TestResponse response = createClient(Main::readContentEntity).path("/foo").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa"));
    assertEquals(200, response.status().code());
    assertEquals("aaa", response.asString().get());
    // bar
    response = createClient(Main::readContentEntity).path("/bar").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa"));
    assertEquals(200, response.status().code());
    assertEquals("aaa", response.asString().get());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 5 with TestResponse

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

the class MainTest method errorHandling.

@Test
public void errorHandling() throws Exception {
    // Valid
    TestResponse response = createClient(Main::errorHandling).path("/compute").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "2"));
    assertEquals(200, response.status().code());
    assertEquals("100 / 2 = 50", response.asString().get());
    // Zero
    response = createClient(Main::errorHandling).path("/compute").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "0"));
    assertEquals(412, response.status().code());
    // NaN
    response = createClient(Main::errorHandling).path("/compute").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa"));
    assertEquals(400, response.status().code());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) 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