@Test public void addOne() throws Exception { CommentReq commentReq = new CommentReq(); commentReq.setArticleID(null); commentReq.setComment(false); commentReq.setContent(UUID.randomUUID().toString()); commentReq.setPid(-1L); commentReq.setResponseId(null); String token = userLogin(); CommentModel PC = null; mockMvc.perform(post("/user/comment/create") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(JSONObject.fromObject(commentReq).toString()) .header("Authorization", token) ).andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class); assertNotEquals(0, model.getId()); assertEquals(commentReq.getPid().longValue(), model.getPid()); assertEquals(-1, model.getPid()); assertEquals(commentReq.getComment(), model.isComment()); assertEquals(commentReq.getContent(), model.getContent()); assertNotNull(model.getDate()); assertNotNull(model.getAuthorName()); assertNotNull(model.getAuthorAvatarImgUrl()); }); Article article = articleMapper.getLastestArticle(); commentReq.setArticleID(article.getId()); commentReq.setComment(true); commentReq.setContent(UUID.randomUUID().toString()); commentReq.setPid(-1L); commentReq.setResponseId(null); mockMvc.perform(post("/user/comment/create") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(JSONObject.fromObject(commentReq).toString()) .header("Authorization", token) ).andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class); assertNotEquals(0, model.getId()); assertEquals(commentReq.getPid().longValue(), model.getPid()); assertEquals(-1, model.getPid()); assertEquals(commentReq.getComment(), model.isComment()); assertEquals(commentReq.getContent(), model.getContent()); assertEquals(commentReq.getArticleID().longValue(), model.getArticleID()); assertNotNull(model.getDate()); assertNotNull(model.getAuthorName()); assertNotNull(model.getAuthorAvatarImgUrl()); }); Comment lastestComment = commentMapper.getLastestComment(); commentReq.setArticleID(lastestComment.getArticleID()); commentReq.setComment(lastestComment.getType()); commentReq.setContent(UUID.randomUUID().toString()); commentReq.setPid(lastestComment.getId()); commentReq.setResponseId(null); mockMvc.perform(post("/user/comment/create") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(JSONObject.fromObject(commentReq).toString()) .header("Authorization", token) ).andDo(MockMvcResultHandlers.print()).andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class); Comment pCommon = commentMapper.findCommentById(lastestComment.getId()); assertEquals(pCommon.getId().longValue(), model.getPid()); String[] ids = pCommon.getResponseId().split(","); boolean contain = false; for (String id : ids) { if (!id.isEmpty() && Long.parseLong(id) == model.getId()) { contain = true; break; } } assertTrue(contain); }); }
@PostMapping("/user/comment/create") public Response addOne(@RequestBody CommentReq reqBody) { return ResponseUtil.success(commentService.create(reqBody)); }
CommentController { @PostMapping("/user/comment/create") public Response addOne(@RequestBody CommentReq reqBody) { return ResponseUtil.success(commentService.create(reqBody)); } }
CommentController { @PostMapping("/user/comment/create") public Response addOne(@RequestBody CommentReq reqBody) { return ResponseUtil.success(commentService.create(reqBody)); }  }
CommentController { @PostMapping("/user/comment/create") public Response addOne(@RequestBody CommentReq reqBody) { return ResponseUtil.success(commentService.create(reqBody)); }  @PostMapping("/user/comment/create") Response addOne(@RequestBody CommentReq reqBody); @DeleteMapping("/user/comment/del") Response delete(@RequestParam("id") long id); @PutMapping("/user/comment/update") Response update(@RequestBody CommentReq reqBody); @GetMapping("/comments") Response commentsOfArticle(@RequestParam("articleId") long articleId,
                                      @RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                      @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/comment/pid/{pid}") Response retrievePage(@PathVariable("pid") long pid,
                                 @RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/leaveMsg") Response retrievePageOfLeaveMsg(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                           @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/admin/comment/type/{type}") Response retrievePageAdmin(
            @PathVariable("type") int isComment,
            @RequestParam(value = "count", required = false, defaultValue = "10") int count,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/user/comment/type/{type}") Response retrievePageByAuthor(
            @PathVariable(value = "type") int isComment,
            @RequestParam(value = "count", required = false, defaultValue = "10") int count,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page); }
CommentController { @PostMapping("/user/comment/create") public Response addOne(@RequestBody CommentReq reqBody) { return ResponseUtil.success(commentService.create(reqBody)); }  @PostMapping("/user/comment/create") Response addOne(@RequestBody CommentReq reqBody); @DeleteMapping("/user/comment/del") Response delete(@RequestParam("id") long id); @PutMapping("/user/comment/update") Response update(@RequestBody CommentReq reqBody); @GetMapping("/comments") Response commentsOfArticle(@RequestParam("articleId") long articleId,
                                      @RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                      @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/comment/pid/{pid}") Response retrievePage(@PathVariable("pid") long pid,
                                 @RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                 @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/leaveMsg") Response retrievePageOfLeaveMsg(@RequestParam(value = "count", required = false, defaultValue = "10") int count,
                                           @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/admin/comment/type/{type}") Response retrievePageAdmin(
            @PathVariable("type") int isComment,
            @RequestParam(value = "count", required = false, defaultValue = "10") int count,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page); @GetMapping("/user/comment/type/{type}") Response retrievePageByAuthor(
            @PathVariable(value = "type") int isComment,
            @RequestParam(value = "count", required = false, defaultValue = "10") int count,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page);  }