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));
}
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());
}
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());
}
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());
}
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());
}
Aggregations