forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2363.java
More file actions
56 lines (48 loc) · 1.77 KB
/
Copy pathIssue2363.java
File metadata and controls
56 lines (48 loc) · 1.77 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
package io.jooby.i2363;
import static okhttp3.RequestBody.create;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import io.jooby.ServerOptions;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
public class Issue2363 {
/**
* Test for https://github.com/jooby-project/jooby/issues/2363.
*
* We just make sure it works as expected but I can't figure it out how to test/assert
* for a 100 response using OKHttpClient.
*
* @param runner Test runner.
*/
@ServerTest
public void shouldAllowExpectAndContinue(ServerTestRunner runner) {
runner.define(app -> {
app.setServerOptions(new ServerOptions().setExpectContinue(true));
app.post("/2363", ctx -> new String(ctx.file("f").bytes(), StandardCharsets.UTF_8));
}).ready(http -> {
http.header("Expect", "100-continue")
.post("/2363", new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("f", "fileupload.js",
create(userdir("src", "test", "resources", "files", "fileupload.js").toFile(),
MediaType.parse("application/javascript")))
.build(), rsp -> {
assertEquals(200, rsp.code());
assertEquals(new String(Files.readAllBytes(userdir("src", "test", "resources", "files", "fileupload.js")), StandardCharsets.UTF_8),
rsp.body().string());
});
});
}
private static Path userdir(String... segments) {
Path path = Paths.get(System.getProperty("user.dir"));
for (String segment : segments) {
path = path.resolve(segment);
}
return path;
}
}