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);
}
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));
}
Aggregations