@Test public void testUpdate() throws IOException, Exception { when(bankService.update(captor.capture(), any(BindingResult.class), any(RequestInfo.class))).thenReturn((getUpdateBanks())); mockMvc.perform(post("/banks/_update?tenantId=default").content(resources.readRequest("bank/bank_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("bank/bank_update_valid_response.json"))); verify(bankService).update(captor.capture(), any(BindingResult.class), any(RequestInfo.class)); final List<Bank> actualRequest = captor.getValue(); assertEquals("nameupdate", actualRequest.get(0).getName()); assertEquals("codeupdate", actualRequest.get(0).getCode()); assertEquals(true, actualRequest.get(0).getActive()); assertEquals("default", actualRequest.get(0).getTenantId()); }
@PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankResponse bankResponse = new BankResponse(); List<Bank> banks = new ArrayList<>(); bankResponse.setResponseInfo(getResponseInfo(bankRequest.getRequestInfo())); Bank bank; BankContract contract; List<BankContract> bankContracts = new ArrayList<>(); for (BankContract bankContract : bankRequest.getBanks()) { bank = new Bank(); model.map(bankContract, bank); bank.setLastModifiedBy(bankRequest.getRequestInfo().getUserInfo()); bank.setLastModifiedDate(new Date()); banks.add(bank); } banks = bankService.update(banks, errors, bankRequest.getRequestInfo()); for (Bank bankObj : banks) { contract = new BankContract(); model.map(bankObj, contract); bankObj.setLastModifiedDate(new Date()); bankContracts.add(contract); } bankResponse.setBanks(bankContracts); return bankResponse; }
BankController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankResponse bankResponse = new BankResponse(); List<Bank> banks = new ArrayList<>(); bankResponse.setResponseInfo(getResponseInfo(bankRequest.getRequestInfo())); Bank bank; BankContract contract; List<BankContract> bankContracts = new ArrayList<>(); for (BankContract bankContract : bankRequest.getBanks()) { bank = new Bank(); model.map(bankContract, bank); bank.setLastModifiedBy(bankRequest.getRequestInfo().getUserInfo()); bank.setLastModifiedDate(new Date()); banks.add(bank); } banks = bankService.update(banks, errors, bankRequest.getRequestInfo()); for (Bank bankObj : banks) { contract = new BankContract(); model.map(bankObj, contract); bankObj.setLastModifiedDate(new Date()); bankContracts.add(contract); } bankResponse.setBanks(bankContracts); return bankResponse; } }
BankController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankResponse bankResponse = new BankResponse(); List<Bank> banks = new ArrayList<>(); bankResponse.setResponseInfo(getResponseInfo(bankRequest.getRequestInfo())); Bank bank; BankContract contract; List<BankContract> bankContracts = new ArrayList<>(); for (BankContract bankContract : bankRequest.getBanks()) { bank = new Bank(); model.map(bankContract, bank); bank.setLastModifiedBy(bankRequest.getRequestInfo().getUserInfo()); bank.setLastModifiedDate(new Date()); banks.add(bank); } banks = bankService.update(banks, errors, bankRequest.getRequestInfo()); for (Bank bankObj : banks) { contract = new BankContract(); model.map(bankObj, contract); bankObj.setLastModifiedDate(new Date()); bankContracts.add(contract); } bankResponse.setBanks(bankContracts); return bankResponse; }  }
BankController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankResponse bankResponse = new BankResponse(); List<Bank> banks = new ArrayList<>(); bankResponse.setResponseInfo(getResponseInfo(bankRequest.getRequestInfo())); Bank bank; BankContract contract; List<BankContract> bankContracts = new ArrayList<>(); for (BankContract bankContract : bankRequest.getBanks()) { bank = new Bank(); model.map(bankContract, bank); bank.setLastModifiedBy(bankRequest.getRequestInfo().getUserInfo()); bank.setLastModifiedDate(new Date()); banks.add(bank); } banks = bankService.update(banks, errors, bankRequest.getRequestInfo()); for (Bank bankObj : banks) { contract = new BankContract(); model.map(bankObj, contract); bankObj.setLastModifiedDate(new Date()); bankContracts.add(contract); } bankResponse.setBanks(bankContracts); return bankResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankResponse create(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo,
			BindingResult errors,@RequestParam String tenantId); }
BankController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankResponse bankResponse = new BankResponse(); List<Bank> banks = new ArrayList<>(); bankResponse.setResponseInfo(getResponseInfo(bankRequest.getRequestInfo())); Bank bank; BankContract contract; List<BankContract> bankContracts = new ArrayList<>(); for (BankContract bankContract : bankRequest.getBanks()) { bank = new Bank(); model.map(bankContract, bank); bank.setLastModifiedBy(bankRequest.getRequestInfo().getUserInfo()); bank.setLastModifiedDate(new Date()); banks.add(bank); } banks = bankService.update(banks, errors, bankRequest.getRequestInfo()); for (Bank bankObj : banks) { contract = new BankContract(); model.map(bankObj, contract); bankObj.setLastModifiedDate(new Date()); bankContracts.add(contract); } bankResponse.setBanks(bankContracts); return bankResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankResponse create(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo,
			BindingResult errors,@RequestParam String tenantId);  }