@Test public void testUpdate() throws IOException, Exception { when(functionService.update(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getUpdateFunctions()); mockMvc.perform( post("/functions/_update?tenantId=default").content(resources.readRequest("function/function_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("function/function_update_valid_response.json"))); verify(functionService).update(captor.capture(), any(BindingResult.class), any(RequestInfo.class)); final List<Function> 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 FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); List<Function> functions = new ArrayList<>(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); Function function; FunctionContract contract; List<FunctionContract> functionContracts = new ArrayList<>(); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedDate(new Date()); functions.add(function); } functions = functionService.update(functions, errors, functionRequest.getRequestInfo()); for (Function functionObj : functions) { contract = new FunctionContract(); model.map(functionObj, contract); functionObj.setLastModifiedDate(new Date()); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }
FunctionController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); List<Function> functions = new ArrayList<>(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); Function function; FunctionContract contract; List<FunctionContract> functionContracts = new ArrayList<>(); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedDate(new Date()); functions.add(function); } functions = functionService.update(functions, errors, functionRequest.getRequestInfo()); for (Function functionObj : functions) { contract = new FunctionContract(); model.map(functionObj, contract); functionObj.setLastModifiedDate(new Date()); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; } }
FunctionController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); List<Function> functions = new ArrayList<>(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); Function function; FunctionContract contract; List<FunctionContract> functionContracts = new ArrayList<>(); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedDate(new Date()); functions.add(function); } functions = functionService.update(functions, errors, functionRequest.getRequestInfo()); for (Function functionObj : functions) { contract = new FunctionContract(); model.map(functionObj, contract); functionObj.setLastModifiedDate(new Date()); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }  }
FunctionController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); List<Function> functions = new ArrayList<>(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); Function function; FunctionContract contract; List<FunctionContract> functionContracts = new ArrayList<>(); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedDate(new Date()); functions.add(function); } functions = functionService.update(functions, errors, functionRequest.getRequestInfo()); for (Function functionObj : functions) { contract = new FunctionContract(); model.map(functionObj, contract); functionObj.setLastModifiedDate(new Date()); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId); }
FunctionController { @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } functionRequest.getRequestInfo().setAction(Constants.ACTION_UPDATE); ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); List<Function> functions = new ArrayList<>(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); Function function; FunctionContract contract; List<FunctionContract> functionContracts = new ArrayList<>(); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedDate(new Date()); functions.add(function); } functions = functionService.update(functions, errors, functionRequest.getRequestInfo()); for (Function functionObj : functions) { contract = new FunctionContract(); model.map(functionObj, contract); functionObj.setLastModifiedDate(new Date()); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FunctionResponse update(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId);  }