forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1405.java
More file actions
72 lines (61 loc) · 2.11 KB
/
Issue1405.java
File metadata and controls
72 lines (61 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.jooby;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1405 {
@ServerTest
public void issue1405(ServerTestRunner runner) {
runner.define(app -> {
app.path("/recover", () -> {
app.after((ctx, result, failure) -> {
ctx.send(failure.getClass().getSimpleName());
});
app.get("/", ctx -> {
throw new IllegalStateException("some error");
});
});
app.path("/rethrow", () -> {
app.after((ctx, result, failure) -> {
ctx.setResetHeadersOnError(false);
ctx.setResponseHeader("failure", failure.getClass().getSimpleName());
});
app.get("/", ctx -> {
throw new IllegalStateException("some error");
});
});
app.path("/suppressed", () -> {
app.after((ctx, result, failure) -> {
throw new IllegalArgumentException("x");
});
app.get("/", ctx -> {
throw new IllegalStateException("some error");
});
});
app.error((ctx, x, code) -> {
ctx.setResponseCode(code);
String errors = Stream.concat(Stream.of(x), Stream.of(x.getSuppressed()))
.filter(Objects::nonNull)
.map(it -> it.getClass().getSimpleName())
.collect(Collectors.joining("::"));
ctx.send("::" + errors);
});
}).ready(client -> {
client.get("/recover", rsp -> {
assertEquals("IllegalStateException", rsp.body().string());
assertEquals(200, rsp.code());
});
client.get("/rethrow", rsp -> {
assertEquals("::IllegalStateException", rsp.body().string());
assertEquals("IllegalStateException", rsp.header("failure"));
assertEquals(500, rsp.code());
});
client.get("/suppressed", rsp -> {
assertEquals("::IllegalStateException::IllegalArgumentException", rsp.body().string());
assertEquals(500, rsp.code());
});
});
}
}