use of io.helidon.webserver.Routing in project helidon by oracle.
the class ClassPathContentHandlerTest method serveFromFiles.
@Test
public void serveFromFiles() throws Exception {
Routing routing = Routing.builder().register("/some", StaticContentSupport.create("content")).build();
// /some/root-a.txt
TestResponse response = TestClient.create(routing).path("/some/root-a.txt").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(filterResponse(response), is("- root A TXT"));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE), is(Optional.of(MediaType.TEXT_PLAIN.toString())));
// /some/bar/root-a.txt
response = TestClient.create(routing).path("/some/bar/root-b.txt").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(filterResponse(response), is("- root B TXT"));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE), is(Optional.of(MediaType.TEXT_PLAIN.toString())));
// /some/bar/not.exist
response = TestClient.create(routing).path("/some/bar/not.exist").get();
assertThat(response.status(), is(Http.Status.NOT_FOUND_404));
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class ClassPathContentHandlerTest method serveFromJar.
@Test
public void serveFromJar() throws Exception {
Routing routing = Routing.builder().register("/some", StaticContentSupport.create("s-internal")).build();
// /some/example-a.txt
TestResponse response = TestClient.create(routing).path("/some/example-a.txt").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(filterResponse(response), is("Example A TXT"));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE), is(Optional.of(MediaType.TEXT_PLAIN.toString())));
// /some/example-a.txt
response = TestClient.create(routing).path("/some/a/example-a.txt").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(filterResponse(response), is("A / Example A TXT"));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE), is(Optional.of(MediaType.TEXT_PLAIN.toString())));
// /some/a/not.exist
response = TestClient.create(routing).path("/some/a/not.exist").get();
assertThat(response.status(), is(Http.Status.NOT_FOUND_404));
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class FileSystemContentHandlerTest method serveFile.
@Test
public void serveFile() throws Exception {
try {
Routing routing = Routing.builder().register("/some", StaticContentSupport.create(folder.root().toPath())).build();
// /some/foo.txt
TestResponse response = TestClient.create(routing).path("/some/foo.txt").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(responseToString(response), is("Foo TXT"));
assertThat(response.headers().first(Http.Header.CONTENT_TYPE).orElse(null), is(MediaType.TEXT_PLAIN.toString()));
// /some/css/b.css
response = TestClient.create(routing).path("/some/css/b.css").get();
assertThat(response.status(), is(Http.Status.OK_200));
assertThat(responseToString(response), is("B CSS"));
// /some/css/not.exists
response = TestClient.create(routing).path("/some/css/not.exists").get();
assertThat(response.status(), is(Http.Status.NOT_FOUND_404));
// /some/css
response = TestClient.create(routing).path("/some/css").get();
assertThat(response.status(), is(Http.Status.MOVED_PERMANENTLY_301));
assertThat(response.headers().first(Http.Header.LOCATION).orElse(null), is("/some/css/"));
// /some/css/
response = TestClient.create(routing).path("/some/css/").get();
assertThat(response.status(), is(Http.Status.NOT_FOUND_404));
} catch (Throwable ex) {
ex.printStackTrace();
}
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class TestClientTest method multipleHandlers.
@Test
public void multipleHandlers() throws Exception {
StringBuffer sb = new StringBuffer();
Routing routing = Routing.builder().get("/foo", (req, res) -> {
sb.append("foo-get");
res.send();
}).post("/foo", (req, res) -> {
sb.append("foo-post");
res.send();
}).put("/foo", (req, res) -> {
sb.append("foo-put");
res.send();
}).put("/foo", (req, res) -> {
sb.append("foo-putb");
res.send();
}).get("/foo/bar", (req, res) -> {
sb.append("foo/bar-get");
res.send();
}).build();
TestResponse response = TestClient.create(routing).path("/foo").get();
assertThat(sb.toString(), is("foo-get"));
sb.setLength(0);
response = TestClient.create(routing).path("/foo").post();
assertThat(sb.toString(), is("foo-post"));
sb.setLength(0);
response = TestClient.create(routing).path("/foo").put();
assertThat(sb.toString(), is("foo-put"));
sb.setLength(0);
response = TestClient.create(routing).path("/foo/bar").get();
assertThat(sb.toString(), is("foo/bar-get"));
}
use of io.helidon.webserver.Routing in project helidon by oracle.
the class StaticContentTest method setupRouting.
@BeforeAll
static void setupRouting() {
Routing routing = Routing.builder().register("/classpath", StaticContentSupport.builder("web")).build();
testClient = TestClient.create(routing);
}
Aggregations