@Test public void testCreate_Error() throws IOException, Exception { when(accountEntityService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getAccountEntities()); mockMvc.perform(post("/accountentities/_create?tenantId=default") .content(resources.readRequest("accountentity/accountentity_create_invalid_fieldvalue.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); List<AccountEntity> accountentities = new ArrayList<>(); AccountEntity accountEntity; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); AccountEntityContract contract; accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setCreatedDate(new Date()); accountEntity.setCreatedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountentities.add(accountEntity); } accountentities = accountEntityService.create(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity f : accountentities) { contract = new AccountEntityContract(); contract.setCreatedDate(new Date()); model.map(f, contract); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }
AccountEntityController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); List<AccountEntity> accountentities = new ArrayList<>(); AccountEntity accountEntity; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); AccountEntityContract contract; accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setCreatedDate(new Date()); accountEntity.setCreatedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountentities.add(accountEntity); } accountentities = accountEntityService.create(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity f : accountentities) { contract = new AccountEntityContract(); contract.setCreatedDate(new Date()); model.map(f, contract); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; } }
AccountEntityController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); List<AccountEntity> accountentities = new ArrayList<>(); AccountEntity accountEntity; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); AccountEntityContract contract; accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setCreatedDate(new Date()); accountEntity.setCreatedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountentities.add(accountEntity); } accountentities = accountEntityService.create(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity f : accountentities) { contract = new AccountEntityContract(); contract.setCreatedDate(new Date()); model.map(f, contract); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }  }
AccountEntityController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); List<AccountEntity> accountentities = new ArrayList<>(); AccountEntity accountEntity; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); AccountEntityContract contract; accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setCreatedDate(new Date()); accountEntity.setCreatedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountentities.add(accountEntity); } accountentities = accountEntityService.create(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity f : accountentities) { contract = new AccountEntityContract(); contract.setCreatedDate(new Date()); model.map(f, contract); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) AccountEntityResponse search(@ModelAttribute AccountEntitySearchContract accountEntitySearchContract,
                                        @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId); }
AccountEntityController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); List<AccountEntity> accountentities = new ArrayList<>(); AccountEntity accountEntity; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); AccountEntityContract contract; accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setCreatedDate(new Date()); accountEntity.setCreatedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountentities.add(accountEntity); } accountentities = accountEntityService.create(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity f : accountentities) { contract = new AccountEntityContract(); contract.setCreatedDate(new Date()); model.map(f, contract); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) AccountEntityResponse create(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) AccountEntityResponse search(@ModelAttribute AccountEntitySearchContract accountEntitySearchContract,
                                        @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId);  }