@Test public void testUpdate() throws IOException, Exception { when(fundService.update(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getUpdateFunds()); mockMvc.perform(post("/funds/_update?tenantId=default") .content(resources.readRequest("fund/fund_update_valid_request.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(201)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(content().json(resources .readResponse("fund/fund_update_valid_response.json"))); verify(fundService).update(captor.capture(), any(BindingResult.class), any(RequestInfo.class)); final List<Fund> actualRequest = captor.getValue(); assertEquals("nameupdate", actualRequest.get(0).getName()); assertEquals("code", actualRequest.get(0).getCode()); assertEquals(Character.valueOf('U'), actualRequest.get(0).getIdentifier()); assertEquals("default", actualRequest.get(0).getTenantId()); }
@PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } fundRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); List<Fund> funds = new ArrayList<>(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); Fund fund; FundContract contract; List<FundContract> fundContracts = new ArrayList<>(); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedDate(new Date()); funds.add(fund); } funds = fundService.update(funds, errors, fundRequest.getRequestInfo()); for (Fund fundObj : funds) { contract = new FundContract(); model.map(fundObj, contract); fundObj.setLastModifiedDate(new Date()); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }
FundController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } fundRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); List<Fund> funds = new ArrayList<>(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); Fund fund; FundContract contract; List<FundContract> fundContracts = new ArrayList<>(); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedDate(new Date()); funds.add(fund); } funds = fundService.update(funds, errors, fundRequest.getRequestInfo()); for (Fund fundObj : funds) { contract = new FundContract(); model.map(fundObj, contract); fundObj.setLastModifiedDate(new Date()); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; } }
FundController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } fundRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); List<Fund> funds = new ArrayList<>(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); Fund fund; FundContract contract; List<FundContract> fundContracts = new ArrayList<>(); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedDate(new Date()); funds.add(fund); } funds = fundService.update(funds, errors, fundRequest.getRequestInfo()); for (Fund fundObj : funds) { contract = new FundContract(); model.map(fundObj, contract); fundObj.setLastModifiedDate(new Date()); fundContracts.add(contract); } fundResponse.setFunds(fundContracts); return fundResponse; }  }
FundController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } fundRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); List<Fund> funds = new ArrayList<>(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); Fund fund; FundContract contract; List<FundContract> fundContracts = new ArrayList<>(); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedDate(new Date()); funds.add(fund); } funds = fundService.update(funds, errors, fundRequest.getRequestInfo()); for (Fund fundObj : funds) { contract = new FundContract(); model.map(fundObj, contract); fundObj.setLastModifiedDate(new Date()); 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("/_update") @ResponseStatus(HttpStatus.CREATED) public FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } fundRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FundResponse fundResponse = new FundResponse(); List<Fund> funds = new ArrayList<>(); fundResponse.setResponseInfo(getResponseInfo(fundRequest.getRequestInfo())); Fund fund; FundContract contract; List<FundContract> fundContracts = new ArrayList<>(); for (FundContract fundContract : fundRequest.getFunds()) { fund = new Fund(); model.map(fundContract, fund); fund.setLastModifiedBy(fundRequest.getRequestInfo().getUserInfo()); fund.setLastModifiedDate(new Date()); funds.add(fund); } funds = fundService.update(funds, errors, fundRequest.getRequestInfo()); for (Fund fundObj : funds) { contract = new FundContract(); model.map(fundObj, contract); fundObj.setLastModifiedDate(new Date()); 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);  }