切换到jackson #10

Merged
xiaohai2271 merged 33 commits from feature-trans2jackson into dev 2020-08-15 16:05:40 +08:00
3 changed files with 16 additions and 16 deletions
Showing only changes of commit 03fcddb971 - Show all commits

View File

@@ -14,7 +14,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID; import java.util.List;
import static cn.celess.blog.enmu.ResponseEnum.DATA_IS_DELETED; import static cn.celess.blog.enmu.ResponseEnum.DATA_IS_DELETED;
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS; import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
@@ -36,25 +36,26 @@ public class CommentControllerTest extends BaseTest {
Article article = articleMapper.getLastestArticle(); Article article = articleMapper.getLastestArticle();
CommentReq commentReq = new CommentReq(); CommentReq commentReq = new CommentReq();
commentReq.setPagePath("/article/" + article.getId()); commentReq.setPagePath("/article/" + article.getId());
commentReq.setContent(UUID.randomUUID().toString()); commentReq.setContent(randomStr());
commentReq.setPid(-1L); List<User> all = userMapper.findAll();
commentReq.setToUserId(-1L); commentReq.setPid(1L);
commentReq.setToUserId(2l);
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> { getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE); Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
assertEquals(SUCCESS.getCode(), response.getCode()); assertEquals(SUCCESS.getCode(), response.getCode());
CommentModel model = response.getResult(); CommentModel model = response.getResult();
assertNotEquals(0, model.getId()); assertNotEquals(0, model.getId());
assertEquals(commentReq.getPid(), model.getPid().longValue()); assertEquals(commentReq.getPid(), model.getPid().longValue());
assertEquals(-1, model.getPid().longValue()); assertEquals(1, model.getPid().longValue());
assertEquals(commentReq.getContent(), model.getContent()); assertEquals(commentReq.getContent(), model.getContent());
assertNotNull(model.getDate()); assertNotNull(model.getDate());
assertNotNull(model.getFromUser()); assertNotNull(model.getFromUser());
assertNull(model.getToUser()); assertNotNull(model.getToUser());
}); });
commentReq.setPagePath("/article/" + article.getId()); commentReq.setPagePath("/article/" + article.getId());
commentReq.setContent(UUID.randomUUID().toString()); commentReq.setContent(randomStr());
commentReq.setPid(-1L); commentReq.setPid(-1L);
commentReq.setToUserId(2); commentReq.setToUserId(2);
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> { getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
@@ -75,7 +76,7 @@ public class CommentControllerTest extends BaseTest {
// 测试二级回复 // 测试二级回复
Comment latestComment = commentMapper.getLastestComment(); Comment latestComment = commentMapper.getLastestComment();
commentReq.setPagePath("/article/" + article.getId()); commentReq.setPagePath("/article/" + article.getId());
commentReq.setContent(UUID.randomUUID().toString()); commentReq.setContent(randomStr());
commentReq.setPid(latestComment.getId()); commentReq.setPid(latestComment.getId());
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> { getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE); Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
@@ -120,7 +121,7 @@ public class CommentControllerTest extends BaseTest {
Comment comment = commentMapper.getLastestComment(); Comment comment = commentMapper.getLastestComment();
CommentReq commentReq = new CommentReq(); CommentReq commentReq = new CommentReq();
commentReq.setId(comment.getId()); commentReq.setId(comment.getId());
commentReq.setContent(UUID.randomUUID().toString()); commentReq.setContent(randomStr());
// 不合法数据 setResponseId // 不合法数据 setResponseId
getMockData(put("/user/comment/update"), userLogin(), commentReq).andDo(result -> { getMockData(put("/user/comment/update"), userLogin(), commentReq).andDo(result -> {
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE); Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);

View File

@@ -11,7 +11,6 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List; import java.util.List;
import java.util.UUID;
import static cn.celess.blog.enmu.ResponseEnum.*; import static cn.celess.blog.enmu.ResponseEnum.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@@ -45,7 +44,7 @@ public class LinksControllerTest extends BaseTest {
}); });
// https/http // https/http
linkReq.setName(UUID.randomUUID().toString().substring(0, 4)); linkReq.setName(randomStr(4));
linkReq.setOpen(false); linkReq.setOpen(false);
linkReq.setUrl("example.com"); linkReq.setUrl("example.com");
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> { getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> {
@@ -105,7 +104,7 @@ public class LinksControllerTest extends BaseTest {
LinkReq linkReq = new LinkReq(); LinkReq linkReq = new LinkReq();
linkReq.setUrl(latest.getUrl()); linkReq.setUrl(latest.getUrl());
linkReq.setOpen(!latest.getOpen()); linkReq.setOpen(!latest.getOpen());
linkReq.setName(UUID.randomUUID().toString().substring(0, 4)); linkReq.setName(randomStr(4));
linkReq.setId(latest.getId()); linkReq.setId(latest.getId());
getMockData(put("/admin/links/update"), adminLogin(), linkReq).andDo(result -> { getMockData(put("/admin/links/update"), adminLogin(), linkReq).andDo(result -> {

View File

@@ -68,8 +68,8 @@ public class UserControllerTest extends BaseTest {
@Test @Test
public void updateInfo() throws Exception { public void updateInfo() throws Exception {
String desc = UUID.randomUUID().toString().substring(0, 4); String desc = randomStr(4);
String disPlayName = UUID.randomUUID().toString().substring(0, 4); String disPlayName = randomStr(4);
getMockData(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName), userLogin()).andDo(result -> { getMockData(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName), userLogin()).andDo(result -> {
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE); Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
assertEquals(SUCCESS.getCode(), response.getCode()); assertEquals(SUCCESS.getCode(), response.getCode());
@@ -157,7 +157,7 @@ public class UserControllerTest extends BaseTest {
public void multipleDelete() throws Exception { public void multipleDelete() throws Exception {
List<User> userList = new ArrayList<>(); List<User> userList = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
String s = UUID.randomUUID().toString(); String s = randomStr();
String email = s.substring(s.length() - 4) + "@celess.cn"; String email = s.substring(s.length() - 4) + "@celess.cn";
String pwd = MD5Util.getMD5("123456789"); String pwd = MD5Util.getMD5("123456789");
User user = new User(email, pwd); User user = new User(email, pwd);
@@ -202,7 +202,7 @@ public class UserControllerTest extends BaseTest {
userReq.setEmailStatus(new Random().nextBoolean()); userReq.setEmailStatus(new Random().nextBoolean());
userReq.setRole("admin"); userReq.setRole("admin");
userReq.setDisplayName(randomStr(4)); userReq.setDisplayName(randomStr(4));
userReq.setEmail(randomStr().substring(0, 5) + "@celess.cn"); userReq.setEmail(randomStr(5) + "@celess.cn");
getMockData(put("/admin/user"), adminLogin(), userReq).andDo(result -> { getMockData(put("/admin/user"), adminLogin(), userReq).andDo(result -> {
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE); Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
assertEquals(SUCCESS.getCode(), response.getCode()); assertEquals(SUCCESS.getCode(), response.getCode());