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);
}
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));
}
Aggregations