@Test
public void searchTest() throws Exception {

	// search published state
	List<DemandResponseEventFilter> filters = DemandResponseEventFilter.builder().isPublished().build();
	searchAndExpect(filters, 0);
	filters = DemandResponseEventFilter.builder().isNotPublished().build();
	searchAndExpect(filters, 3);
	// search by marketcontext
	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);
	// search by ven
	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);
	// search by state
	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);
	// search sendable
	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);
	// search start end
	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);
}