Search in sources :

Example 21 with ColumnFilter

use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.

the class RecordStorageShould method update_entity_column_values.

@Test
public void update_entity_column_values() {
    final Project.Status initialStatus = DONE;
    // is used for documentation purposes.
    @SuppressWarnings("UnnecessaryLocalVariable") final Project.Status statusAfterUpdate = CANCELLED;
    final Int32Value initialStatusValue = Int32Value.newBuilder().setValue(initialStatus.getNumber()).build();
    final ColumnFilter status = eq("projectStatusValue", initialStatusValue);
    final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).build();
    final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
    final RecordStorage<I> storage = getStorage();
    final EntityQuery<I> query = EntityQueries.from(filters, storage);
    final I id = newId();
    final TestCounterEntity<I> entity = new TestCounterEntity<>(id);
    entity.setStatus(initialStatus);
    final EntityRecord record = newStorageRecord(id, newState(id));
    final EntityRecordWithColumns recordWithColumns = create(record, entity, storage);
    final FieldMask fieldMask = FieldMask.getDefaultInstance();
    // Create the record.
    storage.write(id, recordWithColumns);
    final Iterator<EntityRecord> recordsBefore = storage.readAll(query, fieldMask);
    assertSingleRecord(record, recordsBefore);
    // Update the entity columns of the record.
    entity.setStatus(statusAfterUpdate);
    final EntityRecordWithColumns updatedRecordWithColumns = create(record, entity, storage);
    storage.write(id, updatedRecordWithColumns);
    final Iterator<EntityRecord> recordsAfter = storage.readAll(query, fieldMask);
    assertFalse(recordsAfter.hasNext());
}
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) Int32Value(com.google.protobuf.Int32Value) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 22 with ColumnFilter

use of io.spine.client.ColumnFilter in project core-java by SpineEventEngine.

the class EntityQueryMatcherShould method match_Any_instances.

@Test
public void match_Any_instances() {
    final String columnName = "column";
    final Project someMessage = Sample.messageOfType(Project.class);
    final Any actualValue = AnyPacker.pack(someMessage);
    final EntityColumn column = mock(EntityColumn.class);
    when(column.getType()).thenReturn(Any.class);
    when(column.getStoredName()).thenReturn(columnName);
    final EntityColumn.MemoizedValue value = mock(EntityColumn.MemoizedValue.class);
    when(value.getSourceColumn()).thenReturn(column);
    when(value.getValue()).thenReturn(actualValue);
    final EntityRecord record = Sample.messageOfType(EntityRecord.class);
    final Map<String, EntityColumn.MemoizedValue> columns = singletonMap(columnName, value);
    final EntityRecordWithColumns recordWithColumns = createRecord(record, columns);
    final Multimap<EntityColumn, ColumnFilter> filters = of(column, eq(columnName, actualValue));
    final CompositeQueryParameter parameter = createParams(filters, ALL);
    final QueryParameters parameters = QueryParameters.newBuilder().add(parameter).build();
    final EntityQuery<?> query = createQuery(emptySet(), parameters);
    final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
    assertTrue(matcher.apply(recordWithColumns));
}
Also used : 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) Project(io.spine.test.entity.Project) 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