RoleControllerTest.java
4.51 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
95
96
97
98
99
100
101
102
103
package com.dituhui.pea.user;
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.context.SpringBootTest;
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.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RoleControllerTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenAddRoleSuccess() throws Exception {
String content = "{\"name\":\"角色1\",\"teamId\":\"40288ac9768e57d101768e5808610000\",\"extra\":\"1\"}";
String result = mockMvc.perform(post("/v1/role/add").contentType(MediaType.APPLICATION_JSON_UTF8).content(content))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenDeleteRoleSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/role/delete").param("id", "40288ac97697e591017697e5be060000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenAddRoleUserSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/role/addUser")
.param("id", "40288ac97697eca5017697ecd1010000").param("userId", "40288ac97673e23f017673e26e3c0000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenDeleteUserRoleSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/role/deleteUser")
.param("id", "40288ac97697eca5017697ecd1010000").param("userId", "40288ac97673e23f017673e26e3c0000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenAddResourceSuccess() throws Exception {
String content = "{\"name\":\"资源一\",\"teamId\":\"40288ac9768e57d101768e5808610000\",\"extra\":\"1\"}";
String result = mockMvc.perform(post("/v1/resource/add").contentType(MediaType.APPLICATION_JSON_UTF8).content(content))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenDeleteResourceSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/resource/delete").param("id","40288ac97698777801769877a5220000").contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenAddRoleResourceSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/role/addResource")
.param("id","40288ac97697eca5017697ecd1010000")
.param("resource_id","40288ac97698799901769879c6b90000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
}