@Test public void testSearch() throws IOException, Exception { Pagination<Bank> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getBanks()); page.getPagedData().get(0).setId("1"); when(bankService.search(any(BankSearch.class), any(BindingResult.class))).thenReturn(page); mockMvc.perform( post("/banks/_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("bank/bank_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankSearch domain = new BankSearch(); mapper.map(bankSearchContract, domain); BankContract contract; ModelMapper model = new ModelMapper(); List<BankContract> bankContracts = new ArrayList<>(); Pagination<Bank> banks = bankService.search(domain, errors); for (Bank bank : banks.getPagedData()) { contract = new BankContract(); model.map(bank, contract); bankContracts.add(contract); } BankResponse response = new BankResponse(); response.setBanks(bankContracts); response.setPage(new PaginationContract(banks)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
BankController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankSearch domain = new BankSearch(); mapper.map(bankSearchContract, domain); BankContract contract; ModelMapper model = new ModelMapper(); List<BankContract> bankContracts = new ArrayList<>(); Pagination<Bank> banks = bankService.search(domain, errors); for (Bank bank : banks.getPagedData()) { contract = new BankContract(); model.map(bank, contract); bankContracts.add(contract); } BankResponse response = new BankResponse(); response.setBanks(bankContracts); response.setPage(new PaginationContract(banks)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
BankController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankSearch domain = new BankSearch(); mapper.map(bankSearchContract, domain); BankContract contract; ModelMapper model = new ModelMapper(); List<BankContract> bankContracts = new ArrayList<>(); Pagination<Bank> banks = bankService.search(domain, errors); for (Bank bank : banks.getPagedData()) { contract = new BankContract(); model.map(bank, contract); bankContracts.add(contract); } BankResponse response = new BankResponse(); response.setBanks(bankContracts); response.setPage(new PaginationContract(banks)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
BankController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankSearch domain = new BankSearch(); mapper.map(bankSearchContract, domain); BankContract contract; ModelMapper model = new ModelMapper(); List<BankContract> bankContracts = new ArrayList<>(); Pagination<Bank> banks = bankService.search(domain, errors); for (Bank bank : banks.getPagedData()) { contract = new BankContract(); model.map(bank, contract); bankContracts.add(contract); } BankResponse response = new BankResponse(); response.setBanks(bankContracts); response.setPage(new PaginationContract(banks)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankResponse create(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo,
			BindingResult errors,@RequestParam String tenantId); }
BankController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankSearch domain = new BankSearch(); mapper.map(bankSearchContract, domain); BankContract contract; ModelMapper model = new ModelMapper(); List<BankContract> bankContracts = new ArrayList<>(); Pagination<Bank> banks = bankService.search(domain, errors); for (Bank bank : banks.getPagedData()) { contract = new BankContract(); model.map(bank, contract); bankContracts.add(contract); } BankResponse response = new BankResponse(); response.setBanks(bankContracts); response.setPage(new PaginationContract(banks)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankResponse create(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankResponse update(@RequestBody BankRequest bankRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankResponse search(@ModelAttribute BankSearchContract bankSearchContract, @RequestBody RequestInfo requestInfo,
			BindingResult errors,@RequestParam String tenantId);  }