Search in sources :

Example 11 with EntityId

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

EntityId (io.spine.client.EntityId)11 Test (org.junit.Test)8 Any (com.google.protobuf.Any)7 EntityFilters (io.spine.client.EntityFilters)7 EntityIdFilter (io.spine.client.EntityIdFilter)7 Message (com.google.protobuf.Message)5 Query (io.spine.client.Query)3 Target (io.spine.client.Target)3 FieldMask (com.google.protobuf.FieldMask)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 BoolValue (com.google.protobuf.BoolValue)1 Descriptors (com.google.protobuf.Descriptors)1 StringValue (com.google.protobuf.StringValue)1 Identifiers.idToAny (io.spine.base.Identifiers.idToAny)1 Version (io.spine.base.Version)1 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)1 EntityRecord (io.spine.server.entity.EntityRecord)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 TestEntity (io.spine.test.client.TestEntity)1