Skip to content

Commit 04ba8b9

Browse files
gadfly3173colorful3
authored andcommitted
fix #223 & test去除deprecated api等问题修复
1 parent aea6b3b commit 04ba8b9

File tree

10 files changed

+102
-104
lines changed

10 files changed

+102
-104
lines changed

src/main/java/io/github/talelin/latticy/vo/DeletedVO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ public class DeletedVO extends UnifyResponseVO<String> {
1111

1212
public DeletedVO() {
1313
super(Code.DELETED.getCode());
14-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
14+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
1515
}
1616

1717
public DeletedVO(int code) {
1818
super(code);
19-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
19+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
2020
}
2121

2222
public DeletedVO(String message) {
2323
super(message);
24-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
24+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
2525
}
2626

2727
public DeletedVO(int code, String message) {
2828
super(code, message);
29-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
29+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
3030
}
3131

3232
@Override

src/main/java/io/github/talelin/latticy/vo/UpdatedVO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ public class UpdatedVO extends UnifyResponseVO<String> {
1111

1212
public UpdatedVO() {
1313
super(Code.UPDATED.getCode());
14-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
14+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
1515
}
1616

1717
public UpdatedVO(int code) {
1818
super(code);
19-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
19+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
2020
}
2121

2222
public UpdatedVO(String message) {
2323
super(message);
24-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
24+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
2525
}
2626

2727
public UpdatedVO(int code, String message) {
2828
super(code, message);
29-
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.CREATED.value());
29+
ResponseUtil.setCurrentResponseHttpStatus(HttpStatus.OK.value());
3030
}
3131

3232
@Override

src/test/java/io/github/talelin/latticy/controller/cms/AdminControllerTest.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.talelin.latticy.controller.cms;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
4+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
55
import io.github.talelin.latticy.dto.admin.*;
66
import io.github.talelin.latticy.mapper.*;
77
import io.github.talelin.latticy.model.*;
@@ -19,6 +19,7 @@
1919
import org.springframework.transaction.annotation.Transactional;
2020

2121
import java.util.Arrays;
22+
import java.util.Collections;
2223

2324
import static org.junit.jupiter.api.Assertions.*;
2425
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
@@ -130,13 +131,13 @@ public void changeUserPassword() throws Exception {
130131
dto.setConfirmPassword(newPassword);
131132

132133
ObjectMapper mapper = new ObjectMapper();
133-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
134+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
134135
String content = mapper.writeValueAsString(dto);
135136

136137
mvc.perform(put(String.format("/cms/admin/user/%s/password", user.getId()))
137138
.contentType(MediaType.APPLICATION_JSON).content(content))
138139
.andDo(print())
139-
.andExpect(status().isCreated())
140+
.andExpect(status().isOk())
140141
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("密码修改成功"));
141142

142143
boolean b = userIdentityService.verifyUsernamePassword(user.getId(), username, newPassword);
@@ -162,7 +163,7 @@ public void deleteUser() throws Exception {
162163
mvc.perform(delete("/cms/admin/user/" + user.getId())
163164
.contentType(MediaType.APPLICATION_JSON))
164165
.andDo(print())
165-
.andExpect(status().isCreated())
166+
.andExpect(status().isOk())
166167
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("删除用户成功"));
167168

168169
UserDO hit = userMapper.selectById(user.getId());
@@ -184,16 +185,16 @@ public void updateUser() throws Exception {
184185
groupMapper.insert(group);
185186

186187
UpdateUserInfoDTO dto = new UpdateUserInfoDTO();
187-
dto.setGroupIds(Arrays.asList(group.getId()));
188+
dto.setGroupIds(Collections.singletonList(group.getId()));
188189

189190
ObjectMapper mapper = new ObjectMapper();
190-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
191+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
191192
String content = mapper.writeValueAsString(dto);
192193

193194
mvc.perform(put("/cms/admin/user/" + user.getId())
194195
.contentType(MediaType.APPLICATION_JSON).content(content))
195196
.andDo(print())
196-
.andExpect(status().isCreated())
197+
.andExpect(status().isOk())
197198
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("更新用户成功"));
198199
}
199200

