Search in sources :

Example 1 with QueryParameters

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

Example 2 with QueryParameters

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

use of io.spine.server.entity.storage.QueryParameters 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)3 EntityRecord (io.spine.server.entity.EntityRecord)3 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 Test (org.junit.Test)3 Any (com.google.protobuf.Any)2 Project (io.spine.test.entity.Project)1 TaskId (io.spine.test.entity.TaskId)1 Serializable (java.io.Serializable)1