Search in sources :

Example 1 with EntityId

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

the class TopicFactoryShould method create_topic_for_some_entities_of_kind.

@Test
public void create_topic_for_some_entities_of_kind() {
    final Set<TestEntityId> ids = newHashSet(entityId(1), entityId(2), entityId(3));
    final Topic topic = factory().topic().someOf(TARGET_ENTITY_CLASS, ids);
    verifyTargetAndContext(topic);
    final List<EntityId> actualIds = topic.getTarget().getFilters().getIdFilter().getIdsList();
    assertEquals(ids.size(), actualIds.size());
    for (EntityId actualId : actualIds) {
        final Any rawId = actualId.getId();
        final TestEntityId unpackedId = AnyPacker.unpack(rawId);
        assertTrue(ids.contains(unpackedId));
    }
}
Also used : TestEntityId(io.spine.test.client.TestEntityId) EntityId(io.spine.client.EntityId) TestEntityId(io.spine.test.client.TestEntityId) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 2 with EntityId

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

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

the class EntityIdFunctionShould method do_not_accept_wrong_id_type.

@Test(expected = IllegalStateException.class)
public void do_not_accept_wrong_id_type() {
    final Function<EntityId, StringValue> func = new RecordBasedRepository.EntityIdFunction<>(StringValue.class);
    final EntityId wrongType = EntityId.newBuilder().setId(Wrapper.forLong().pack(100L)).build();
    func.apply(wrongType);
}
Also used : EntityId(io.spine.client.EntityId) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 4 with EntityId

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

the class SubscriptionRecord method matchByFilters.

private static boolean matchByFilters(Object id, EntityFilters filters) {
    final boolean result;
    final EntityIdFilter givenIdFilter = filters.getIdFilter();
    final boolean idFilterSet = !EntityIdFilter.getDefaultInstance().equals(givenIdFilter);
    if (idFilterSet) {
        final Any idAsAny = Identifiers.idToAny(id);
        final EntityId givenEntityId = EntityId.newBuilder().setId(idAsAny).build();
        final List<EntityId> idsList = givenIdFilter.getIdsList();
        result = idsList.contains(givenEntityId);
    } else {
        result = false;
    }
    return result;
}
Also used : EntityId(io.spine.client.EntityId) EntityIdFilter(io.spine.client.EntityIdFilter) Any(com.google.protobuf.Any)

Example 5 with EntityId

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

the class StandShould method entityFilterMatcher.

@SuppressWarnings("OverlyComplexAnonymousInnerClass")
private static ArgumentMatcher<EntityFilters> entityFilterMatcher(final Collection<ProjectId> projectIds) {
    // ALL the expected IDs.
    return new ArgumentMatcher<EntityFilters>() {

        @Override
        public boolean matches(EntityFilters argument) {
            boolean everyElementPresent = true;
            for (EntityId entityId : argument.getIdFilter().getIdsList()) {
                final Any idAsAny = entityId.getId();
                final Message rawId = AnyPacker.unpack(idAsAny);
                if (rawId instanceof ProjectId) {
                    final ProjectId convertedProjectId = (ProjectId) rawId;
                    everyElementPresent = everyElementPresent && projectIds.contains(convertedProjectId);
                } else {
                    everyElementPresent = false;
                }
            }
            return everyElementPresent;
        }
    };
}
Also used : EntityId(io.spine.client.EntityId) Message(com.google.protobuf.Message) ArgumentMatcher(org.mockito.ArgumentMatcher) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.projection.ProjectId) Any(com.google.protobuf.Any)

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