-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationTest.java
More file actions
94 lines (79 loc) · 3.15 KB
/
ApplicationTest.java
File metadata and controls
94 lines (79 loc) · 3.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import models.Bar;
import org.junit.Test;
import play.data.Form;
import play.libs.ws.WS;
import play.mvc.Result;
import play.test.FakeRequest;
import play.twirl.api.Html;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.fest.assertions.Assertions.assertThat;
import static play.test.Helpers.*;
// todo: not using the right spring context when using fakeApplication()
public class ApplicationTest {
@Test
public void indexTemplate() {
running(fakeApplication(), new Runnable() {
public void run() {
Form<Bar> form = Form.form(Bar.class);
Html html = views.html.index.render(form);
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Welcome");
}
});
}
@Test
public void callIndex() {
Result result = callAction(controllers.routes.ref.Application.index());
assertThat(status(result)).isEqualTo(OK);
assertThat(contentType(result)).isEqualTo("text/html");
assertThat(charset(result)).isEqualTo("utf-8");
assertThat(contentAsString(result)).contains("Welcome");
}
@Test
public void callAddBar() {
running(fakeApplication(), new Runnable() {
public void run() {
Map<String, String> formParams = new HashMap<String, String>();
formParams.put("name", "foo");
FakeRequest fakeRequest = fakeRequest().withFormUrlEncodedBody(formParams);
Result result = callAction(controllers.routes.ref.Application.addBar(), fakeRequest);
assertThat(status(result)).isEqualTo(SEE_OTHER);
}
});
}
@Test
public void callListBars() {
running(fakeApplication(), new Runnable() {
public void run() {
Map<String, String> formParams = new HashMap<String, String>();
formParams.put("name", "foo");
FakeRequest fakeRequest = fakeRequest().withFormUrlEncodedBody(formParams);
callAction(controllers.routes.ref.Application.addBar(), fakeRequest);
Result result = callAction(controllers.routes.ref.Application.listBars());
assertThat(status(result)).isEqualTo(OK);
assertThat(contentType(result)).isEqualTo("application/json");
assertThat(contentAsString(result)).startsWith("[");
assertThat(contentAsString(result)).contains("foo");
}
});
}
@Test
public void barsRoute() {
running(fakeApplication(), new Runnable() {
public void run() {
Result result = route(fakeRequest(GET, "/bars"));
assertThat(result).isNotNull();
}
});
}
@Test
public void realBarsRequest() {
running(testServer(3333), new Runnable() {
public void run() {
assertThat(WS.url("http://localhost:3333/bars").get().get(5, TimeUnit.SECONDS).getStatus()).isEqualTo(OK);
}
});
}
}