@Test void saveResponseOk() throws Exception { when(newsSubscriberService.save(any(NewsSubscriberRequestDto.class))) .thenReturn(ModelUtils.getNewsSubscriberRequestDto()); mockMvc.perform(post(newsSubscriberControllerLink) .content("{\n" + " \"email\": \"test@gmail.com\"\n" + "}") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); verify(newsSubscriberService).save(eq(ModelUtils.getNewsSubscriberRequestDto())); }
@ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") public ResponseEntity<NewsSubscriberRequestDto> save( @RequestBody @Valid NewsSubscriberRequestDto dto) { return ResponseEntity.status(HttpStatus.OK) .body(newsSubscriberService.save(dto)); }
NewsSubscriberController { @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") public ResponseEntity<NewsSubscriberRequestDto> save( @RequestBody @Valid NewsSubscriberRequestDto dto) { return ResponseEntity.status(HttpStatus.OK) .body(newsSubscriberService.save(dto)); } }
NewsSubscriberController { @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") public ResponseEntity<NewsSubscriberRequestDto> save( @RequestBody @Valid NewsSubscriberRequestDto dto) { return ResponseEntity.status(HttpStatus.OK) .body(newsSubscriberService.save(dto)); } @Autowired  NewsSubscriberController(NewsSubscriberService newsSubscriberService); }
NewsSubscriberController { @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") public ResponseEntity<NewsSubscriberRequestDto> save( @RequestBody @Valid NewsSubscriberRequestDto dto) { return ResponseEntity.status(HttpStatus.OK) .body(newsSubscriberService.save(dto)); } @Autowired  NewsSubscriberController(NewsSubscriberService newsSubscriberService); @ApiOperation(value = "Get all emails for sending news.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @GetMapping("") ResponseEntity<List<NewsSubscriberResponseDto>> getAll(); @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") ResponseEntity<NewsSubscriberRequestDto> save(
        @RequestBody @Valid NewsSubscriberRequestDto dto); @ApiOperation(value = "Deleting an email from subscribe table in database.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @GetMapping("/unsubscribe") ResponseEntity<Long> delete(@RequestParam @Valid String email,
                                       @RequestParam String unsubscribeToken); }
NewsSubscriberController { @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") public ResponseEntity<NewsSubscriberRequestDto> save( @RequestBody @Valid NewsSubscriberRequestDto dto) { return ResponseEntity.status(HttpStatus.OK) .body(newsSubscriberService.save(dto)); } @Autowired  NewsSubscriberController(NewsSubscriberService newsSubscriberService); @ApiOperation(value = "Get all emails for sending news.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @GetMapping("") ResponseEntity<List<NewsSubscriberResponseDto>> getAll(); @ApiOperation(value = "Save email in database for receiving news.") @ApiResponses(value = { @ApiResponse(code = 201, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @PostMapping("") ResponseEntity<NewsSubscriberRequestDto> save(
        @RequestBody @Valid NewsSubscriberRequestDto dto); @ApiOperation(value = "Deleting an email from subscribe table in database.") @ApiResponses(value = { @ApiResponse(code = 200, message = HttpStatuses.OK), @ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST), @ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN), }) @GetMapping("/unsubscribe") ResponseEntity<Long> delete(@RequestParam @Valid String email,
                                       @RequestParam String unsubscribeToken); final NewsSubscriberService newsSubscriberService; }