@Test public void saveOrUpdateShouldRespondWithNoErrorResponseWhenThePostedJsonIsCorrect() throws Exception { mockMvc.perform(post(REQUEST_URL) .contentType(MediaTypes.APPLICATION_JSON_UTF8) .accept(MediaTypes.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(positionDTOWithCorrectPositionName))) .andExpect(status().isOk()) .andExpect(jsonPath("$.errorMessage").isEmpty()) .andExpect(jsonPath("$.fields").isEmpty()); then(positionService).should().saveOrUpdate(positionDTOWithCorrectPositionName); verifyZeroInteractions(messageKeyResolver); }
@Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(positionDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = this.messageKeyResolver.resolveMessageOrDefault(EMPTY_POSITION_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } }
PositionController extends LogicallyDeletableAbstractController<PositionDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(positionDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = this.messageKeyResolver.resolveMessageOrDefault(EMPTY_POSITION_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } }
PositionController extends LogicallyDeletableAbstractController<PositionDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(positionDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = this.messageKeyResolver.resolveMessageOrDefault(EMPTY_POSITION_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  PositionController(PositionService positionService,
                            MessageKeyResolver messageKeyResolver); }
PositionController extends LogicallyDeletableAbstractController<PositionDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(positionDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = this.messageKeyResolver.resolveMessageOrDefault(EMPTY_POSITION_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  PositionController(PositionService positionService,
                            MessageKeyResolver messageKeyResolver); @Override ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO,
                                                   BindingResult result, Locale locale); @RequestMapping(method = RequestMethod.GET) Collection<ChannelDTO> getPositions(); }
PositionController extends LogicallyDeletableAbstractController<PositionDTO> { @Override public ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { this.logicallyDeletableService.saveOrUpdate(positionDTO); return new ResponseEntity<>(RestResponse.NO_ERROR, HttpStatus.OK); } else { String errorMessage = this.messageKeyResolver.resolveMessageOrDefault(EMPTY_POSITION_NAME_MESSAGE_KEY); RestResponse restResponse = new RestResponse(errorMessage); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  PositionController(PositionService positionService,
                            MessageKeyResolver messageKeyResolver); @Override ResponseEntity<RestResponse> saveOrUpdate(@RequestBody @Valid PositionDTO positionDTO,
                                                   BindingResult result, Locale locale); @RequestMapping(method = RequestMethod.GET) Collection<ChannelDTO> getPositions();  }