@Test public void test_search() throws IOException, Exception { Pagination<Fund> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getFunds()); page.getPagedData().get(0).setId("1"); when(fundService.search(any(FundSearch.class), any(BindingResult.class))).thenReturn(page); mockMvc.perform( post("/funds/_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("fund/fund_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { System.out.println("requestInfo in FundController Search "+requestInfo.toString()); System.out.println("requestInfo in FundController Search "+requestInfo.getAuthToken()); ModelMapper mapper = new ModelMapper(); FundSearch domain = new FundSearch(); mapper.map(fundSearchContract, domain); FundContract contract; ModelMapper model = new ModelMapper(); List<FundContract> fundContracts = new ArrayList<>(); Pagination<Fund> funds = fundService.search(domain, errors); if (funds.getPagedData() != null) { for (Fund fund : funds.getPagedData()) { contract = new FundContract(); model.map(fund, contract); fundContracts.add(contract); } } FundResponse response = new FundResponse(); response.setFunds(fundContracts); response.setPage(new PaginationContract(funds)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
FundController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { System.out.println("requestInfo in FundController Search "+requestInfo.toString()); System.out.println("requestInfo in FundController Search "+requestInfo.getAuthToken()); ModelMapper mapper = new ModelMapper(); FundSearch domain = new FundSearch(); mapper.map(fundSearchContract, domain); FundContract contract; ModelMapper model = new ModelMapper(); List<FundContract> fundContracts = new ArrayList<>(); Pagination<Fund> funds = fundService.search(domain, errors); if (funds.getPagedData() != null) { for (Fund fund : funds.getPagedData()) { contract = new FundContract(); model.map(fund, contract); fundContracts.add(contract); } } FundResponse response = new FundResponse(); response.setFunds(fundContracts); response.setPage(new PaginationContract(funds)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
FundController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { System.out.println("requestInfo in FundController Search "+requestInfo.toString()); System.out.println("requestInfo in FundController Search "+requestInfo.getAuthToken()); ModelMapper mapper = new ModelMapper(); FundSearch domain = new FundSearch(); mapper.map(fundSearchContract, domain); FundContract contract; ModelMapper model = new ModelMapper(); List<FundContract> fundContracts = new ArrayList<>(); Pagination<Fund> funds = fundService.search(domain, errors); if (funds.getPagedData() != null) { for (Fund fund : funds.getPagedData()) { contract = new FundContract(); model.map(fund, contract); fundContracts.add(contract); } } FundResponse response = new FundResponse(); response.setFunds(fundContracts); response.setPage(new PaginationContract(funds)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
FundController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { System.out.println("requestInfo in FundController Search "+requestInfo.toString()); System.out.println("requestInfo in FundController Search "+requestInfo.getAuthToken()); ModelMapper mapper = new ModelMapper(); FundSearch domain = new FundSearch(); mapper.map(fundSearchContract, domain); FundContract contract; ModelMapper model = new ModelMapper(); List<FundContract> fundContracts = new ArrayList<>(); Pagination<Fund> funds = fundService.search(domain, errors); if (funds.getPagedData() != null) { for (Fund fund : funds.getPagedData()) { contract = new FundContract(); model.map(fund, contract); fundContracts.add(contract); } } FundResponse response = new FundResponse(); response.setFunds(fundContracts); response.setPage(new PaginationContract(funds)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo,
            BindingResult errors,@RequestParam String tenantId); }
FundController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { System.out.println("requestInfo in FundController Search "+requestInfo.toString()); System.out.println("requestInfo in FundController Search "+requestInfo.getAuthToken()); ModelMapper mapper = new ModelMapper(); FundSearch domain = new FundSearch(); mapper.map(fundSearchContract, domain); FundContract contract; ModelMapper model = new ModelMapper(); List<FundContract> fundContracts = new ArrayList<>(); Pagination<Fund> funds = fundService.search(domain, errors); if (funds.getPagedData() != null) { for (Fund fund : funds.getPagedData()) { contract = new FundContract(); model.map(fund, contract); fundContracts.add(contract); } } FundResponse response = new FundResponse(); response.setFunds(fundContracts); response.setPage(new PaginationContract(funds)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) FundResponse create(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) FundResponse update(@RequestBody FundRequest fundRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) FundResponse search(@ModelAttribute FundSearchContract fundSearchContract, @RequestBody RequestInfo requestInfo,
            BindingResult errors,@RequestParam String tenantId);  }