@Test public void testCreate_Error() throws IOException, Exception { when(functionService.create(any(List.class), any(BindingResult.class), any(RequestInfo.class))) .thenReturn(getFunctions()); mockMvc.perform(post("/functions/_create") .content(resources.readRequest("function/function_create_invalid_field_value.json")) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is5xxServerError()); }
@PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); List<Function> functions = new ArrayList<>(); Function function; List<FunctionContract> functionContracts = new ArrayList<>(); FunctionContract contract; functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setCreatedDate(new Date()); function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); functions.add(function); } functions = functionService.create(functions, errors, functionRequest.getRequestInfo()); for (Function f : functions) { contract = new FunctionContract(); contract.setCreatedDate(new Date()); model.map(f, contract); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }
FunctionController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); List<Function> functions = new ArrayList<>(); Function function; List<FunctionContract> functionContracts = new ArrayList<>(); FunctionContract contract; functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setCreatedDate(new Date()); function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); functions.add(function); } functions = functionService.create(functions, errors, functionRequest.getRequestInfo()); for (Function f : functions) { contract = new FunctionContract(); contract.setCreatedDate(new Date()); model.map(f, contract); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; } }
FunctionController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); List<Function> functions = new ArrayList<>(); Function function; List<FunctionContract> functionContracts = new ArrayList<>(); FunctionContract contract; functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setCreatedDate(new Date()); function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); functions.add(function); } functions = functionService.create(functions, errors, functionRequest.getRequestInfo()); for (Function f : functions) { contract = new FunctionContract(); contract.setCreatedDate(new Date()); model.map(f, contract); functionContracts.add(contract); } functionResponse.setFunctions(functionContracts); return functionResponse; }  }
FunctionController { @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); List<Function> functions = new ArrayList<>(); Function function; List<FunctionContract> functionContracts = new ArrayList<>(); FunctionContract contract; functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setCreatedDate(new Date()); function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); functions.add(function); } functions = functionService.create(functions, errors, functionRequest.getRequestInfo()); for (Function f : functions) { contract = new FunctionContract(); contract.setCreatedDate(new Date()); model.map(f, contract); 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("/_create") @ResponseStatus(HttpStatus.CREATED) public FunctionResponse create(@RequestBody FunctionRequest functionRequest, BindingResult errors,@RequestParam String tenantId) { if (errors.hasErrors()) { throw new CustomBindException(errors); } ModelMapper model = new ModelMapper(); FunctionResponse functionResponse = new FunctionResponse(); functionResponse.setResponseInfo(getResponseInfo(functionRequest.getRequestInfo())); List<Function> functions = new ArrayList<>(); Function function; List<FunctionContract> functionContracts = new ArrayList<>(); FunctionContract contract; functionRequest.getRequestInfo().setAction(Constants.ACTION_CREATE); for (FunctionContract functionContract : functionRequest.getFunctions()) { function = new Function(); model.map(functionContract, function); function.setCreatedDate(new Date()); function.setCreatedBy(functionRequest.getRequestInfo().getUserInfo()); function.setLastModifiedBy(functionRequest.getRequestInfo().getUserInfo()); functions.add(function); } functions = functionService.create(functions, errors, functionRequest.getRequestInfo()); for (Function f : functions) { contract = new FunctionContract(); contract.setCreatedDate(new Date()); model.map(f, contract); 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);  }