@Test public void testCreate_Error() throws IOException, Exception { when(bankBranchService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))).thenReturn((getBankBranches())); mockMvc.perform(post("/bankbranches/_create") .content(resources.readRequest("bankbranch/bankbranch_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankBranchResponse bankBranchResponse = new BankBranchResponse(); bankBranchResponse.setResponseInfo(getResponseInfo(bankBranchRequest.getRequestInfo())); List<BankBranch> bankbranches = new ArrayList<>(); BankBranch bankBranch; List<BankBranchContract> bankBranchContracts = new ArrayList<>(); BankBranchContract contract; bankBranchRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankBranchContract bankBranchContract : bankBranchRequest.getBankBranches()) { bankBranch = new BankBranch(); model.map(bankBranchContract, bankBranch); bankBranch.setCreatedDate(new Date()); bankBranch.setCreatedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankBranch.setLastModifiedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankbranches.add(bankBranch); } bankbranches = bankBranchService.create(bankbranches, errors, bankBranchRequest.getRequestInfo()); for (BankBranch f : bankbranches) { contract = new BankBranchContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankBranchContracts.add(contract); } bankBranchResponse.setBankBranches(bankBranchContracts); return bankBranchResponse; }
BankBranchController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankBranchResponse bankBranchResponse = new BankBranchResponse(); bankBranchResponse.setResponseInfo(getResponseInfo(bankBranchRequest.getRequestInfo())); List<BankBranch> bankbranches = new ArrayList<>(); BankBranch bankBranch; List<BankBranchContract> bankBranchContracts = new ArrayList<>(); BankBranchContract contract; bankBranchRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankBranchContract bankBranchContract : bankBranchRequest.getBankBranches()) { bankBranch = new BankBranch(); model.map(bankBranchContract, bankBranch); bankBranch.setCreatedDate(new Date()); bankBranch.setCreatedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankBranch.setLastModifiedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankbranches.add(bankBranch); } bankbranches = bankBranchService.create(bankbranches, errors, bankBranchRequest.getRequestInfo()); for (BankBranch f : bankbranches) { contract = new BankBranchContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankBranchContracts.add(contract); } bankBranchResponse.setBankBranches(bankBranchContracts); return bankBranchResponse; } }
BankBranchController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankBranchResponse bankBranchResponse = new BankBranchResponse(); bankBranchResponse.setResponseInfo(getResponseInfo(bankBranchRequest.getRequestInfo())); List<BankBranch> bankbranches = new ArrayList<>(); BankBranch bankBranch; List<BankBranchContract> bankBranchContracts = new ArrayList<>(); BankBranchContract contract; bankBranchRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankBranchContract bankBranchContract : bankBranchRequest.getBankBranches()) { bankBranch = new BankBranch(); model.map(bankBranchContract, bankBranch); bankBranch.setCreatedDate(new Date()); bankBranch.setCreatedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankBranch.setLastModifiedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankbranches.add(bankBranch); } bankbranches = bankBranchService.create(bankbranches, errors, bankBranchRequest.getRequestInfo()); for (BankBranch f : bankbranches) { contract = new BankBranchContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankBranchContracts.add(contract); } bankBranchResponse.setBankBranches(bankBranchContracts); return bankBranchResponse; }  }
BankBranchController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankBranchResponse bankBranchResponse = new BankBranchResponse(); bankBranchResponse.setResponseInfo(getResponseInfo(bankBranchRequest.getRequestInfo())); List<BankBranch> bankbranches = new ArrayList<>(); BankBranch bankBranch; List<BankBranchContract> bankBranchContracts = new ArrayList<>(); BankBranchContract contract; bankBranchRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankBranchContract bankBranchContract : bankBranchRequest.getBankBranches()) { bankBranch = new BankBranch(); model.map(bankBranchContract, bankBranch); bankBranch.setCreatedDate(new Date()); bankBranch.setCreatedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankBranch.setLastModifiedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankbranches.add(bankBranch); } bankbranches = bankBranchService.create(bankbranches, errors, bankBranchRequest.getRequestInfo()); for (BankBranch f : bankbranches) { contract = new BankBranchContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankBranchContracts.add(contract); } bankBranchResponse.setBankBranches(bankBranchContracts); return bankBranchResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankBranchResponse update(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankBranchResponse search(@ModelAttribute BankBranchSearchContract bankBranchSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId); }
BankBranchController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); BankBranchResponse bankBranchResponse = new BankBranchResponse(); bankBranchResponse.setResponseInfo(getResponseInfo(bankBranchRequest.getRequestInfo())); List<BankBranch> bankbranches = new ArrayList<>(); BankBranch bankBranch; List<BankBranchContract> bankBranchContracts = new ArrayList<>(); BankBranchContract contract; bankBranchRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (BankBranchContract bankBranchContract : bankBranchRequest.getBankBranches()) { bankBranch = new BankBranch(); model.map(bankBranchContract, bankBranch); bankBranch.setCreatedDate(new Date()); bankBranch.setCreatedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankBranch.setLastModifiedBy(bankBranchRequest.getRequestInfo().getUserInfo()); bankbranches.add(bankBranch); } bankbranches = bankBranchService.create(bankbranches, errors, bankBranchRequest.getRequestInfo()); for (BankBranch f : bankbranches) { contract = new BankBranchContract(); contract.setCreatedDate(new Date()); model.map(f, contract); bankBranchContracts.add(contract); } bankBranchResponse.setBankBranches(bankBranchContracts); return bankBranchResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankBranchResponse create(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankBranchResponse update(@RequestBody BankBranchRequest bankBranchRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankBranchResponse search(@ModelAttribute BankBranchSearchContract bankBranchSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId);  }