forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1292.java
More file actions
68 lines (52 loc) · 1.56 KB
/
Copy pathIssue1292.java
File metadata and controls
68 lines (52 loc) · 1.56 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
package io.jooby;
import io.jooby.i1292.Controller1292;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1292 {
public static class SubApp extends Jooby {
{
get("/", ctx -> "subapp");
}
}
@ServerTest
public void shouldSwitchBaseOnDomain(ServerTestRunner runner) {
runner.define(app -> {
app.domain("foo.devd.io", () -> {
app.get("/", ctx -> "foo");
});
app.domain("bar.devd.io", () -> {
app.get("/", ctx -> "bar");
});
app.domain("mvc.devd.io", () -> {
app.mvc(new Controller1292());
});
app.domain("subapp.devd.io", new SubApp());
app.get("/", ctx -> "app");
}).ready(client -> {
client.header("Host", "foo.devd.io");
client.get("/", rsp -> {
assertEquals("foo", rsp.body().string());
});
client.header("Host", "bar.devd.io");
client.get("/", rsp -> {
assertEquals("bar", rsp.body().string());
});
client.header("Host", "mvc.devd.io");
client.get("/", rsp -> {
assertEquals("mvc", rsp.body().string());
});
client.header("Host", "subapp.devd.io");
client.get("/", rsp -> {
assertEquals("subapp", rsp.body().string());
});
client.get("/", rsp -> {
assertEquals("app", rsp.body().string());
});
});
}
private Predicate<Context> domainIs(String host) {
return ctx -> ctx.getHost().equals(host);
}
}