-
Notifications
You must be signed in to change notification settings - Fork 24
/
ShowControllerStandaloneTest.java
50 lines (42 loc) 路 1.72 KB
/
ShowControllerStandaloneTest.java
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
package com.liuwill.demo.kotlinboot.test.integration;
/**
* Created by liuwill<liuwill@live.com> on 2017/3/17.
*/
import com.liuwill.demo.kotlinboot.controllers.ShowController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@WebMvcTest(ShowController.class)
public class ShowControllerStandaloneTest {
private WebApplicationContext wac;
@Autowired
private MockMvc mvc;
@Before
public void setUp() throws Exception {
//mvc = MockMvcBuilders.standaloneSetup(new DataController()).build();
}
@Test
public void getData() throws Exception {
String expectStr = "{\"msg\":\"hello\"}";
mvc.perform(
MockMvcRequestBuilders.put("/v1/api/data")
.contentType(MediaType.APPLICATION_JSON)
.content(expectStr)
.accept(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(content().json(expectStr))
.andDo(print());
}
}