@Test public void testCreate_Error() throws IOException, Exception { when(recoveryService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getRecoverys()); mockMvc.perform( post("/recoverys/_create").content(resources.readRequest("recovery/recovery_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; recoveryRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recovery.setCreatedDate(new Date()); recovery.setCreatedBy(recoveryRequest.getRequestInfo().getUserInfo()); recovery.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoverys.add(recovery); } recoverys = recoveryService.create(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery f : recoverys) { contract = new RecoveryContract(); contract.setCreatedDate(new Date()); model.map(f, contract); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }
RecoveryController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; recoveryRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recovery.setCreatedDate(new Date()); recovery.setCreatedBy(recoveryRequest.getRequestInfo().getUserInfo()); recovery.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoverys.add(recovery); } recoverys = recoveryService.create(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery f : recoverys) { contract = new RecoveryContract(); contract.setCreatedDate(new Date()); model.map(f, contract); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; } }
RecoveryController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; recoveryRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recovery.setCreatedDate(new Date()); recovery.setCreatedBy(recoveryRequest.getRequestInfo().getUserInfo()); recovery.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoverys.add(recovery); } recoverys = recoveryService.create(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery f : recoverys) { contract = new RecoveryContract(); contract.setCreatedDate(new Date()); model.map(f, contract); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  }
RecoveryController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; recoveryRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recovery.setCreatedDate(new Date()); recovery.setCreatedBy(recoveryRequest.getRequestInfo().getUserInfo()); recovery.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoverys.add(recovery); } recoverys = recoveryService.create(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery f : recoverys) { contract = new RecoveryContract(); contract.setCreatedDate(new Date()); model.map(f, contract); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) RecoveryResponse search(@ModelAttribute RecoverySearchContract recoverySearchContract, @RequestBody RequestInfo requestInfo,
                                   BindingResult errors,@RequestParam String tenantId); }
RecoveryController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); RecoveryResponse recoveryResponse = new RecoveryResponse(); recoveryResponse.setResponseInfo(getResponseInfo(recoveryRequest.getRequestInfo())); List<Recovery> recoverys = new ArrayList<>(); Recovery recovery; List<RecoveryContract> recoveryContracts = new ArrayList<>(); RecoveryContract contract; recoveryRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (RecoveryContract recoveryContract : recoveryRequest.getRecoverys()) { recovery = new Recovery(); model.map(recoveryContract, recovery); recovery.setCreatedDate(new Date()); recovery.setCreatedBy(recoveryRequest.getRequestInfo().getUserInfo()); recovery.setLastModifiedBy(recoveryRequest.getRequestInfo().getUserInfo()); recoverys.add(recovery); } recoverys = recoveryService.create(recoverys, errors, recoveryRequest.getRequestInfo()); for (Recovery f : recoverys) { contract = new RecoveryContract(); contract.setCreatedDate(new Date()); model.map(f, contract); recoveryContracts.add(contract); } recoveryResponse.setRecoverys(recoveryContracts); return recoveryResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse create(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) RecoveryResponse update(@RequestBody RecoveryRequest recoveryRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) RecoveryResponse search(@ModelAttribute RecoverySearchContract recoverySearchContract, @RequestBody RequestInfo requestInfo,
                                   BindingResult errors,@RequestParam String tenantId);  }