QueryToFilters { static TargetFilters convert(EventStreamQuery query) { TargetFilters result = new QueryToFilters(query).convert(); return result; } private  QueryToFilters(EventStreamQuery query);   }
@Test @DisplayName("convert empty query to empty EntityFilters") void convertEmptyToFilters() { EventStreamQuery query = EventStreamQuery.newBuilder() .build(); TargetFilters entityFilters = convert(query); assertTrue(entityFilters.getFilterList() .isEmpty()); }
@Test @DisplayName("convert time query to EntityFilters") void convertTimeToFilters() { EventStreamQuery query = EventStreamQuery .newBuilder() .setAfter(Timestamps.MIN_VALUE) .setBefore(Timestamps.MAX_VALUE) .build(); TargetFilters entityFilters = convert(query); assertEquals(1, entityFilters.getFilterCount()); CompositeFilter compositeFilter = entityFilters.getFilter(0); List<Filter> filters = compositeFilter.getFilterList(); assertEquals(CompositeOperator.ALL, compositeFilter.getOperator()); assertEquals(2, filters.size()); }
@Test @DisplayName("convert type query to EntityFilters") void convertTypeToFilters() { String typeName = " com.example.EventType "; EventFilter validFilter = filterForType(typeName); EventFilter invalidFilter = filterForType(" "); EventStreamQuery query = EventStreamQuery .newBuilder() .addFilter(validFilter) .addFilter(invalidFilter) .build(); TargetFilters entityFilters = convert(query); assertEquals(1, entityFilters.getFilterCount()); CompositeFilter compositeFilter = entityFilters.getFilter(0); List<Filter> filters = compositeFilter.getFilterList(); assertEquals(CompositeOperator.EITHER, compositeFilter.getOperator()); assertEquals(1, filters.size()); Any typeNameAsAny = filters.get(0) .getValue(); assertEquals(typeName.trim(), toObject(typeNameAsAny, String.class)); }