More Related Content Similar to Java web application testing (20) More from Tokuhiro Matsuno (20) Java web application testing83. JettyServletTester.runServlet((req, resp) -> {
resp.getWriter().print("Hey");
}, (uri) -> {
try (CloseableHttpClient client =
HttpClientBuilder.create()
.build()) {
HttpGet request = new HttpGet(uri);
try (CloseableHttpResponse resp =
client.execute(request)) {
String body = EntityUtils.toString(resp.getEntity(),
StandardCharsets.UTF_8);
assertEquals("Hey", body);
}
}
});
91. @Test
public void test() {
mockApi(mock -> {
mock.get(“/api/member/detail“,c -> {
return ImmutableMap.of(“hoge”, “fuga”);
});
},
() -> {
assertEquals(”fuga}”,
injector.get(Client.class).getMember(1)
.getHoge()
);
}
}
106. @Test
public void test() {
val req = new Req(“hoge”, “fuga”);
Res res = mech2.postJSON(“/api/
member/register“, req)
.isOK()
.parseJSON(Res.class);
assertThat(res.getName())
.isEqualTo(“hoge”);
}
107. @Test
public void test() {
http.post(“/api/member/create“)
.param(“name”, “John”)
.isOK()
.contentContains(“hogehoge”);
}