forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1937.java
More file actions
57 lines (48 loc) · 1.81 KB
/
Copy pathIssue1937.java
File metadata and controls
57 lines (48 loc) · 1.81 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
package io.jooby.i1937;
import io.jooby.Context;
import io.jooby.di.GuiceModule;
import io.jooby.exception.RegistryException;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Issue1937 {
@ServerTest
public void shouldFailIfContextAsServiceWasNotCalled(ServerTestRunner runner) {
runner.define(app -> app.get("/i1937", ctx -> {
app.require(Context.class);
return "OK";
})).ready(http -> http.get("/i1937", rsp -> assertEquals(500, rsp.code())));
}
@ServerTest
public void shouldWorkIfContextAsServiceWasCalled(ServerTestRunner runner) {
runner.define(app -> {
app.get("/i1937", ctx -> {
app.require(Context.class);
return "OK";
});
app.setContextAsService(true);
}).ready(http -> http.get("/i1937", rsp -> assertEquals(200, rsp.code())));
}
@ServerTest
public void shouldThrowIfOutOfScope(ServerTestRunner runner) {
runner.define(app -> {
app.setContextAsService(true);
app.onStarted(() -> {
Throwable t = assertThrows(RegistryException.class, () -> app.require(Context.class));
assertEquals(t.getMessage(), "Context is not available. Are you getting it from request scope?");
});
}).ready(http -> {});
}
@ServerTest
public void shouldThrowIfOutOfScopeWithDI(ServerTestRunner runner) {
runner.define(app -> {
app.install(new GuiceModule());
app.setContextAsService(true);
app.onStarted(() -> {
Throwable t = assertThrows(RegistryException.class, () -> app.require(Context.class));
assertEquals(t.getMessage(), "Context is not available. Are you getting it from request scope?");
});
}).ready(http -> {});
}
}