use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class EntityQueryMatcherShould method not_match_by_wrong_field_name.
@Test
public void not_match_by_wrong_field_name() {
final String wrongName = "wrong";
final EntityColumn target = mock(EntityColumn.class);
final Multimap<EntityColumn, ColumnFilter> filters = of(target, eq(wrongName, "any"));
final CompositeQueryParameter parameter = createParams(filters, EITHER);
final QueryParameters params = QueryParameters.newBuilder().add(parameter).build();
final EntityQuery<?> query = createQuery(Collections.emptyList(), params);
final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
final EntityRecord record = EntityRecord.newBuilder().setEntityId(Any.getDefaultInstance()).build();
final EntityRecordWithColumns recordWithColumns = of(record);
assertFalse(matcher.apply(recordWithColumns));
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class RecordBasedRepositoryShould method find_entities_by_query.
@Test
public void find_entities_by_query() {
final I id1 = createId(271);
final I id2 = createId(314);
final Class<E> entityClass = repository.getEntityClass();
final E entity1 = Given.entityOfClass(entityClass).withId(id1).build();
final E entity2 = Given.entityOfClass(entityClass).withId(id2).build();
repository.store(entity1);
repository.store(entity2);
final String fieldPath = "idString";
final StringValue fieldValue = StringValue.newBuilder().setValue(id1.toString()).build();
final ColumnFilter filter = eq(fieldPath, fieldValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().addFilter(filter).setOperator(ALL).build();
final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
final Collection<E> found = newArrayList(repository.find(filters, FieldMask.getDefaultInstance()));
assertSize(1, found);
assertContains(entity1, found);
assertNotContains(entity2, found);
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class CompositeQueryParameterShould method merge_with_other_instances.
@Test
public void merge_with_other_instances() {
final Class<? extends Entity> cls = AbstractVersionableEntity.class;
final String archivedColumnName = archived.name();
final String deletedColumnName = deleted.name();
final String versionColumnName = version.name();
final EntityColumn archivedColumn = findColumn(cls, archivedColumnName);
final EntityColumn deletedColumn = findColumn(cls, deletedColumnName);
final EntityColumn versionColumn = findColumn(cls, versionColumnName);
final ColumnFilter archived = eq(archivedColumnName, true);
final ColumnFilter deleted = eq(archivedColumnName, false);
final ColumnFilter versionLower = ge(archivedColumnName, 2);
final ColumnFilter versionUpper = lt(archivedColumnName, 10);
final CompositeQueryParameter lifecycle = from(of(archivedColumn, archived, deletedColumn, deleted), ALL);
final CompositeQueryParameter versionLowerBound = from(of(versionColumn, versionLower), ALL);
final CompositeQueryParameter versionUpperBound = from(of(versionColumn, versionUpper), ALL);
// Merge the instances
final CompositeQueryParameter all = lifecycle.conjunct(newArrayList(versionLowerBound, versionUpperBound));
// Check
assertEquals(all.getOperator(), ALL);
final Multimap<EntityColumn, ColumnFilter> asMultimp = all.getFilters();
assertContainsAll(asMultimp.get(versionColumn), versionLower, versionUpper);
assertContainsAll(asMultimp.get(archivedColumn), archived);
assertContainsAll(asMultimp.get(deletedColumn), deleted);
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class CompositeQueryParameterShould method merge_with_single_filter.
@Test
public void merge_with_single_filter() {
final Class<? extends Entity> cls = AbstractVersionableEntity.class;
final String archivedColumnName = archived.name();
final String deletedColumnName = deleted.name();
final String versionColumnName = version.name();
final EntityColumn archivedColumn = findColumn(cls, archivedColumnName);
final EntityColumn deletedColumn = findColumn(cls, deletedColumnName);
final EntityColumn versionColumn = findColumn(cls, versionColumnName);
final ColumnFilter archived = eq(archivedColumnName, false);
final ColumnFilter deleted = eq(archivedColumnName, false);
final ColumnFilter version = ge(archivedColumnName, 4);
final CompositeQueryParameter lifecycle = from(of(archivedColumn, archived, deletedColumn, deleted), ALL);
// Merge the instances
final CompositeQueryParameter all = lifecycle.and(versionColumn, version);
// Check
assertEquals(all.getOperator(), ALL);
final Multimap<EntityColumn, ColumnFilter> asMultimp = all.getFilters();
assertContainsAll(asMultimp.get(versionColumn), version);
assertContainsAll(asMultimp.get(archivedColumn), archived);
assertContainsAll(asMultimp.get(deletedColumn), deleted);
}
use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.
the class EntityQueriesShould method check_filter_type.
@Test(expected = IllegalArgumentException.class)
public void check_filter_type() {
// Boolean EntityColumn queried for for an Integer value
final ColumnFilter filter = ColumnFilters.gt(archived.name(), 42);
final CompositeColumnFilter compositeFilter = ColumnFilters.all(filter);
final EntityFilters filters = EntityFilters.newBuilder().addFilter(compositeFilter).build();
createEntityQuery(filters, AbstractVersionableEntity.class);
}
Aggregations