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