|
|
@@ -1,27 +1,26 @@
|
|
1
|
1
|
package hello;
|
|
2
|
2
|
|
|
|
3
|
+import static org.hamcrest.Matchers.is;
|
|
|
4
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
|
5
|
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
6
|
+
|
|
3
|
7
|
import org.junit.Before;
|
|
4
|
8
|
import org.junit.Test;
|
|
5
|
9
|
import org.junit.runner.RunWith;
|
|
6
|
10
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
7
|
11
|
import org.springframework.http.MediaType;
|
|
8
|
12
|
import org.springframework.mock.web.MockServletContext;
|
|
9
|
|
-import org.springframework.test.context.ContextConfiguration;
|
|
10
|
13
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
11
|
14
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
12
|
15
|
import org.springframework.test.web.servlet.MockMvc;
|
|
13
|
16
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
14
|
17
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
15
|
18
|
|
|
16
|
|
-import static org.hamcrest.Matchers.is;
|
|
17
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
18
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
19
|
|
-
|
|
20
|
19
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
21
|
|
-@SpringApplicationConfiguration(classes = Application.class)
|
|
22
|
|
-@ContextConfiguration(classes = MockServletContext.class)
|
|
|
20
|
+@SpringApplicationConfiguration(classes = MockServletContext.class)
|
|
23
|
21
|
@WebAppConfiguration
|
|
24
|
22
|
public class HelloControllerTest {
|
|
|
23
|
+
|
|
25
|
24
|
private MockMvc mvc;
|
|
26
|
25
|
|
|
27
|
26
|
@Before
|
|
|
@@ -31,7 +30,7 @@ public class HelloControllerTest {
|
|
31
|
30
|
|
|
32
|
31
|
@Test
|
|
33
|
32
|
public void getHello() throws Exception {
|
|
34
|
|
- mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
|
|
|
33
|
+ mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
|
|
35
|
34
|
.andExpect(status().isOk())
|
|
36
|
35
|
.andExpect(content().string(is("Greetings from Spring Boot!")));
|
|
37
|
36
|
}
|