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