Search in sources :

Example 21 with EntityRecordWithColumns

use of io.spine.server.entity.storage.EntityRecordWithColumns in project core-java by SpineEventEngine.

the class RecordStorageShould method allow_by_single_id_queries_with_no_columns.

@Test
public void allow_by_single_id_queries_with_no_columns() {
    // Create the test data
    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);
    final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
    final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
    final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
    final RecordStorage<I> storage = getStorage();
    final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity, storage);
    final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1, storage);
    final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2, storage);
    // Fill the storage
    storage.write(idWrong1, recordWrong1);
    storage.write(idMatching, recordRight);
    storage.write(idWrong2, recordWrong2);
    // Prepare the query
    final Any matchingIdPacked = TypeConverter.toAny(idMatching);
    final EntityId entityId = EntityId.newBuilder().setId(matchingIdPacked).build();
    final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(entityId).build();
    final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).build();
    final EntityQuery<I> query = EntityQueries.from(filters, storage);
    // Perform the query
    final Iterator<EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
    // Check results
    assertSingleRecord(fineRecord, readRecords);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityId(io.spine.client.EntityId) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) Test(org.junit.Test)

Example 22 with EntityRecordWithColumns

use of io.spine.server.entity.storage.EntityRecordWithColumns 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

EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)22 EntityRecord (io.spine.server.entity.EntityRecord)14 Test (org.junit.Test)12 Any (com.google.protobuf.Any)7 ColumnFilter (io.spine.client.ColumnFilter)5 Message (com.google.protobuf.Message)3 EntityFilters (io.spine.client.EntityFilters)3 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 Project (io.spine.test.storage.Project)3 Int32Value (com.google.protobuf.Int32Value)2 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)2 TypeUrl (io.spine.type.TypeUrl)2 HashMap (java.util.HashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newConcurrentMap (com.google.common.collect.Maps.newConcurrentMap)1 FieldMask (com.google.protobuf.FieldMask)1