@Test public void testSearch() throws IOException, Exception { Pagination<BankAccount> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getBankAccounts()); page.getPagedData().get(0).setId("1"); when(bankAccountService.search(any(BankAccountSearch.class), any(BindingResult.class))).thenReturn(page); mockMvc.perform(post("/bankaccounts/_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("bankaccount/bankAccount_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankAccountSearch domain = new BankAccountSearch(); mapper.map(bankAccountSearchContract, domain); BankAccountContract contract; ModelMapper model = new ModelMapper(); List<BankAccountContract> bankAccountContracts = new ArrayList<>(); Pagination<BankAccount> bankaccounts = bankAccountService.search(domain, errors); for (BankAccount bankAccount : bankaccounts.getPagedData()) { contract = new BankAccountContract(); model.map(bankAccount, contract); bankAccountContracts.add(contract); } BankAccountResponse response = new BankAccountResponse(); response.setBankAccounts(bankAccountContracts); response.setPage(new PaginationContract(bankaccounts)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
BankAccountController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankAccountSearch domain = new BankAccountSearch(); mapper.map(bankAccountSearchContract, domain); BankAccountContract contract; ModelMapper model = new ModelMapper(); List<BankAccountContract> bankAccountContracts = new ArrayList<>(); Pagination<BankAccount> bankaccounts = bankAccountService.search(domain, errors); for (BankAccount bankAccount : bankaccounts.getPagedData()) { contract = new BankAccountContract(); model.map(bankAccount, contract); bankAccountContracts.add(contract); } BankAccountResponse response = new BankAccountResponse(); response.setBankAccounts(bankAccountContracts); response.setPage(new PaginationContract(bankaccounts)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
BankAccountController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankAccountSearch domain = new BankAccountSearch(); mapper.map(bankAccountSearchContract, domain); BankAccountContract contract; ModelMapper model = new ModelMapper(); List<BankAccountContract> bankAccountContracts = new ArrayList<>(); Pagination<BankAccount> bankaccounts = bankAccountService.search(domain, errors); for (BankAccount bankAccount : bankaccounts.getPagedData()) { contract = new BankAccountContract(); model.map(bankAccount, contract); bankAccountContracts.add(contract); } BankAccountResponse response = new BankAccountResponse(); response.setBankAccounts(bankAccountContracts); response.setPage(new PaginationContract(bankaccounts)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
BankAccountController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankAccountSearch domain = new BankAccountSearch(); mapper.map(bankAccountSearchContract, domain); BankAccountContract contract; ModelMapper model = new ModelMapper(); List<BankAccountContract> bankAccountContracts = new ArrayList<>(); Pagination<BankAccount> bankaccounts = bankAccountService.search(domain, errors); for (BankAccount bankAccount : bankaccounts.getPagedData()) { contract = new BankAccountContract(); model.map(bankAccount, contract); bankAccountContracts.add(contract); } BankAccountResponse response = new BankAccountResponse(); response.setBankAccounts(bankAccountContracts); response.setPage(new PaginationContract(bankaccounts)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId); }
BankAccountController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract, @RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId) { ModelMapper mapper = new ModelMapper(); BankAccountSearch domain = new BankAccountSearch(); mapper.map(bankAccountSearchContract, domain); BankAccountContract contract; ModelMapper model = new ModelMapper(); List<BankAccountContract> bankAccountContracts = new ArrayList<>(); Pagination<BankAccount> bankaccounts = bankAccountService.search(domain, errors); for (BankAccount bankAccount : bankaccounts.getPagedData()) { contract = new BankAccountContract(); model.map(bankAccount, contract); bankAccountContracts.add(contract); } BankAccountResponse response = new BankAccountResponse(); response.setBankAccounts(bankAccountContracts); response.setPage(new PaginationContract(bankaccounts)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse create(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) BankAccountResponse update(@RequestBody BankAccountRequest bankAccountRequest, BindingResult errors,@RequestParam String tenantId); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) BankAccountResponse search(@ModelAttribute BankAccountSearchContract bankAccountSearchContract,
			@RequestBody RequestInfo requestInfo, BindingResult errors,@RequestParam String tenantId);  }