QueryParameters implements Iterable<CompositeQueryParameter> { public static Builder newBuilder() { return new Builder(); } private  QueryParameters(Builder builder); static Builder newBuilder(); static Builder newBuilder(QueryParameters parameters); static QueryParameters activeEntityQueryParams(RecordStorage<?> storage); @Override Iterator<CompositeQueryParameter> iterator(); boolean isLifecycleAttributesSet(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test @DisplayName("support equality") void supportEquality() { QueryParameters paramsA1 = newBuilder().build(); QueryParameters paramsA2 = newBuilder().build(); Column bColumn = column(); Filter bFilter = Filters.eq("b", "c"); QueryParameters paramsB1 = newBuilder().add(aggregatingParameter(bColumn, bFilter)) .build(); QueryParameters paramsB2 = newBuilder().add(aggregatingParameter(bColumn, bFilter)) .build(); QueryParameters paramsB3 = newBuilder().add(aggregatingParameter(bColumn, bFilter)) .build(); Column cColumn = column(); Filter cFilter = Filters.eq("a", 42); QueryParameters paramsC = newBuilder().add(aggregatingParameter(cColumn, cFilter)) .build(); new EqualsTester().addEqualityGroup(paramsA1, paramsA2) .addEqualityGroup(paramsB1, paramsB2, paramsB3) .addEqualityGroup(paramsC) .testEquals(); }
@Test @DisplayName("be constructed from empty builder") void constructFromEmptyBuilder() { QueryParameters parameters = newBuilder().build(); assertNotNull(parameters); }
@Test @DisplayName("produce iterator over filters") void produceFilterIterator() { Filter[] filters = { eq("firstFilter", 1), eq("secondFilter", 42), gt("thirdFilter", currentTime())}; Multimap<Column, Filter> filterMap = ImmutableMultimap.of(column(), filters[0], column(), filters[1], column(), filters[2]); CompositeQueryParameter parameter = CompositeQueryParameter.from(filterMap, ALL); QueryParameters parameters = newBuilder().add(parameter) .build(); Collection<Filter> results = newLinkedList(); for (CompositeQueryParameter queryParameter : parameters) { results.addAll(queryParameter.filters() .values()); } assertArrayEquals(filters, results.toArray()); }
@Test @DisplayName("keep multiple filters for single column") void keepManyFiltersForColumn() throws ParseException { String columnName = "time"; Column column = column(); Timestamp startTime = Timestamps.parse("2000-01-01T10:00:00.000-05:00"); Timestamp deadline = Timestamps.parse("2017-01-01T10:00:00.000-05:00"); Filter startTimeFilter = gt(columnName, startTime); Filter deadlineFilter = le(columnName, deadline); Multimap<Column, Filter> filterMap = ImmutableMultimap.<Column, Filter>builder() .put(column, startTimeFilter) .put(column, deadlineFilter) .build(); CompositeQueryParameter parameter = CompositeQueryParameter.from(filterMap, ALL); QueryParameters parameters = newBuilder().add(parameter) .build(); List<CompositeQueryParameter> aggregatingParameters = newArrayList(parameters); assertThat(aggregatingParameters).hasSize(1); Multimap<Column, Filter> actualFilters = aggregatingParameters.get(0) .filters(); Collection<Filter> timeFilters = actualFilters.get(column); IterableSubject assertTimeFilters = assertThat(timeFilters); assertTimeFilters.hasSize(2); assertTimeFilters.containsExactly(startTimeFilter, deadlineFilter); }