@Test public void testCreate_Error() throws IOException, Exception { when(bankAccountService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn((getBankAccounts())); mockMvc.perform(post("/bankaccounts/_create") .content(resources.readRequest("bankaccount/bankaccount_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); List<BankAccount> bankaccounts = new ArrayList<>(); BankAccount bankAccount; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); BankAccountContract contract; bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setCreatedDate(new Date()); bankAccount.setCreatedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.create(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount f : bankaccounts) { contract = new BankAccountContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }
BankAccountController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); List<BankAccount> bankaccounts = new ArrayList<>(); BankAccount bankAccount; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); BankAccountContract contract; bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setCreatedDate(new Date()); bankAccount.setCreatedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.create(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount f : bankaccounts) { contract = new BankAccountContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; } }
BankAccountController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); List<BankAccount> bankaccounts = new ArrayList<>(); BankAccount bankAccount; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); BankAccountContract contract; bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setCreatedDate(new Date()); bankAccount.setCreatedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.create(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount f : bankaccounts) { contract = new BankAccountContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankAccountContracts.add(contract); } bankAccountResponse.setBankAccounts(bankAccountContracts); return bankAccountResponse; }  }
BankAccountController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); List<BankAccount> bankaccounts = new ArrayList<>(); BankAccount bankAccount; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); BankAccountContract contract; bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setCreatedDate(new Date()); bankAccount.setCreatedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.create(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount f : bankaccounts) { contract = new BankAccountContract(); contract.setCreatedDate(new Date()); model.map(f, contract); 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("/_create") @ResponseStatus(HttpStatus.CREATED) public BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankAccountResponse bankAccountResponse = new BankAccountResponse(); bankAccountResponse.setResponseInfo(getResponseInfo(bankAccountRequest.getRequestInfo())); List<BankAccount> bankaccounts = new ArrayList<>(); BankAccount bankAccount; List<BankAccountContract> bankAccountContracts = new ArrayList<>(); BankAccountContract contract; bankAccountRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankAccountContract bankAccountContract : bankAccountRequest.getBankAccounts()) { bankAccount = new BankAccount(); model.map(bankAccountContract, bankAccount); bankAccount.setCreatedDate(new Date()); bankAccount.setCreatedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankAccount.setLastModifiedBy(bankAccountRequest.getRequestInfo().getUserInfo()); bankaccounts.add(bankAccount); } bankaccounts = bankAccountService.create(bankaccounts, errors, bankAccountRequest.getRequestInfo()); for (BankAccount f : bankaccounts) { contract = new BankAccountContract(); contract.setCreatedDate(new Date()); model.map(f, contract); 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);  }