Search in sources :

Example 1 with EntityFilters

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);
}
Also used : EntityFilters(io.spine.client.EntityFilters)

Example 2 with EntityFilters

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));
}
Also used : EntityId(io.spine.client.EntityId) Target(io.spine.client.Target) Query(io.spine.client.Query) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) Test(org.junit.Test)

Example 3 with EntityFilters

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()]));
}
Also used : TestEntityId(io.spine.test.client.TestEntityId) EntityFilters(io.spine.client.EntityFilters)

Example 4 with EntityFilters

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);
}
Also used : Target(io.spine.client.Target) Query(io.spine.client.Query) Message(com.google.protobuf.Message) EntityFilters(io.spine.client.EntityFilters) Matchers.containsString(org.hamcrest.Matchers.containsString) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 5 with EntityFilters

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());
}
Also used : AbstractEntity(io.spine.server.entity.AbstractEntity) EntityFilters(io.spine.client.EntityFilters) Test(org.junit.Test)

Aggregations

EntityFilters (io.spine.client.EntityFilters)18 Test (org.junit.Test)11 Any (com.google.protobuf.Any)7 Message (com.google.protobuf.Message)7 EntityId (io.spine.client.EntityId)7 EntityIdFilter (io.spine.client.EntityIdFilter)6 Target (io.spine.client.Target)6 Query (io.spine.client.Query)5 FieldMask (com.google.protobuf.FieldMask)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 EntityRecord (io.spine.server.entity.EntityRecord)3 Int32Value (com.google.protobuf.Int32Value)2 Version (io.spine.base.Version)2 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 ProjectId (io.spine.test.projection.ProjectId)2 ImmutableList (com.google.common.collect.ImmutableList)1 BoolValue (com.google.protobuf.BoolValue)1 Descriptors (com.google.protobuf.Descriptors)1 StringValue (com.google.protobuf.StringValue)1