@Test public void testCreate_Error() throws IOException, Exception { when(fundService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getFunds()); mockMvc.perform( post("/funds/_create").content(resources.readRequest("fund/fund_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { ApplicationThreadLocals.setRequestInfo(fundRequest.getRequestInfo()); if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); List<Fund> funds = new ArrayList<>(); Fund fund; List<FundContract> fundContracts = new ArrayList<>(); FundContract contract; fundRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setCreatedDate(new Date()); fund.setCreatedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); funds.add(fund); } funds = fundService.create(funds, errors, fundRequest.getRequestInfo()); for (Fund f : funds) { contract = new FundContract(); contract.setCreatedDate(new Date()); model.map(f, contract); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }
FundController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { ApplicationThreadLocals.setRequestInfo(fundRequest.getRequestInfo()); if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); List<Fund> funds = new ArrayList<>(); Fund fund; List<FundContract> fundContracts = new ArrayList<>(); FundContract contract; fundRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setCreatedDate(new Date()); fund.setCreatedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); funds.add(fund); } funds = fundService.create(funds, errors, fundRequest.getRequestInfo()); for (Fund f : funds) { contract = new FundContract(); contract.setCreatedDate(new Date()); model.map(f, contract); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; } }
FundController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { ApplicationThreadLocals.setRequestInfo(fundRequest.getRequestInfo()); if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); List<Fund> funds = new ArrayList<>(); Fund fund; List<FundContract> fundContracts = new ArrayList<>(); FundContract contract; fundRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setCreatedDate(new Date()); fund.setCreatedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); funds.add(fund); } funds = fundService.create(funds, errors, fundRequest.getRequestInfo()); for (Fund f : funds) { contract = new FundContract(); contract.setCreatedDate(new Date()); model.map(f, contract); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }  }
FundController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { ApplicationThreadLocals.setRequestInfo(fundRequest.getRequestInfo()); if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); List<Fund> funds = new ArrayList<>(); Fund fund; List<FundContract> fundContracts = new ArrayList<>(); FundContract contract; fundRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setCreatedDate(new Date()); fund.setCreatedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); funds.add(fund); } funds = fundService.create(funds, errors, fundRequest.getRequestInfo()); for (Fund f : funds) { contract = new FundContract(); contract.setCreatedDate(new Date()); model.map(f, contract); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo,
            BindingResult errors,@RequestParam String tenantId); }
FundController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { ApplicationThreadLocals.setRequestInfo(fundRequest.getRequestInfo()); if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); List<Fund> funds = new ArrayList<>(); Fund fund; List<FundContract> fundContracts = new ArrayList<>(); FundContract contract; fundRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setCreatedDate(new Date()); fund.setCreatedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); funds.add(fund); } funds = fundService.create(funds, errors, fundRequest.getRequestInfo()); for (Fund f : funds) { contract = new FundContract(); contract.setCreatedDate(new Date()); model.map(f, contract); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo,
            BindingResult errors,@RequestParam String tenantId);  }