@Test public void test_search() throws IOException, Exception { Pagination<Instrument> page = new Pagination<>(); page.setTotalPages(1); page.setTotalResults(1); page.setCurrentPage(0); page.setPagedData(getInstruments()); page.getPagedData().get(0).setId("1"); when(instrumentService.search(any(InstrumentSearch.class))).thenReturn(page); mockMvc.perform(post("/instruments/_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("instrument/instrument_search_valid_response.json"))); }
@PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract, RequestInfo requestInfo, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentSearch domain = mapper.toSearchDomain(instrumentSearchContract); InstrumentContract contract; List<InstrumentContract> instrumentContracts = new ArrayList<>(); Pagination<Instrument> instruments = instrumentService.search(domain); if (instruments.getPagedData() != null) for (Instrument instrument : instruments.getPagedData()) { contract = mapper.toContract(instrument); instrumentContracts.add(contract); } InstrumentResponse response = new InstrumentResponse(); response.setInstruments(instrumentContracts); response.setPage(new PaginationContract(instruments)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }
InstrumentController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract, RequestInfo requestInfo, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentSearch domain = mapper.toSearchDomain(instrumentSearchContract); InstrumentContract contract; List<InstrumentContract> instrumentContracts = new ArrayList<>(); Pagination<Instrument> instruments = instrumentService.search(domain); if (instruments.getPagedData() != null) for (Instrument instrument : instruments.getPagedData()) { contract = mapper.toContract(instrument); instrumentContracts.add(contract); } InstrumentResponse response = new InstrumentResponse(); response.setInstruments(instrumentContracts); response.setPage(new PaginationContract(instruments)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; } }
InstrumentController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract, RequestInfo requestInfo, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentSearch domain = mapper.toSearchDomain(instrumentSearchContract); InstrumentContract contract; List<InstrumentContract> instrumentContracts = new ArrayList<>(); Pagination<Instrument> instruments = instrumentService.search(domain); if (instruments.getPagedData() != null) for (Instrument instrument : instruments.getPagedData()) { contract = mapper.toContract(instrument); instrumentContracts.add(contract); } InstrumentResponse response = new InstrumentResponse(); response.setInstruments(instrumentContracts); response.setPage(new PaginationContract(instruments)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  }
InstrumentController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract, RequestInfo requestInfo, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentSearch domain = mapper.toSearchDomain(instrumentSearchContract); InstrumentContract contract; List<InstrumentContract> instrumentContracts = new ArrayList<>(); Pagination<Instrument> instruments = instrumentService.search(domain); if (instruments.getPagedData() != null) for (Instrument instrument : instruments.getPagedData()) { contract = mapper.toContract(instrument); instrumentContracts.add(contract); } InstrumentResponse response = new InstrumentResponse(); response.setInstruments(instrumentContracts); response.setPage(new PaginationContract(instruments)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse update(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse delete(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract,
            RequestInfo requestInfo, BindingResult errors); @PostMapping("/_deposit") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse depositInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); @PostMapping("/_dishonor") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse dishonorInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); }
InstrumentController { @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) public InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract, RequestInfo requestInfo, BindingResult errors) { InstrumentMapper mapper = new InstrumentMapper(); InstrumentSearch domain = mapper.toSearchDomain(instrumentSearchContract); InstrumentContract contract; List<InstrumentContract> instrumentContracts = new ArrayList<>(); Pagination<Instrument> instruments = instrumentService.search(domain); if (instruments.getPagedData() != null) for (Instrument instrument : instruments.getPagedData()) { contract = mapper.toContract(instrument); instrumentContracts.add(contract); } InstrumentResponse response = new InstrumentResponse(); response.setInstruments(instrumentContracts); response.setPage(new PaginationContract(instruments)); response.setResponseInfo(getResponseInfo(requestInfo)); return response; }  @PostMapping("/_create") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse create(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_update") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse update(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_delete") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse delete(@RequestBody InstrumentRequest instrumentRequest, BindingResult errors); @PostMapping("/_search") @ResponseBody @ResponseStatus(HttpStatus.OK) InstrumentResponse search(@ModelAttribute InstrumentSearchContract instrumentSearchContract,
            RequestInfo requestInfo, BindingResult errors); @PostMapping("/_deposit") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse depositInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); @PostMapping("/_dishonor") @ResponseStatus(HttpStatus.CREATED) InstrumentResponse dishonorInstrument(@RequestBody InstrumentRequest instrumentDepositRequest, BindingResult errors); static final String ACTION_CREATE; static final String ACTION_UPDATE; static final String ACTION_DELETE; static final String PLACEHOLDER; }