weeks of bullshit
This commit is contained in:
@@ -46,7 +46,7 @@ class HttpServerConcurrencyTest {
|
||||
return new Response(200, body, ContentType.TEXT_PLAIN);
|
||||
});
|
||||
|
||||
app.start().get(5, TimeUnit.SECONDS);
|
||||
app.start();
|
||||
|
||||
httpClient = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
@@ -188,7 +188,7 @@ class HttpServerConcurrencyTest {
|
||||
freshApp.get("/route" + idx, (req, res) -> "handler" + idx);
|
||||
}
|
||||
|
||||
freshApp.start().get(5, TimeUnit.SECONDS);
|
||||
freshApp.start();
|
||||
|
||||
int count = 20;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(count);
|
||||
|
||||
@@ -61,7 +61,7 @@ class HttpServerTest {
|
||||
return res.body(body);
|
||||
});
|
||||
|
||||
app.start().get(5, TimeUnit.SECONDS);
|
||||
app.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -148,29 +148,31 @@ class HttpServerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotFound_returns404Html() throws Exception {
|
||||
void testNotFound_returns404() throws Exception {
|
||||
String req = "GET /api/unknown HTTP/1.1\r\nHost: localhost\r\n\r\n";
|
||||
String res = sendRawRequest(req);
|
||||
assertTrue(res.startsWith("HTTP/1.1 404 Not Found"));
|
||||
assertTrue(res.contains("404"));
|
||||
assertTrue(res.contains("No route matched this request"));
|
||||
// Prod default: JSON body — no internal details leaked
|
||||
assertTrue(res.contains("\"status\":404"));
|
||||
assertTrue(res.contains("application/json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testException_returns500Html() throws Exception {
|
||||
void testException_returns500() throws Exception {
|
||||
String req = "GET /api/crash HTTP/1.1\r\nHost: localhost\r\n\r\n";
|
||||
String res = sendRawRequest(req);
|
||||
assertTrue(res.startsWith("HTTP/1.1 500 Internal Server Error"));
|
||||
assertTrue(res.contains("500"));
|
||||
assertTrue(res.contains("Simulated Crash"));
|
||||
// Prod default: generic JSON — stack trace not leaked
|
||||
assertTrue(res.contains("\"status\":500"));
|
||||
assertTrue(res.contains("application/json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRoot_returns404_noExceptionTossed() throws Exception {
|
||||
void testRoot_returns404() throws Exception {
|
||||
String req = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n";
|
||||
String res = sendRawRequest(req);
|
||||
assertTrue(res.startsWith("HTTP/1.1 404 Not Found"));
|
||||
assertTrue(res.contains("No route matched this request."));
|
||||
assertTrue(res.contains("\"status\":404"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,10 +58,23 @@ class ResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBody_withObjectConvertedToString() {
|
||||
void setBody_withString() {
|
||||
Response r = new Response(200, new byte[0], ContentType.TEXT_PLAIN);
|
||||
r.setBody(12345);
|
||||
assertArrayEquals("12345".getBytes(StandardCharsets.UTF_8), r.getBody());
|
||||
r.setBody("hello");
|
||||
assertArrayEquals("hello".getBytes(StandardCharsets.UTF_8), r.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBody_withCharSequence() {
|
||||
Response r = new Response(200, new byte[0], ContentType.TEXT_PLAIN);
|
||||
r.setBody(new StringBuilder("hi"));
|
||||
assertArrayEquals("hi".getBytes(StandardCharsets.UTF_8), r.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setBody_withUnsupportedType_throws() {
|
||||
Response r = new Response(200, new byte[0], ContentType.TEXT_PLAIN);
|
||||
assertThrows(IllegalArgumentException.class, () -> r.setBody(12345));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.relism.routing;
|
||||
|
||||
import dev.relism.http.ContentType;
|
||||
import dev.relism.http.HttpMethod;
|
||||
import dev.relism.models.Request;
|
||||
import dev.relism.models.RequestHandler;
|
||||
@@ -52,7 +51,7 @@ class AbstractRouterTest {
|
||||
void doRegister_classBasedHandler_addsRoute() {
|
||||
DummyRouter router = new DummyRouter();
|
||||
ProfileHandler handler = new ProfileHandler();
|
||||
Route ann = ProfileHandler.class.getAnnotation(Route.class);
|
||||
Route ann = Routes.of(ProfileHandler.class);
|
||||
|
||||
router.doRegister(ann.method(), ann.path(), handler, new Middleware[0]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user