@Test public void testUpdate() throws IOException, Exception { when(bankAccountService.update(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn((getUpdatedBankAccounts())); mockMvc.perform(post("/bankaccounts/_update?tenantId=default") .content(resources.readRequest("bankaccount/bankAccount_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("bankaccount/bankAccount_update_valid_response.json"))); verify(bankAccountService).update(captor.capture(), any(BindingResult.class), any(RequestInfo.class)); final List<BankAccount> actualRequest = captor.getValue(); assertEquals("1", actualRequest.get(0).getBankBranch().getId()); assertEquals("1", actualRequest.get(0).getChartOfAccount().getId()); assertEquals("2", actualRequest.get(0).getFund().getId()); assertEquals("0004", actualRequest.get(0).getAccountNumber()); assertEquals("testupdate", actualRequest.get(0).getAccountType()); assertEquals(true, actualRequest.get(0).getActive()); }
@PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); List<BankAccount> bankaccounts = new ArrayList<>(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); BankAccount bankAccount; BankAccountContract contract; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedDate(new Date()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.update(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount bankAccountObj : bankaccounts) { contract = new BankAccountContract(); model.map(bankAccountObj, contract); bankAccountObj.setLastModifiedDate(new Date()); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }
BankAccountController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); List<BankAccount> bankaccounts = new ArrayList<>(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); BankAccount bankAccount; BankAccountContract contract; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedDate(new Date()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.update(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount bankAccountObj : bankaccounts) { contract = new BankAccountContract(); model.map(bankAccountObj, contract); bankAccountObj.setLastModifiedDate(new Date()); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; } }
BankAccountController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); List<BankAccount> bankaccounts = new ArrayList<>(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); BankAccount bankAccount; BankAccountContract contract; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedDate(new Date()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.update(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount bankAccountObj : bankaccounts) { contract = new BankAccountContract(); model.map(bankAccountObj, contract); bankAccountObj.setLastModifiedDate(new Date()); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }  }
BankAccountController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); List<BankAccount> bankaccounts = new ArrayList<>(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); BankAccount bankAccount; BankAccountContract contract; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedDate(new Date()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.update(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount bankAccountObj : bankaccounts) { contract = new BankAccountContract(); model.map(bankAccountObj, contract); bankAccountObj.setLastModifiedDate(new Date()); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId); }
BankAccountController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); List<BankAccount> bankaccounts = new ArrayList<>(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); BankAccount bankAccount; BankAccountContract contract; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedDate(new Date()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.update(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount bankAccountObj : bankaccounts) { contract = new BankAccountContract(); model.map(bankAccountObj, contract); bankAccountObj.setLastModifiedDate(new Date()); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId);  }