forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteAttributeTest.java
More file actions
60 lines (44 loc) · 1.63 KB
/
Copy pathRouteAttributeTest.java
File metadata and controls
60 lines (44 loc) · 1.63 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
package io.jooby;
import examples.MvcAttributes;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RouteAttributeTest {
@ServerTest
public void canRetrieveRouteAttributesForMvcAPI(ServerTestRunner runner) {
runner.define(app -> {
app.decorator(next -> ctx -> {
String role = (String) ctx.getRoute().attribute("Role");
String level = (String) ctx.getRoute().attribute("Role.level");
if (ctx.getRoute().getPattern().equals("/attr/secured/otherpath")) {
assertEquals("User", role);
assertEquals("one", level);
}
if (ctx.getRoute().getPattern().equals("/attr/secured/subpath")) {
assertEquals("Admin", role);
assertEquals("two", level);
}
return next.apply(ctx);
});
app.mvc(new MvcAttributes());
}).ready(client -> {
client.get("/attr/secured/otherpath", rsp -> assertEquals("OK!", rsp.body().string()));
client.get("/attr/secured/subpath", rsp -> assertEquals("Got it!!", rsp.body().string()));
});
}
@ServerTest
public void canRetrieveRouteAttributesForScriptAPI(ServerTestRunner runner) {
runner.define(app -> {
app.decorator(next -> ctx -> {
String foo = (String) ctx.getRoute().attribute("foo");
assertEquals("bar", foo);
return next.apply(ctx);
});
app.get("/fb", ctx -> "Hello World!").attribute("foo", "bar");
}).ready(client -> {
client.get("/fb", rsp -> {
assertEquals("Hello World!", rsp.body().string());
});
});
}
}