use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.
the class QueryFactoryShould method checkTypeCorrectAndFiltersEmpty.
private static void checkTypeCorrectAndFiltersEmpty(Class<TestEntity> expectedTargetClass, Query query) {
final Target entityTarget = checkTarget(expectedTargetClass, query);
final EntityFilters filters = entityTarget.getFilters();
assertNotNull(filters);
assertEquals(EntityFilters.getDefaultInstance(), filters);
}
use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.
the class QueryBuilderShould method create_queries_with_ids.
@Test
public void create_queries_with_ids() {
final int id1 = 314;
final int id2 = 271;
final Query query = factory().query().select(TestEntity.class).byId(id1, id2).build();
assertNotNull(query);
assertFalse(query.hasFieldMask());
final Target target = query.getTarget();
assertFalse(target.getIncludeAll());
final EntityFilters entityFilters = target.getFilters();
final EntityIdFilter idFilter = entityFilters.getIdFilter();
final Collection<EntityId> idValues = idFilter.getIdsList();
final Function<EntityId, Integer> transformer = new EntityIdUnpacker<>(int.class);
final Collection<Integer> intIdValues = transform(idValues, transformer);
assertSize(2, idValues);
assertThat(intIdValues, containsInAnyOrder(id1, id2));
}
use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.
the class QueryFactoryShould method checkIdQueriesEqual.
private static void checkIdQueriesEqual(Query query1, Query query2) {
assertNotEquals(query1.getId(), query2.getId());
final Target targetFromFactory = query1.getTarget();
final Target targetFromBuilder = query2.getTarget();
final EntityFilters filtersFromFactory = targetFromFactory.getFilters();
final EntityFilters filtersFromBuilder = targetFromBuilder.getFilters();
// Everything except filters is the same
assertEquals(targetFromFactory.toBuilder().clearFilters().build(), targetFromBuilder.toBuilder().clearFilters().build());
final EntityIdFilter idFilterFromFactory = filtersFromFactory.getIdFilter();
final EntityIdFilter idFilterFromBuilder = filtersFromBuilder.getIdFilter();
// Everything except ID filter is the same
assertEquals(filtersFromBuilder.toBuilder().clearIdFilter().build(), filtersFromBuilder.toBuilder().clearIdFilter().build());
final Collection<EntityId> entityIdsFromFactory = idFilterFromFactory.getIdsList();
final Collection<EntityId> entityIdsFromBuilder = idFilterFromBuilder.getIdsList();
// Order may differ but all the elements are the same
assertEquals(entityIdsFromFactory.size(), entityIdsFromBuilder.size());
assertContainsAll(entityIdsFromBuilder, entityIdsFromFactory.toArray(new EntityId[entityIdsFromBuilder.size()]));
}
use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.
the class QueryBuilderShould method create_queries_with_multiple_params.
@Test
public void create_queries_with_multiple_params() {
final String columnName1 = "myColumn";
final Object columnValue1 = 42;
final String columnName2 = "oneMore";
final Object columnValue2 = newMessageId();
final Query query = factory().query().select(TestEntity.class).where(eq(columnName1, columnValue1), eq(columnName2, columnValue2)).build();
assertNotNull(query);
final Target target = query.getTarget();
assertFalse(target.getIncludeAll());
final EntityFilters entityFilters = target.getFilters();
final Map<String, Any> columnFilters = entityFilters.getColumnFilterMap();
assertSize(2, columnFilters);
final Any actualValue1 = columnFilters.get(columnName1);
assertNotNull(actualValue1);
final int actualGenericValue1 = TypeConverter.toObject(actualValue1, int.class);
assertEquals(columnValue1, actualGenericValue1);
final Any actualValue2 = columnFilters.get(columnName2);
assertNotNull(actualValue2);
final Message actualGenericValue2 = TypeConverter.toObject(actualValue2, ProjectId.class);
assertEquals(columnValue2, actualGenericValue2);
}
use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.
the class EntityQueriesShould method construct_empty_queries.
@Test
public void construct_empty_queries() {
final EntityFilters filters = EntityFilters.getDefaultInstance();
final Class<? extends Entity> entityClass = AbstractEntity.class;
final EntityQuery<?> query = EntityQueries.from(filters, entityClass);
assertNotNull(query);
assertEmpty(query.getParameters());
assertTrue(query.getIds().isEmpty());
}
Aggregations