@Test void update() throws Exception { User user = getUser(); when(userService.findByEmail(anyString())).thenReturn(user); mockMvc.perform(patch(ecoNewsCommentControllerLink + "?id=1&text=text") .principal(principal)) .andExpect(status().isOk()); verify(userService).findByEmail(eq("test@gmail.com")); verify(ecoNewsCommentService).update(eq("text"), eq(1L), eq(user)); }
@ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") public void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); ecoNewsCommentService.update(text, id, user); }
EcoNewsCommentController { @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") public void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); ecoNewsCommentService.update(text, id, user); } }
EcoNewsCommentController { @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") public void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); ecoNewsCommentService.update(text, id, user); }  }
EcoNewsCommentController { @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") public void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); ecoNewsCommentService.update(text, id, user); }  @ApiOperation(value = "Add comment.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.CREATED, response = AddEcoNewsCommentDtoResponse.class), @ApiResponse(code = 303, message = HttpStatuses.SEE_OTHER), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), }) @PostMapping("{econewsId}") ResponseEntity<AddEcoNewsCommentDtoResponse> save(@PathVariable Long econewsId,
                                                             @Valid @RequestBody AddEcoNewsCommentDtoRequest request,
                                                             @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Get all comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> findAll(@ApiIgnore Pageable pageable,
                                                                  Long ecoNewsId,
                                                                  @ApiIgnore @AuthenticationPrincipal
                                                                      Principal principal); @ApiOperation(value = "Count comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/count/comments/{ecoNewsId}") int getCountOfComments(@PathVariable Long ecoNewsId); @ApiOperation(value = "Get all replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK) }) @GetMapping("replies/{parentCommentId}") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> findAllReplies(@ApiIgnore Pageable pageable,
                                                                         @PathVariable Long parentCommentId,
                                                                         @ApiIgnore @AuthenticationPrincipal
                                                                             Principal principal); @ApiOperation(value = "Get count of replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("count/replies/{parentCommentId}") int getCountOfReplies(@PathVariable Long parentCommentId); @ApiOperation(value = "Mark comment as deleted.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @DeleteMapping("") ResponseEntity<Object> delete(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Like comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PostMapping("like") void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Count comment likes.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/count/likes") int getCountOfLikes(Long id); @MessageMapping("/likeAndCount") @SendTo("/topic/comment") AmountCommentLikesDto getCountOfLike(Long id); @ApiOperation(value = "Get all active comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/active") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> getAllActiveComments(@ApiIgnore Pageable pageable,
                                                                               Long ecoNewsId,
                                                                               @ApiIgnore @AuthenticationPrincipal
                                                                                   Principal principal); }
EcoNewsCommentController { @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") public void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); ecoNewsCommentService.update(text, id, user); }  @ApiOperation(value = "Add comment.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.CREATED, response = AddEcoNewsCommentDtoResponse.class), @ApiResponse(code = 303, message = HttpStatuses.SEE_OTHER), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), }) @PostMapping("{econewsId}") ResponseEntity<AddEcoNewsCommentDtoResponse> save(@PathVariable Long econewsId,
                                                             @Valid @RequestBody AddEcoNewsCommentDtoRequest request,
                                                             @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Get all comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> findAll(@ApiIgnore Pageable pageable,
                                                                  Long ecoNewsId,
                                                                  @ApiIgnore @AuthenticationPrincipal
                                                                      Principal principal); @ApiOperation(value = "Count comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/count/comments/{ecoNewsId}") int getCountOfComments(@PathVariable Long ecoNewsId); @ApiOperation(value = "Get all replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK) }) @GetMapping("replies/{parentCommentId}") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> findAllReplies(@ApiIgnore Pageable pageable,
                                                                         @PathVariable Long parentCommentId,
                                                                         @ApiIgnore @AuthenticationPrincipal
                                                                             Principal principal); @ApiOperation(value = "Get count of replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("count/replies/{parentCommentId}") int getCountOfReplies(@PathVariable Long parentCommentId); @ApiOperation(value = "Mark comment as deleted.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @DeleteMapping("") ResponseEntity<Object> delete(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Update comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PatchMapping("") void update(Long id, String text, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Like comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED) }) @PostMapping("like") void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal); @ApiOperation(value = "Count comment likes.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/count/likes") int getCountOfLikes(Long id); @MessageMapping("/likeAndCount") @SendTo("/topic/comment") AmountCommentLikesDto getCountOfLike(Long id); @ApiOperation(value = "Get all active comments.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST) }) @GetMapping("/active") @ApiPageable ResponseEntity<PageableDto<EcoNewsCommentDto>> getAllActiveComments(@ApiIgnore Pageable pageable,
                                                                               Long ecoNewsId,
                                                                               @ApiIgnore @AuthenticationPrincipal
                                                                                   Principal principal);  }