Search in sources :

Example 6 with ColumnFilter

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);
}
Also used : ColumnFilter(io.spine.client.ColumnFilter) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 7 with ColumnFilter

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) ColumnFilter(io.spine.client.ColumnFilter) Test(org.junit.Test)

Example 8 with ColumnFilter

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

Example 9 with ColumnFilter

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);
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) Int32Value(com.google.protobuf.Int32Value) Test(org.junit.Test)

Example 10 with ColumnFilter

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));
}
Also used : Serializable(java.io.Serializable) TaskId(io.spine.test.entity.TaskId) EntityColumn(io.spine.server.entity.storage.EntityColumn) ColumnFilter(io.spine.client.ColumnFilter) QueryParameters(io.spine.server.entity.storage.QueryParameters) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) CompositeQueryParameter(io.spine.server.entity.storage.CompositeQueryParameter) EntityRecord(io.spine.server.entity.EntityRecord) 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