Search in sources :

Example 26 with Query

use of io.spine.client.Query 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 27 with Query

use of io.spine.client.Query 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)

Aggregations

Query (io.spine.client.Query)27 Test (org.junit.Test)23 Any (com.google.protobuf.Any)10 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 Target (io.spine.client.Target)6 Customer (io.spine.test.commandservice.customer.Customer)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 FieldMask (com.google.protobuf.FieldMask)5 Version (io.spine.base.Version)5 EntityFilters (io.spine.client.EntityFilters)5 QueryResponse (io.spine.client.QueryResponse)4 Message (com.google.protobuf.Message)3 EntityId (io.spine.client.EntityId)3 TestEntity (io.spine.test.client.TestEntity)3 CustomerId (io.spine.test.commandservice.customer.CustomerId)3 TypeUrl (io.spine.type.TypeUrl)3 EntityIdFilter (io.spine.client.EntityIdFilter)2 StandStorage (io.spine.server.stand.StandStorage)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1