@Test public void saveOrUpdateShouldRespondWithNoErrorResponseWhenThePostedJsonIsCorrect() throws Exception { mockMvc.perform(buildJsonPostRequest(REQUEST_URL, correctPostedDto)) .andExpect(status().isOk()) .andExpect(jsonPath("$.errorMessage").isEmpty()) .andExpect(jsonPath("$.fields").isEmpty()); then(channelService).should().saveOrUpdate(correctPostedDto); verifyZeroInteractions(messageKeyResolver); }
@Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(channelDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = messageKeyResolver.resolveMessageOrDefault(EMPTY_CHANNEL_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } }
ChannelController extends LogicallyDeletableAbstractController<ChannelDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(channelDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = messageKeyResolver.resolveMessageOrDefault(EMPTY_CHANNEL_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } }
ChannelController extends LogicallyDeletableAbstractController<ChannelDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(channelDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = messageKeyResolver.resolveMessageOrDefault(EMPTY_CHANNEL_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  ChannelController(ChannelService channelService, MessageKeyResolver messageKeyResolver); }
ChannelController extends LogicallyDeletableAbstractController<ChannelDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(channelDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = messageKeyResolver.resolveMessageOrDefault(EMPTY_CHANNEL_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  ChannelController(ChannelService channelService, MessageKeyResolver messageKeyResolver); @Override ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO,
                                                   BindingResult result, Locale locale); @RequestMapping(method = RequestMethod.GET) Collection<ChannelDTO> getChannels(); }
ChannelController extends LogicallyDeletableAbstractController<ChannelDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(channelDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = messageKeyResolver.resolveMessageOrDefault(EMPTY_CHANNEL_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  ChannelController(ChannelService channelService, MessageKeyResolver messageKeyResolver); @Override ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid ChannelDTO channelDTO,
                                                   BindingResult result, Locale locale); @RequestMapping(method = RequestMethod.GET) Collection<ChannelDTO> getChannels();  }