@Test public void likeTest() throws Exception { Principal principal = Mockito.mock(Principal.class); when(principal.getName()).thenReturn("Liam.Johnson@gmail.com"); User user = getUser(); when(userService.findByEmail(anyString())).thenReturn(user); mockMvc.perform(post(tipsAndTricksCommentLink + "/like?id=1") .principal(principal)) .andExpect(status().isOk()); verify(userService).findByEmail(eq("Liam.Johnson@gmail.com")); verify(tipsAndTricksCommentService).like(eq(1L), eq(user)); }
@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") public void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); tipsAndTricksCommentService.like(id, user); }
TipsAndTricksCommentController { @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") public void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); tipsAndTricksCommentService.like(id, user); } }
TipsAndTricksCommentController { @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") public void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); tipsAndTricksCommentService.like(id, user); }  }
TipsAndTricksCommentController { @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") public void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); tipsAndTricksCommentService.like(id, user); }  @ApiOperation(value = "Add comment.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.CREATED, response = AddTipsAndTricksCommentDtoResponse.class), @ApiResponse(code = 303, message = HttpStatuses.SEE_OTHER), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), }) @PostMapping("{tipsAndTricksId}") ResponseEntity<AddTipsAndTricksCommentDtoResponse> save(@PathVariable Long tipsAndTricksId,
                                                                   @Valid @RequestBody
                                                                       AddTipsAndTricksCommentDtoRequest 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<TipsAndTricksCommentDto>> findAll(@ApiIgnore Pageable pageable,
                                                                        Long tipsAndTricksId,
                                                                        @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") int getCountOfComments(Long id); @ApiOperation(value = "Get all replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK) }) @GetMapping("replies/{parentCommentId}") ResponseEntity<List<TipsAndTricksCommentDto>> findAllReplies(@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); @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") int getCountOfReplies(Long parentCommentId); }
TipsAndTricksCommentController { @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") public void like(Long id, @ApiIgnore @AuthenticationPrincipal Principal principal) { User user = userService.findByEmail(principal.getName()); tipsAndTricksCommentService.like(id, user); }  @ApiOperation(value = "Add comment.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.CREATED, response = AddTipsAndTricksCommentDtoResponse.class), @ApiResponse(code = 303, message = HttpStatuses.SEE_OTHER), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED), }) @PostMapping("{tipsAndTricksId}") ResponseEntity<AddTipsAndTricksCommentDtoResponse> save(@PathVariable Long tipsAndTricksId,
                                                                   @Valid @RequestBody
                                                                       AddTipsAndTricksCommentDtoRequest 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<TipsAndTricksCommentDto>> findAll(@ApiIgnore Pageable pageable,
                                                                        Long tipsAndTricksId,
                                                                        @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") int getCountOfComments(Long id); @ApiOperation(value = "Get all replies to comment.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK) }) @GetMapping("replies/{parentCommentId}") ResponseEntity<List<TipsAndTricksCommentDto>> findAllReplies(@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); @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") int getCountOfReplies(Long parentCommentId);  }