@Test public void test_search() throws IOException, Exception { final Pagination<Budget> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getBudgets()); page.getPagedData().get(0).setId("1"); when(budgetService.search(any(BudgetSearch.class))).thenReturn(page); mockMvc.perform(post("/budgets/_search").content(resources.getRequestInfo()) .contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().is(200)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(resources.readResponse("budget/budget_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract, @RequestBody final RequestInfo requestInfo, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetSearch domain = mapper.toSearchDomain(budgetSearchContract); BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); final Pagination<Budget> budgets = budgetService.search(domain); for (final Budget budget : budgets.getPagedData()) { contract = mapper.toContract(budget); budgetContracts.add(contract); } final BudgetResponse response = new BudgetResponse(); response.setBudgets(budgetContracts); response.setPage(new PaginationContract(budgets)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
BudgetController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract, @RequestBody final RequestInfo requestInfo, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetSearch domain = mapper.toSearchDomain(budgetSearchContract); BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); final Pagination<Budget> budgets = budgetService.search(domain); for (final Budget budget : budgets.getPagedData()) { contract = mapper.toContract(budget); budgetContracts.add(contract); } final BudgetResponse response = new BudgetResponse(); response.setBudgets(budgetContracts); response.setPage(new PaginationContract(budgets)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
BudgetController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract, @RequestBody final RequestInfo requestInfo, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetSearch domain = mapper.toSearchDomain(budgetSearchContract); BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); final Pagination<Budget> budgets = budgetService.search(domain); for (final Budget budget : budgets.getPagedData()) { contract = mapper.toContract(budget); budgetContracts.add(contract); } final BudgetResponse response = new BudgetResponse(); response.setBudgets(budgetContracts); response.setPage(new PaginationContract(budgets)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
BudgetController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract, @RequestBody final RequestInfo requestInfo, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetSearch domain = mapper.toSearchDomain(budgetSearchContract); BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); final Pagination<Budget> budgets = budgetService.search(domain); for (final Budget budget : budgets.getPagedData()) { contract = mapper.toContract(budget); budgetContracts.add(contract); } final BudgetResponse response = new BudgetResponse(); response.setBudgets(budgetContracts); response.setPage(new PaginationContract(budgets)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BudgetResponse create(@RequestBody final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BudgetResponse update(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract,
            @RequestBody final RequestInfo requestInfo, final BindingResult errors); }
BudgetController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract, @RequestBody final RequestInfo requestInfo, final BindingResult errors) { final BudgetMapper mapper = new BudgetMapper(); final BudgetSearch domain = mapper.toSearchDomain(budgetSearchContract); BudgetContract contract = null; final List<BudgetContract> budgetContracts = new ArrayList<BudgetContract>(); final Pagination<Budget> budgets = budgetService.search(domain); for (final Budget budget : budgets.getPagedData()) { contract = mapper.toContract(budget); budgetContracts.add(contract); } final BudgetResponse response = new BudgetResponse(); response.setBudgets(budgetContracts); response.setPage(new PaginationContract(budgets)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BudgetResponse create(@RequestBody final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BudgetResponse update(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) BudgetResponse delete(@RequestBody @Valid final BudgetRequest budgetRequest, final BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BudgetResponse search(@ModelAttribute final BudgetSearchContract budgetSearchContract,
            @RequestBody final RequestInfo requestInfo, final BindingResult errors); static final String ACTION_CREATE; static final String ACTION_UPDATE; static final String ACTION_DELETE; static final String PLACEHOLDER; }