Search in sources :

Example 16 with EntityFilters

use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.

the class QueryBuilderShould method create_queries_with_param.

@Test
public void create_queries_with_param() {
    final String columnName = "myImaginaryColumn";
    final Object columnValue = 42;
    final Query query = factory().query().select(TestEntity.class).where(eq(columnName, columnValue)).build();
    assertNotNull(query);
    final Target target = query.getTarget();
    assertFalse(target.getIncludeAll());
    final EntityFilters entityFilters = target.getFilters();
    final Map<String, Any> columnFilters = entityFilters.getColumnFilterMap();
    assertSize(1, columnFilters);
    final Any actualValue = columnFilters.get(columnName);
    assertNotNull(columnValue);
    final Int32Value messageValue = AnyPacker.unpack(actualValue);
    final int actualGenericValue = messageValue.getValue();
    assertEquals(columnValue, actualGenericValue);
}
Also used : Target(io.spine.client.Target) Query(io.spine.client.Query) EntityFilters(io.spine.client.EntityFilters) Int32Value(com.google.protobuf.Int32Value) Matchers.containsString(org.hamcrest.Matchers.containsString) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 17 with EntityFilters

use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.

the class QueryBuilderShould method persist_only_last_ids_clause.

@Test
public void persist_only_last_ids_clause() {
    final Iterable<?> genericIds = asList(newUuid(), -1, newMessageId());
    final Long[] longIds = { 1L, 2L, 3L };
    final Message[] messageIds = { newMessageId(), newMessageId(), newMessageId() };
    final String[] stringIds = { newUuid(), newUuid(), newUuid() };
    final Integer[] intIds = { 4, 5, 6 };
    final Query query = factory().query().select(TestEntity.class).byId(genericIds).byId(longIds).byId(stringIds).byId(intIds).byId(messageIds).build();
    assertNotNull(query);
    final Target target = query.getTarget();
    final EntityFilters filters = target.getFilters();
    final Collection<EntityId> entityIds = filters.getIdFilter().getIdsList();
    assertSize(messageIds.length, entityIds);
    final Function<EntityId, ProjectId> transformer = new EntityIdUnpacker<>(ProjectId.class);
    final Iterable<? extends Message> actualValues = transform(entityIds, transformer);
    assertThat(actualValues, containsInAnyOrder(messageIds));
}
Also used : Message(com.google.protobuf.Message) Query(io.spine.client.Query) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.validate.msg.ProjectId) Matchers.containsString(org.hamcrest.Matchers.containsString) EntityId(io.spine.client.EntityId) Target(io.spine.client.Target) Test(org.junit.Test)

Example 18 with EntityFilters

use of io.spine.client.EntityFilters in project core-java by SpineEventEngine.

the class EntityQueriesShould method construct_non_empty_queries.

@Test
public void construct_non_empty_queries() {
    final Message someGenericId = Sample.messageOfType(ProjectId.class);
    final Any someId = AnyPacker.pack(someGenericId);
    final EntityId entityId = EntityId.newBuilder().setId(someId).build();
    final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(entityId).build();
    final Version versionValue = Version.newBuilder().setNumber(1).build();
    final BoolValue archivedValue = BoolValue.newBuilder().setValue(true).build();
    final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).putColumnFilter("version", AnyPacker.pack(versionValue)).putColumnFilter("archived", AnyPacker.pack(archivedValue)).build();
    final Class<? extends Entity> entityClass = AbstractVersionableEntity.class;
    final EntityQuery<?> query = EntityQueries.from(filters, entityClass);
    assertNotNull(query);
    assertSize(2, query.getParameters());
    final Collection<?> ids = query.getIds();
    assertFalse(ids.isEmpty());
    assertSize(1, ids);
    final Object singleId = ids.iterator().next();
    assertEquals(someGenericId, singleId);
    final Map<Column<?>, Object> params = query.getParameters();
    final Collection<Object> values = params.values();
    assertContains(versionValue, values);
    assertContains(archivedValue.getValue(), values);
}
Also used : Message(com.google.protobuf.Message) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) BoolValue(com.google.protobuf.BoolValue) Any(com.google.protobuf.Any) EntityId(io.spine.client.EntityId) Version(io.spine.base.Version) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) 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