1 | import org.junit.*; |
---|
2 | |
---|
3 | import java.util.*; |
---|
4 | |
---|
5 | import play.mvc.*; |
---|
6 | import play.test.*; |
---|
7 | import play.libs.F.*; |
---|
8 | |
---|
9 | import static play.test.Helpers.*; |
---|
10 | import static org.fest.assertions.Assertions.*; |
---|
11 | |
---|
12 | public class FunctionalTest { |
---|
13 | |
---|
14 | @Test |
---|
15 | public void redirectHomePage() { |
---|
16 | running(fakeApplication(), new Runnable() { |
---|
17 | public void run() { |
---|
18 | Result result = callAction(controllers.routes.ref.Application.index()); |
---|
19 | |
---|
20 | assertThat(status(result)).isEqualTo(SEE_OTHER); |
---|
21 | assertThat(redirectLocation(result)).isEqualTo("/computers"); |
---|
22 | } |
---|
23 | }); |
---|
24 | } |
---|
25 | |
---|
26 | @Test |
---|
27 | public void listComputersOnTheFirstPage() { |
---|
28 | running(fakeApplication(), new Runnable() { |
---|
29 | public void run() { |
---|
30 | Result result = callAction(controllers.routes.ref.Application.list(0, "name", "asc", "")); |
---|
31 | |
---|
32 | assertThat(status(result)).isEqualTo(OK); |
---|
33 | assertThat(contentAsString(result)).contains("574 computers found"); |
---|
34 | } |
---|
35 | }); |
---|
36 | } |
---|
37 | |
---|
38 | @Test |
---|
39 | public void filterComputerByName() { |
---|
40 | running(fakeApplication(), new Runnable() { |
---|
41 | public void run() { |
---|
42 | Result result = callAction(controllers.routes.ref.Application.list(0, "name", "asc", "Apple")); |
---|
43 | |
---|
44 | assertThat(status(result)).isEqualTo(OK); |
---|
45 | assertThat(contentAsString(result)).contains("13 computers found"); |
---|
46 | } |
---|
47 | }); |
---|
48 | } |
---|
49 | |
---|
50 | @Test |
---|
51 | public void createANewComputer() { |
---|
52 | running(fakeApplication(), new Runnable() { |
---|
53 | public void run() { |
---|
54 | Result result = callAction(controllers.routes.ref.Application.save()); |
---|
55 | |
---|
56 | assertThat(status(result)).isEqualTo(BAD_REQUEST); |
---|
57 | |
---|
58 | Map<String,String> data = new HashMap<String,String>(); |
---|
59 | data.put("name", "FooBar"); |
---|
60 | data.put("introduced", "badbadbad"); |
---|
61 | data.put("company.id", "1"); |
---|
62 | |
---|
63 | result = callAction( |
---|
64 | controllers.routes.ref.Application.save(), |
---|
65 | fakeRequest().withFormUrlEncodedBody(data) |
---|
66 | ); |
---|
67 | |
---|
68 | assertThat(status(result)).isEqualTo(BAD_REQUEST); |
---|
69 | assertThat(contentAsString(result)).contains("<option value=\"1\" selected>Apple Inc.</option>"); |
---|
70 | assertThat(contentAsString(result)).contains("<input type=\"text\" id=\"introduced\" name=\"introduced\" value=\"badbadbad\" >"); |
---|
71 | assertThat(contentAsString(result)).contains("<input type=\"text\" id=\"name\" name=\"name\" value=\"FooBar\" >"); |
---|
72 | |
---|
73 | data.put("introduced", "2011-12-24"); |
---|
74 | |
---|
75 | result = callAction( |
---|
76 | controllers.routes.ref.Application.save(), |
---|
77 | fakeRequest().withFormUrlEncodedBody(data) |
---|
78 | ); |
---|
79 | |
---|
80 | assertThat(status(result)).isEqualTo(SEE_OTHER); |
---|
81 | assertThat(redirectLocation(result)).isEqualTo("/computers"); |
---|
82 | assertThat(flash(result).get("success")).isEqualTo("Computer FooBar has been created"); |
---|
83 | |
---|
84 | result = callAction(controllers.routes.ref.Application.list(0, "name", "asc", "FooBar")); |
---|
85 | assertThat(status(result)).isEqualTo(OK); |
---|
86 | assertThat(contentAsString(result)).contains("One computer found"); |
---|
87 | |
---|
88 | } |
---|
89 | }); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|