@Test public void test_search() throws IOException, Exception { Pagination<Function> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getFunctions()); page.getPagedData().get(0).setId("1"); when(functionService.search(any(FunctionSearch.class), any(BindingResult.class))).thenReturn(page); mockMvc.perform(post("/functions/_search?tenantId=default").content(resources.getRequestInfo()) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(resources.readResponse("function/function_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); FunctionSearch domain = new FunctionSearch(); mapper.map(functionSearchContract, domain); FunctionContract contract; ModelMapper model = new ModelMapper(); List<FunctionContract> functionContracts = new ArrayList<>(); Pagination<Function> functions = functionService.search(domain, errors); for (Function function : functions.getPagedData()) { contract = new FunctionContract(); model.map(function, contract); functionContracts.add(contract); } FunctionResponse response = new FunctionResponse(); response.setFunctions(functionContracts); response.setPage(new PaginationContract(functions)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
FunctionController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); FunctionSearch domain = new FunctionSearch(); mapper.map(functionSearchContract, domain); FunctionContract contract; ModelMapper model = new ModelMapper(); List<FunctionContract> functionContracts = new ArrayList<>(); Pagination<Function> functions = functionService.search(domain, errors); for (Function function : functions.getPagedData()) { contract = new FunctionContract(); model.map(function, contract); functionContracts.add(contract); } FunctionResponse response = new FunctionResponse(); response.setFunctions(functionContracts); response.setPage(new PaginationContract(functions)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
FunctionController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); FunctionSearch domain = new FunctionSearch(); mapper.map(functionSearchContract, domain); FunctionContract contract; ModelMapper model = new ModelMapper(); List<FunctionContract> functionContracts = new ArrayList<>(); Pagination<Function> functions = functionService.search(domain, errors); for (Function function : functions.getPagedData()) { contract = new FunctionContract(); model.map(function, contract); functionContracts.add(contract); } FunctionResponse response = new FunctionResponse(); response.setFunctions(functionContracts); response.setPage(new PaginationContract(functions)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
FunctionController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); FunctionSearch domain = new FunctionSearch(); mapper.map(functionSearchContract, domain); FunctionContract contract; ModelMapper model = new ModelMapper(); List<FunctionContract> functionContracts = new ArrayList<>(); Pagination<Function> functions = functionService.search(domain, errors); for (Function function : functions.getPagedData()) { contract = new FunctionContract(); model.map(function, contract); functionContracts.add(contract); } FunctionResponse response = new FunctionResponse(); response.setFunctions(functionContracts); response.setPage(new PaginationContract(functions)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @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("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FunctionResponse search(@ModelAttribute FunctionSearchContract functionSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); FunctionSearch domain = new FunctionSearch(); mapper.map(functionSearchContract, domain); FunctionContract contract; ModelMapper model = new ModelMapper(); List<FunctionContract> functionContracts = new ArrayList<>(); Pagination<Function> functions = functionService.search(domain, errors); for (Function function : functions.getPagedData()) { contract = new FunctionContract(); model.map(function, contract); functionContracts.add(contract); } FunctionResponse response = new FunctionResponse(); response.setFunctions(functionContracts); response.setPage(new PaginationContract(functions)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @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);  }