forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1687.java
More file actions
41 lines (34 loc) · 1.15 KB
/
Copy pathIssue1687.java
File metadata and controls
41 lines (34 loc) · 1.15 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
package io.jooby;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import okhttp3.FormBody;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1687 {
@ServerTest
public void shouldUseHiddenMethod(ServerTestRunner runner) {
runner.define(app -> {
app.setHiddenMethod("_method");
app.put("/1687", Context::getMethod);
}).ready(client -> {
client.post("/1687", new FormBody.Builder().add("_method", "put").build(), rsp -> {
assertEquals("PUT", rsp.body().string());
});
// If _method is missing, then 405
client.post("/1687", rsp -> {
assertEquals(StatusCode.METHOD_NOT_ALLOWED.value(), rsp.code());
});
});
}
@ServerTest
public void shouldUseHiddenMethodFromStrategy(ServerTestRunner runner) {
runner.define(app -> {
app.setHiddenMethod(ctx -> ctx.header("X-HTTP-Method-Override").toOptional());
app.put("/1687", Context::getMethod);
}).ready(client -> {
client.header("X-HTTP-Method-Override", "put");
client.post("/1687", rsp -> {
assertEquals("PUT", rsp.body().string());
});
});
}
}