Search in sources :

Example 16 with TestResponse

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

the class CommentsServiceTest method testRouting.

@Test
public void testRouting() throws Exception {
    Routing routing = Routing.builder().register(new CommentsService()).build();
    TestResponse response = TestClient.create(routing).path("one").get();
    assertEquals(Http.Status.OK_200, response.status());
    response = TestClient.create(routing).path("one").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "aaa"));
    assertEquals(Http.Status.OK_200, response.status());
    response = TestClient.create(routing).path("one").get();
    assertEquals(Http.Status.OK_200, response.status());
    byte[] data = response.asBytes().toCompletableFuture().join();
    assertEquals("anonymous: aaa", new String(data, StandardCharsets.UTF_8));
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Routing(io.helidon.webserver.Routing) Test(org.junit.jupiter.api.Test)

Example 17 with TestResponse

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

the class MainTest method argot.

@Test
public void argot() throws Exception {
    TestResponse response = TestClient.create(Main.createRouting(true)).path("/comments/one").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "Spring framework is the BEST!"));
    assertEquals(Http.Status.NOT_ACCEPTABLE_406, response.status());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 18 with TestResponse

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

the class MainTest method anonymousDisabled.

@Test
public void anonymousDisabled() throws Exception {
    TestResponse response = TestClient.create(Main.createRouting(false)).path("/comment/one").get();
    assertEquals(Http.Status.FORBIDDEN_403, response.status());
}
Also used : TestResponse(io.helidon.webserver.testsupport.TestResponse) Test(org.junit.jupiter.api.Test)

Example 19 with TestResponse

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

the class MainTest method firstRouting.

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

Example 20 with TestResponse

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

the class MainTest method mediaReader.

@Test
public void mediaReader() throws Exception {
    TestResponse response = createClient(Main::mediaReader).path("/create-record").post(MediaPublisher.create(MediaType.parse("application/name"), "John Smith"));
    assertEquals(201, response.status().code());
    assertEquals("John Smith", response.asString().get());
    // Unsupported Content-Type
    response = createClient(Main::mediaReader).path("/create-record").post(MediaPublisher.create(MediaType.TEXT_PLAIN, "John Smith"));
    assertEquals(500, 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