forked from suyeq/MBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexControllerTest.java
More file actions
53 lines (43 loc) · 1.64 KB
/
Copy pathIndexControllerTest.java
File metadata and controls
53 lines (43 loc) · 1.64 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
package com.cyc.controller;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.springframework.http.MediaType;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebAppConfiguration
public class IndexControllerTest
{
@InjectMocks
private IndexController indexController;
private MockMvc mockMvc;
// @Autowired
// protected WebApplicationContext webApplicationContext;
@Before
public void setup()
{
// initialize mock object
MockitoAnnotations.initMocks(this);
// Setup Spring test in standalone mode
this.mockMvc = MockMvcBuilders.standaloneSetup(indexController).build();
// MockMvcBuilders.webAppContextSetup().build();
}
@Test
public void showIndex() throws Exception
{
String responseString = mockMvc.perform(get("/index.html")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("pcode", "root"))
.andExpect(status().isOk())
.andDo(print())
.andReturn()
.getResponse()
.getContentAsString();
System.out.println("--------返回的json = " + responseString);
}
}