@Test public void testUpdate() throws IOException, Exception { when(accountEntityService.update(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getUpdateAccountEntities()); mockMvc.perform( post("/accountentities/_update?tenantId=default").content(resources.readRequest("accountentity/accountentity_update_request.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().is(201)).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(resources.readResponse("accountentity/accountentity_update_response.json"))); verify(accountEntityService).update(captor.capture(), any(BindingResult.class), any(RequestInfo.class)); final List<AccountEntity> actualRequest = captor.getValue(); assertEquals("nameU", actualRequest.get(0).getName()); assertEquals("codeU", actualRequest.get(0).getCode()); assertEquals("default", actualRequest.get(0).getTenantId()); }
@PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); List<AccountEntity> accountentities = new ArrayList<>(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); AccountEntity accountEntity; AccountEntityContract contract; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedDate(new Date()); accountentities.add(accountEntity); } accountentities = accountEntityService.update(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity accountEntityObj : accountentities) { contract = new AccountEntityContract(); model.map(accountEntityObj, contract); accountEntityObj.setLastModifiedDate(new Date()); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }
AccountEntityController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); List<AccountEntity> accountentities = new ArrayList<>(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); AccountEntity accountEntity; AccountEntityContract contract; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedDate(new Date()); accountentities.add(accountEntity); } accountentities = accountEntityService.update(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity accountEntityObj : accountentities) { contract = new AccountEntityContract(); model.map(accountEntityObj, contract); accountEntityObj.setLastModifiedDate(new Date()); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; } }
AccountEntityController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); List<AccountEntity> accountentities = new ArrayList<>(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); AccountEntity accountEntity; AccountEntityContract contract; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedDate(new Date()); accountentities.add(accountEntity); } accountentities = accountEntityService.update(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity accountEntityObj : accountentities) { contract = new AccountEntityContract(); model.map(accountEntityObj, contract); accountEntityObj.setLastModifiedDate(new Date()); accountEntityContracts.add(contract); } accountEntityResponse.setAccountEntities(accountEntityContracts); return accountEntityResponse; }  }
AccountEntityController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); List<AccountEntity> accountentities = new ArrayList<>(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); AccountEntity accountEntity; AccountEntityContract contract; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedDate(new Date()); accountentities.add(accountEntity); } accountentities = accountEntityService.update(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity accountEntityObj : accountentities) { contract = new AccountEntityContract(); model.map(accountEntityObj, contract); accountEntityObj.setLastModifiedDate(new Date()); 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("/_update") @ResponseStatus(HttpStatus.CREATED) public AccountEntityResponse update(@RequestBody AccountEntityRequest accountEntityRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } accountEntityRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); AccountEntityResponse accountEntityResponse = new AccountEntityResponse(); List<AccountEntity> accountentities = new ArrayList<>(); accountEntityResponse.setResponseInfo(getResponseInfo(accountEntityRequest.getRequestInfo())); AccountEntity accountEntity; AccountEntityContract contract; List<AccountEntityContract> accountEntityContracts = new ArrayList<>(); for (AccountEntityContract accountEntityContract : accountEntityRequest.getAccountEntities()) { accountEntity = new AccountEntity(); model.map(accountEntityContract, accountEntity); accountEntity.setLastModifiedBy(accountEntityRequest.getRequestInfo().getUserInfo()); accountEntity.setLastModifiedDate(new Date()); accountentities.add(accountEntity); } accountentities = accountEntityService.update(accountentities, errors, accountEntityRequest.getRequestInfo()); for (AccountEntity accountEntityObj : accountentities) { contract = new AccountEntityContract(); model.map(accountEntityObj, contract); accountEntityObj.setLastModifiedDate(new Date()); 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);  }