DemandResponseController { @RequestMapping(value = "/search", method = RequestMethod.POST) @ResponseBody public List<DemandResponseEventReadDto> search(@RequestBody List<DemandResponseEventFilter> filters, @RequestParam(value = "start", required = false) Long start, @RequestParam(value = "end", required = false) Long end, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, HttpServletResponse response) { Page<DemandResponseEvent> search = demandResponseEventService.search(filters, start, end, page, size); response.addHeader("X-total-page", String.valueOf(search.getTotalPages())); response.addHeader("X-total-count", String.valueOf(search.getTotalElements())); return dtoMapper.mapList(search, DemandResponseEventReadDto.class); }  @RequestMapping(value = "/search", method = RequestMethod.POST) @ResponseBody List<DemandResponseEventReadDto> search(@RequestBody List<DemandResponseEventFilter> filters,
			@RequestParam(value = "start", required = false) Long start,
			@RequestParam(value = "end", required = false) Long end,
			@RequestParam(value = "page", required = false) Integer page,
			@RequestParam(value = "size", required = false) Integer size, HttpServletResponse response); @RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto create(@Valid @RequestBody DemandResponseEventCreateDto event,
			HttpServletResponse response, BindingResult result); @RequestMapping(value = "/{id}", method = RequestMethod.PUT) @ResponseBody DemandResponseEventReadDto update(@PathVariable(value = "id") Long id,
			@Valid @RequestBody DemandResponseEventUpdateDto event, HttpServletResponse response,
			BindingResult result); @RequestMapping(value = "/{id}/publish", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto publish(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/active", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto active(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/cancel", method = RequestMethod.POST) @ResponseBody DemandResponseEventReadDto cancel(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody DemandResponseEventReadDto read(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseBody void delete(@PathVariable(value = "id") Long id, HttpServletResponse response); @RequestMapping(value = "/{id}/venResponse", method = RequestMethod.GET) @ResponseBody List<VenDemandResponseEventDto> readVenDemandResponseEvent(@PathVariable(value = "id") Long id,
			HttpServletResponse response); @RequestMapping(value = "/{id}/venResponse/{username}", method = RequestMethod.GET) @ResponseBody VenDemandResponseEventDto readVenDemandResponseEvent(@PathVariable(value = "id") Long id,
			@PathVariable(value = "username") String username, HttpServletResponse response);  }
@Test public void searchTest() throws Exception { List<DemandResponseEventFilter> filters = DemandResponseEventFilter.builder().isPublished().build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().isNotPublished().build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().addMarketContext(marketContext.getName()).build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().isPublished().addMarketContext(marketContext.getName()).build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().isPublished().isNotPublished() .addMarketContext(marketContext.getName()).build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().isNotPublished().isPublished() .addMarketContext(marketContext.getName()).build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().addMarketContext(marketContext.getName()).isPublished().build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().addMarketContext(UNKNOWN_MARKETCONTEXT_NAME).build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().addVenId(VEN1).build(); searchAndExpect(filters, 2); filters = DemandResponseEventFilter.builder().addVenId(VEN1).addVenId(VEN2).build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().addVenId(VEN1).addMarketContext(UNKNOWN_MARKETCONTEXT_NAME) .build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().addMarketContext(UNKNOWN_MARKETCONTEXT_NAME).addVenId(VEN1) .build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().addMarketContext(UNKNOWN_MARKETCONTEXT_NAME) .addMarketContext(marketContext.getName()).addVenId(VEN1).build(); searchAndExpect(filters, 2); filters = DemandResponseEventFilter.builder().addVenId(VEN2).build(); searchAndExpect(filters, 2); filters = DemandResponseEventFilter.builder().addVenId("mouaiccool").build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.ACTIVE).build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.ACTIVE).addVenId(VEN1) .build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().addVenId(VEN1).addState(DemandResponseEventStateEnum.ACTIVE) .build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.CANCELLED).build(); searchAndExpect(filters, 2); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.CANCELLED) .addState(DemandResponseEventStateEnum.ACTIVE).build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().isSendable().build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 3); filters = DemandResponseEventFilter.builder().isNotSendable().addState(DemandResponseEventStateEnum.ACTIVE) .build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().isNotSendable().isSendable() .addState(DemandResponseEventStateEnum.ACTIVE).build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().isSendable().isNotSendable() .addState(DemandResponseEventStateEnum.ACTIVE).build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.ACTIVE).isNotSendable() .build(); searchAndExpect(filters, 1); filters = DemandResponseEventFilter.builder().addState(DemandResponseEventStateEnum.ACTIVE).isNotSendable() .addVenId("mouaiccool").build(); searchAndExpect(filters, 0); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 0L, 1L, 0); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 0L, 10L * 1000, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 0L, null, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, null, 10L * 1000, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 10L, 10L * 1000, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 0L, 5L * 1000, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 5L * 1000, 10L * 1000, 3); filters = DemandResponseEventFilter.builder().isNotSendable().build(); searchAndExpect(filters, 11L * 1000, 15L * 1000, 0); }