TeamControllerTest.java
5.29 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.dituhui.mp.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 TeamControllerTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenQueryTeamSuccess() throws Exception {
String result = mockMvc.perform(
get("/v1/team/get").param("id", "40288ac9764ba85101764baef86f0000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenAddTeamSuccess() throws Exception {
String content = "{\"name\":\"测试团队001\",\"business\":\"001团队\",\"province\":\"四川省\",\"city\":\"成都市\",\"county\":\"高新区\",\"size\":1000,\"address\":\"新川科技园成都超图大厦\",\"expireDate\":\"2020-12-23 00:00:00\"}";
String result = mockMvc.perform(post("/v1/team/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 whenUpdateTeamSuccess() throws Exception {
String content = "{\"id\":\"40288ac9768e57d101768e5808610000\",\"name\":\"测试团队002\",\"business\":\"002团队\",\"province\":\"四川省\",\"city\":\"成都市\",\"county\":\"高新区\",\"size\":1000,\"address\":\"新川科技园成都超图大厦\"}";
String result = mockMvc.perform(post("/v1/team/update").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 whenDeleteTeamSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/team/delete").param("id", "40288ac9768e540101768e5437aa0000")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenAddTeamUserSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/team/addUser").param("id","40288ac9768e57d101768e5808610000")
.param("userId", "9a29b842388148eda91eede9e11dddbb")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenDeleteTeamUserSuccess() throws Exception {
String result = mockMvc.perform(post("/v1/team/deleteUser").param("id","40288ac9768e57d101768e5808610000")
.param("userId", "9a29b842388148eda91eede9e11dddbb")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk())
.andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenGetTeamUserSuccess() throws Exception {
String result = mockMvc.perform(get("/v1/team/getUsers").param("teamId", "40288ac97673e23f017673e26ed90001")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
@Test
public void whenGetTeamRoleSuccess() throws Exception {
String result = mockMvc.perform(get("/v1/team/getRoles").param("teamId", "40288ac97673e23f017673e26ed90001")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()).andExpect(jsonPath("$.success").value(true))
.andReturn().getResponse().getContentAsString();
System.out.println(result);
}
}