@@ -275,10 +276,10 @@ public void createGroup() throws Exception {
275276
PermissionDO permission = PermissionDO.builder().name(permissionName).module(module).build();
276277
permissionMapper.insert(permission);
277278

278-
dto.setPermissionIds(Arrays.asList(permission.getId()));
279+
dto.setPermissionIds(Collections.singletonList(permission.getId()));
279280

280281
ObjectMapper mapper = new ObjectMapper();
281-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
282+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
282283
String content = mapper.writeValueAsString(dto);
283284

284285
mvc.perform(post("/cms/admin/group/")
@@ -308,13 +309,13 @@ public void updateGroup() throws Exception {
308309
dto.setInfo("flink is a finger");
309310

310311
ObjectMapper mapper = new ObjectMapper();
311-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
312+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
312313
String content = mapper.writeValueAsString(dto);
313314

314315
mvc.perform(put("/cms/admin/group/" + group.getId())
315316
.contentType(MediaType.APPLICATION_JSON).content(content))
316317
.andDo(print())
317-
.andExpect(status().isCreated())
318+
.andExpect(status().isOk())
318319
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("更新分组成功"));
319320

320321
GroupDO hit = groupMapper.selectById(group.getId());
@@ -335,7 +336,7 @@ public void deleteGroup() throws Exception {
335336
mvc.perform(delete("/cms/admin/group/" + group.getId())
336337
.contentType(MediaType.APPLICATION_JSON))
337338
.andDo(print())
338-
.andExpect(status().isCreated())
339+
.andExpect(status().isOk())
339340
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("删除分组成功"));
340341
GroupDO hit = groupMapper.selectById(group.getId());
341342
assertNull(hit);
@@ -359,7 +360,7 @@ public void dispatchPermission() throws Exception {
359360
dto.setPermissionId(permission.getId());
360361

361362
ObjectMapper mapper = new ObjectMapper();
362-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
363+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
363364
String content = mapper.writeValueAsString(dto);
364365

365366
mvc.perform(post("/cms/admin/permission/dispatch")
@@ -389,7 +390,7 @@ public void dispatchPermissions() throws Exception {
389390
dto.setPermissionIds(Arrays.asList(permission.getId(), permission1.getId()));
390391

391392
ObjectMapper mapper = new ObjectMapper();
392-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
393+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
393394
String content = mapper.writeValueAsString(dto);
394395

395396
mvc.perform(post("/cms/admin/permission/dispatch/batch")
@@ -419,16 +420,16 @@ public void removePermissions() throws Exception {
419420

420421
RemovePermissionsDTO dto = new RemovePermissionsDTO();
421422
dto.setGroupId(group.getId());
422-
dto.setPermissionIds(Arrays.asList(permission1.getId()));
423+
dto.setPermissionIds(Collections.singletonList(permission1.getId()));
423424

424425
ObjectMapper mapper = new ObjectMapper();
425-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
426+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
426427
String content = mapper.writeValueAsString(dto);
427428

428429
mvc.perform(post("/cms/admin/permission/remove")
429430
.contentType(MediaType.APPLICATION_JSON).content(content))
430431
.andDo(print())
431-
.andExpect(status().isCreated())
432+
.andExpect(status().isOk())
432433
.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("删除权限成功"));
433434
}
434435
}

src/test/java/io/github/talelin/latticy/controller/cms/UserControllerTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.talelin.latticy.controller.cms;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4-
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
4+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
55
import io.github.talelin.latticy.common.LocalUser;
66
import io.github.talelin.latticy.dto.user.ChangePasswordDTO;
77
import io.github.talelin.latticy.dto.user.LoginDTO;
@@ -25,9 +25,10 @@
2525
import org.springframework.transaction.annotation.Transactional;
2626

2727
import java.util.Arrays;
28+
import java.util.Collections;
2829
import java.util.Random;
2930

30-
import static org.junit.jupiter.api.Assertions.assertTrue;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
3132
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
3233
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
3334
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -49,26 +50,26 @@ public class UserControllerTest {
4950
@Autowired
5051
private UserService userService;
5152

52-
private String email = "[email protected]";
53+
private final String email = "[email protected]";
5354

54-
private String password = "123456";
55+
private final String password = "123456";
5556

56-
private String username = "pedro大大";
57+
private final String username = "pedro大大";
5758

5859
@Test
5960
public void register() throws Exception {
6061
GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build();
6162
groupMapper.insert(group);
6263

6364
RegisterDTO dto = new RegisterDTO();
64-
dto.setGroupIds(Arrays.asList(group.getId()));
65+
dto.setGroupIds(Collections.singletonList(group.getId()));
6566
dto.setEmail(email);
6667
dto.setConfirmPassword(password);
6768
dto.setPassword(password);
6869
dto.setUsername(username);
6970

7071
ObjectMapper mapper = new ObjectMapper();
71-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
72+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
7273
String content = mapper.writeValueAsString(dto);
7374

7475
mvc.perform(post("/cms/user/register")
@@ -93,7 +94,7 @@ public void register1() throws Exception {
9394
dto.setUsername(username);
9495

9596
ObjectMapper mapper = new ObjectMapper();
96-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
97+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
9798
String content = mapper.writeValueAsString(dto);
9899

99100
mvc.perform(post("/cms/user/register")
@@ -120,7 +121,7 @@ public void login() throws Exception {
120121
dto1.setPassword(password);
121122

122123
ObjectMapper mapper = new ObjectMapper();
123-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
124+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
124125
String content = mapper.writeValueAsString(dto1);
125126

126127
mvc.perform(post("/cms/user/login")
@@ -138,7 +139,7 @@ public void update() throws Exception {
138139
groupMapper.insert(root);
139140
groupMapper.insert(group);
140141
RegisterDTO dto = new RegisterDTO();
141-
dto.setGroupIds(Arrays.asList(group.getId()));
142+
dto.setGroupIds(Collections.singletonList(group.getId()));
142143
dto.setEmail(email);
143144
dto.setConfirmPassword(password);
144145
dto.setPassword(password);
@@ -153,27 +154,27 @@ public void update() throws Exception {
153154
dto1.setUsername("pedro小小");
154155

155156
ObjectMapper mapper = new ObjectMapper();
156-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
157+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
157158
String content = mapper.writeValueAsString(dto1);
158159

159160

160161
mvc.perform(MockMvcRequestBuilders.put("/cms/user/")
161162
.contentType(MediaType.APPLICATION_JSON).content(content))
162163
.andDo(print())
163-
.andExpect(status().isCreated())
164+
.andExpect(status().isOk())
164165
.andExpect(MockMvcResultMatchers.
165166
jsonPath("$.message").value("更新用户成功"));
166167

167168
UserDO user1 = userService.getUserByUsername("pedro小小");
168-
assertTrue(user1.getEmail().equals("[email protected]"));
169+
assertEquals("[email protected]", user1.getEmail());
169170
}
170171

171172
@Test
172173
public void updatePassword() throws Exception {
173174
GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build();
174175
groupMapper.insert(group);
175176
RegisterDTO dto = new RegisterDTO();
176-
dto.setGroupIds(Arrays.asList(group.getId()));
177+
dto.setGroupIds(Collections.singletonList(group.getId()));
177178
dto.setEmail(email);
178179
dto.setConfirmPassword(password);
179180
dto.setPassword(password);
@@ -189,14 +190,14 @@ public void updatePassword() throws Exception {
189190
dto1.setConfirmPassword("147258");
190191

191192
ObjectMapper mapper = new ObjectMapper();
192-
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
193+
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
193194
String content = mapper.writeValueAsString(dto1);
194195

195196

196197
mvc.perform(MockMvcRequestBuilders.put("/cms/user/change_password")
197198
.contentType(MediaType.APPLICATION_JSON).content(content))
198199
.andDo(print())
199-
.andExpect(status().isCreated())
200+
.andExpect(status().isOk())
200201
.andExpect(MockMvcResultMatchers.
201202
jsonPath("$.message").value("密码修改成功"));
202203
}
@@ -206,7 +207,7 @@ public void refreshToken() throws Exception {
206207
GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build();
207208
groupMapper.insert(group);
208209
RegisterDTO dto = new RegisterDTO();
209-
dto.setGroupIds(Arrays.asList(group.getId()));
210+
dto.setGroupIds(Collections.singletonList(group.getId()));
210211
dto.setEmail(email);
211212
dto.setConfirmPassword(password);
212213
dto.setPassword(password);
@@ -229,7 +230,7 @@ public void getPermissions() throws Exception {
229230
GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build();
230231
groupMapper.insert(group);
231232
RegisterDTO dto = new RegisterDTO();
232-
dto.setGroupIds(Arrays.asList(group.getId()));
233+
dto.setGroupIds(Collections.singletonList(group.getId()));
233234
dto.setEmail(email);
234235
dto.setConfirmPassword(password);
235236
dto.setPassword(password);
@@ -253,7 +254,7 @@ public void getInformation() throws Exception {
253254
groupMapper.insert(root);
254255
groupMapper.insert(group);
255256
RegisterDTO dto = new RegisterDTO();
256-
dto.setGroupIds(Arrays.asList(group.getId()));
257+
dto.setGroupIds(Collections.singletonList(group.getId()));
257258
dto.setEmail(email);
258259
dto.setConfirmPassword(password);
259260
dto.setPassword(password);

0 commit comments

Comments
 (0)