forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue2293.java
More file actions
55 lines (47 loc) · 1.51 KB
/
Copy pathIssue2293.java
File metadata and controls
55 lines (47 loc) · 1.51 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
package io.jooby.i2293;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import io.jooby.SneakyThrows;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import reactor.core.publisher.Mono;
public class Issue2293 {
@ServerTest
public void shouldSendLargeResponseAsNonBlocking(ServerTestRunner runner) {
String resource = "i2293.json";
runner.define(app -> {
app.get("/2293", ctx ->
Mono.fromCallable(() -> resource)
.map(this::readJsonAsString)
);
}).ready(http -> {
http.get("/2293", rsp -> {
assertEquals(readJsonAsString(resource), rsp.body().string());
});
});
}
public String readJsonAsString(String resourcePath) {
try {
String result = null;
InputStream is = Issue2293.class.getResourceAsStream(resourcePath);
if (is != null) {
result = IOUtils.toString(is, StandardCharsets.UTF_8);
} else {
URL resourceUrl = this.getClass().getClassLoader().getResource(resourcePath);
if (resourceUrl != null) {
File file = new File(resourceUrl.getFile());
result = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
}
}
return result;
} catch (IOException ex) {
throw SneakyThrows.propagate(ex);
}
}
}