Search in sources :

Example 11 with ColumnFilter

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));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityColumn(io.spine.server.entity.storage.EntityColumn) ColumnFilter(io.spine.client.ColumnFilter) QueryParameters(io.spine.server.entity.storage.QueryParameters) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) CompositeQueryParameter(io.spine.server.entity.storage.CompositeQueryParameter) Test(org.junit.Test)

Example 12 with ColumnFilter

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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) StringValue(com.google.protobuf.StringValue) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 13 with ColumnFilter

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);
}
Also used : AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) ColumnFilter(io.spine.client.ColumnFilter) Test(org.junit.Test)

Example 14 with ColumnFilter

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);
}
Also used : AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) ColumnFilter(io.spine.client.ColumnFilter) Test(org.junit.Test)

Example 15 with ColumnFilter

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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) ColumnFilter(io.spine.client.ColumnFilter) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) Test(org.junit.Test)

Aggregations

ColumnFilter (io.spine.client.ColumnFilter)22 Test (org.junit.Test)17 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)12 EntityFilters (io.spine.client.EntityFilters)8 EntityRecord (io.spine.server.entity.EntityRecord)5 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)5 Any (com.google.protobuf.Any)4 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 Int32Value (com.google.protobuf.Int32Value)2 Timestamp (com.google.protobuf.Timestamp)2 Version (io.spine.core.Version)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 ERepository.toEntityFilters (io.spine.server.event.ERepository.toEntityFilters)2 Project (io.spine.test.storage.Project)2 EqualsTester (com.google.common.testing.EqualsTester)1 BoolValue (com.google.protobuf.BoolValue)1 FieldMask (com.google.protobuf.FieldMask)1 Message (com.google.protobuf.Message)1