use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class QueryParametersShould method keep_multiple_filters_for_single_column.
@Test
public void keep_multiple_filters_for_single_column() throws ParseException {
final String columnName = "time";
final EntityColumn column = mock(EntityColumn.class);
// Some valid Timestamp values
final Timestamp startTime = Timestamps.parse("2000-01-01T10:00:00.000-05:00");
final Timestamp deadline = Timestamps.parse("2017-01-01T10:00:00.000-05:00");
final ColumnFilter startTimeFilter = gt(columnName, startTime);
final ColumnFilter deadlineFilter = le(columnName, deadline);
final Multimap<EntityColumn, ColumnFilter> columnFilters = ImmutableMultimap.<EntityColumn, ColumnFilter>builder().put(column, startTimeFilter).put(column, deadlineFilter).build();
final CompositeQueryParameter parameter = from(columnFilters, ALL);
final QueryParameters parameters = newBuilder().add(parameter).build();
final List<CompositeQueryParameter> aggregatingParameters = newArrayList(parameters);
assertSize(1, aggregatingParameters);
final Multimap<EntityColumn, ColumnFilter> actualColumnFilters = aggregatingParameters.get(0).getFilters();
final Collection<ColumnFilter> timeFilters = actualColumnFilters.get(column);
assertSize(2, timeFilters);
assertContainsAll(timeFilters, startTimeFilter, deadlineFilter);
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class QueryParametersShould method support_equality.
@Test
public void support_equality() {
// --- Group A ---
// Consists of 2 empty instances
final QueryParameters paramsA1 = newBuilder().build();
final QueryParameters paramsA2 = newBuilder().build();
// --- Group B ---
// Consists of 3 instances with a single filter targeting a String column
final EntityColumn bColumn = mockColumn();
final ColumnFilter bFilter = ColumnFilters.eq("b", "c");
final QueryParameters paramsB1 = newBuilder().add(aggregatingParameter(bColumn, bFilter)).build();
final QueryParameters paramsB2 = newBuilder().add(aggregatingParameter(bColumn, bFilter)).build();
final QueryParameters paramsB3 = newBuilder().add(aggregatingParameter(bColumn, bFilter)).build();
// --- Group C ---
// Consists of an instance with a single filter targeting an integer number column
final EntityColumn cColumn = mockColumn();
final ColumnFilter cFilter = ColumnFilters.eq("a", 42);
final QueryParameters paramsC = newBuilder().add(aggregatingParameter(cColumn, cFilter)).build();
// --- Check ---
new EqualsTester().addEqualityGroup(paramsA1, paramsA2).addEqualityGroup(paramsB1, paramsB2, paramsB3).addEqualityGroup(paramsC).testEquals();
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class ERepositoryShould method convert_type_query_to_EntityFilters.
@Test
public void convert_type_query_to_EntityFilters() {
final String typeName = " com.example.EventType ";
final EventFilter validFilter = filterForType(typeName);
final EventFilter invalidFilter = filterForType(" ");
final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(validFilter).addFilter(invalidFilter).build();
final EntityFilters entityFilters = toEntityFilters(query);
assertEquals(1, entityFilters.getFilterCount());
final CompositeColumnFilter compositeFilter = entityFilters.getFilter(0);
final List<ColumnFilter> columnFilters = compositeFilter.getFilterList();
assertEquals(CompositeOperator.EITHER, compositeFilter.getOperator());
assertEquals(1, columnFilters.size());
final Any typeNameAsAny = columnFilters.get(0).getValue();
assertEquals(typeName, toObject(typeNameAsAny, String.class));
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class RecordStorageShould method filter_records_by_columns.
// Complex test case (still tests a single operation)
@SuppressWarnings("OverlyLongMethod")
@Test
public void filter_records_by_columns() {
final Project.Status requiredValue = DONE;
final Int32Value wrappedValue = Int32Value.newBuilder().setValue(requiredValue.getNumber()).build();
final Version versionValue = Version.newBuilder().setNumber(// Value of the counter after one columns
2).build();
final ColumnFilter status = eq("projectStatusValue", wrappedValue);
final ColumnFilter version = eq("counterVersion", versionValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).addFilter(version).build();
final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.from(filters, storage);
final I idMatching = newId();
final I idWrong1 = newId();
final I idWrong2 = newId();
final TestCounterEntity<I> matchingEntity = new TestCounterEntity<>(idMatching);
final TestCounterEntity<I> wrongEntity1 = new TestCounterEntity<>(idWrong1);
final TestCounterEntity<I> wrongEntity2 = new TestCounterEntity<>(idWrong2);
// 2 of 3 have required values
matchingEntity.setStatus(requiredValue);
wrongEntity1.setStatus(requiredValue);
wrongEntity2.setStatus(CANCELLED);
// Change internal Entity state
wrongEntity1.getCounter();
// After the mutation above the single matching record is the one under the `idMatching` ID
final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
storage.write(idMatching, recordRight);
storage.write(idWrong1, recordWrong1);
storage.write(idWrong2, recordWrong2);
final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
assertSingleRecord(fineRecord, readRecords);
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method match_columns.
@SuppressWarnings({ // Mocks <-> reflection issues
"unchecked", // Test data is constant
"ConstantConditions" })
@Test
public void match_columns() {
final String targetName = "feature";
final EntityColumn target = mock(EntityColumn.class);
when(target.isNullable()).thenReturn(true);
when(target.getStoredName()).thenReturn(targetName);
when(target.getType()).thenReturn(Boolean.class);
final Serializable acceptedValue = true;
final Collection<Object> ids = Collections.emptyList();
final Multimap<EntityColumn, ColumnFilter> filters = of(target, eq(targetName, acceptedValue));
final CompositeQueryParameter parameter = createParams(filters, ALL);
final QueryParameters params = QueryParameters.newBuilder().add(parameter).build();
final EntityQuery<?> query = createQuery(ids, params);
final Any matchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final Any nonMatchingId = AnyPacker.pack(Sample.messageOfType(TaskId.class));
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord matching = EntityRecord.newBuilder().setEntityId(matchingId).build();
final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(nonMatchingId).build();
final EntityColumn.MemoizedValue storedValue = mock(EntityColumn.MemoizedValue.class);
when(storedValue.getSourceColumn()).thenReturn(target);
when(storedValue.getValue()).thenReturn(acceptedValue);
final Map<String, EntityColumn.MemoizedValue> matchingColumns = ImmutableMap.of(targetName, storedValue);
final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
final EntityRecordWithColumns matchingRecord = createRecord(matching, matchingColumns);
assertTrue(matcher.apply(matchingRecord));
assertFalse(matcher.apply(nonMatchingRecord));
}
Aggregations