pre-major refactoring + ext api.
This commit is contained in:
@@ -38,11 +38,11 @@ class HttpServerConcurrencyTest {
|
||||
.build();
|
||||
|
||||
server = new HttpServer(config);
|
||||
server.get("/ping", (req, res) -> "pong");
|
||||
server.get("/ping", (req, res) -> "pong").with();
|
||||
server.post("/echo", (req, res) -> {
|
||||
byte[] body = req.body().bytes();
|
||||
return new Response(200, body, ContentType.TEXT_PLAIN);
|
||||
});
|
||||
}).with();
|
||||
|
||||
server.start().get(5, TimeUnit.SECONDS);
|
||||
|
||||
@@ -187,7 +187,7 @@ class HttpServerConcurrencyTest {
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final int idx = i;
|
||||
freshServer.get("/route" + idx, (req, res) -> "handler" + idx);
|
||||
freshServer.get("/route" + idx, (req, res) -> "handler" + idx).with();
|
||||
}
|
||||
|
||||
freshServer.start().get(5, TimeUnit.SECONDS);
|
||||
|
||||
@@ -37,31 +37,31 @@ class HttpServerTest {
|
||||
server = new HttpServer(config);
|
||||
|
||||
// Setup some routes
|
||||
server.get("/api/ping", (req, res) -> "pong");
|
||||
|
||||
server.get("/api/ping", (req, res) -> "pong").with();
|
||||
|
||||
server.post("/api/echo", (req, res) -> {
|
||||
byte[] body = req.body().bytes();
|
||||
return res.status(201).body(body); // echo body & change status
|
||||
});
|
||||
}).with();
|
||||
|
||||
server.get("/api/crash", (req, res) -> {
|
||||
throw new RuntimeException("Simulated Crash");
|
||||
});
|
||||
}).with();
|
||||
|
||||
byte[] streamData = "streaming response body".getBytes(StandardCharsets.UTF_8);
|
||||
server.get("/api/stream", (req, res) ->
|
||||
res.stream(new ByteArrayInputStream(streamData), streamData.length));
|
||||
res.stream(new ByteArrayInputStream(streamData), streamData.length)).with();
|
||||
|
||||
server.get("/api/chunked-out", (req, res) ->
|
||||
res.chunked(new ByteArrayInputStream(streamData)));
|
||||
res.chunked(new ByteArrayInputStream(streamData))).with();
|
||||
|
||||
server.get("/api/custom-header", (req, res) ->
|
||||
res.body("ok").header("X-Flash", "works"));
|
||||
res.body("ok").header("X-Flash", "works")).with();
|
||||
|
||||
server.post("/api/chunked-in", (req, res) -> {
|
||||
byte[] body = req.body().bytes();
|
||||
return res.body(body);
|
||||
});
|
||||
}).with();
|
||||
|
||||
server.start().get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class AbstractRouterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Route(method = "POST", path = "/profile")
|
||||
@Route(method = dev.relism.http.HttpMethod.POST, path = "/profile")
|
||||
static class ProfileHandler extends RequestHandler {
|
||||
@Override
|
||||
public Object handle(Request request, Response response) {
|
||||
@@ -68,18 +68,18 @@ class AbstractRouterTest {
|
||||
DummyRouter router = new DummyRouter();
|
||||
SimpleHandler.FunctionalHandler func = (req, res) -> "OK";
|
||||
|
||||
router.get("users/", func);
|
||||
router.get("users/", func).with();
|
||||
assertEquals(HttpMethod.GET, router.lastAddedMethod);
|
||||
assertEquals("/users", router.lastAddedPath);
|
||||
assertTrue(router.lastAddedHandler instanceof SimpleHandler);
|
||||
|
||||
router.post("/items", func);
|
||||
router.post("/items", func).with();
|
||||
assertEquals(HttpMethod.POST, router.lastAddedMethod);
|
||||
|
||||
router.put("update", func);
|
||||
router.put("update", func).with();
|
||||
assertEquals(HttpMethod.PUT, router.lastAddedMethod);
|
||||
|
||||
router.delete("//delete//", func);
|
||||
router.delete("//delete//", func).with();
|
||||
assertEquals(HttpMethod.DELETE, router.lastAddedMethod);
|
||||
assertEquals("/delete", router.lastAddedPath);
|
||||
}
|
||||
@@ -90,9 +90,9 @@ class AbstractRouterTest {
|
||||
void register_annotatedHandler_addsRoute() {
|
||||
DummyRouter router = new DummyRouter();
|
||||
ProfileHandler handler = new ProfileHandler();
|
||||
|
||||
router.register(handler);
|
||||
|
||||
|
||||
router.register(handler).with();
|
||||
|
||||
assertEquals(HttpMethod.POST, router.lastAddedMethod);
|
||||
assertEquals("/profile", router.lastAddedPath);
|
||||
assertEquals(handler, router.lastAddedHandler);
|
||||
@@ -101,7 +101,7 @@ class AbstractRouterTest {
|
||||
@Test
|
||||
void register_unannotatedHandler_doesNothing() {
|
||||
DummyRouter router = new DummyRouter();
|
||||
router.register(new UnannotatedHandler());
|
||||
router.register(new UnannotatedHandler()).with();
|
||||
assertNull(router.lastAddedMethod); // Nothing added
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class GlobalRouterTest {
|
||||
GlobalRouter global = new GlobalRouter();
|
||||
RequestHandler internalHandler = new SimpleHandler((req, res) -> "internal");
|
||||
|
||||
global.get("/hello", (req, res) -> "internal");
|
||||
global.get("/hello", (req, res) -> "internal").with();
|
||||
// We know it routes to internal. Let's send a request.
|
||||
RequestHandler resolved = global.route(mockRequest("/hello"));
|
||||
assertNotNull(resolved);
|
||||
|
||||
+4
-4
@@ -34,8 +34,8 @@ class FastPathRouterImplTest {
|
||||
void route_lazyCompilationAndMatch() throws Exception {
|
||||
FastPathRouterImpl router = new FastPathRouterImpl();
|
||||
|
||||
router.get("/a", (req, res) -> "A");
|
||||
router.post("/b", (req, res) -> "B");
|
||||
router.get("/a", (req, res) -> "A").with();
|
||||
router.post("/b", (req, res) -> "B").with();
|
||||
|
||||
RequestHandler res1 = router.route(mockRequest(HttpMethod.GET, "/a"));
|
||||
assertNotNull(res1);
|
||||
@@ -49,7 +49,7 @@ class FastPathRouterImplTest {
|
||||
@Test
|
||||
void route_noMatch_returnsNull() {
|
||||
FastPathRouterImpl router = new FastPathRouterImpl();
|
||||
router.get("/a", (req, res) -> "A");
|
||||
router.get("/a", (req, res) -> "A").with();
|
||||
|
||||
assertNull(router.route(mockRequest(HttpMethod.GET, "/b")));
|
||||
// Wrong method
|
||||
@@ -60,7 +60,7 @@ class FastPathRouterImplTest {
|
||||
void route_extractsPathParams() throws Exception {
|
||||
FastPathRouterImpl router = new FastPathRouterImpl();
|
||||
|
||||
router.get("/users/{id}/items/{itemId}", (req, res) -> "Extract");
|
||||
router.get("/users/{id}/items/{itemId}", (req, res) -> "Extract").with();
|
||||
|
||||
Request request = mockRequest(HttpMethod.GET, "/users/123/items/456");
|
||||
RequestHandler handler = router.route(request);
|
||||
|
||||
Reference in New Issue
Block a user