use of io.spine.client.Target 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.Target in project core-java by SpineEventEngine.
the class QueryBuilderShould method create_queries_with_type_only.
@Test
public void create_queries_with_type_only() {
final Class<? extends Message> testEntityClass = TestEntity.class;
final Query query = factory().query().select(testEntityClass).build();
assertNotNull(query);
assertFalse(query.hasFieldMask());
final Target target = query.getTarget();
assertTrue(target.getIncludeAll());
assertEquals(TypeName.of(testEntityClass).value(), target.getType());
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method handle_cancellation_process_exceptions_and_call_observer_error_callback.
@Test
public void handle_cancellation_process_exceptions_and_call_observer_error_callback() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscriptionObserver);
final String rejectionMessage = "Execution breaking exception";
final MemoizeStreamObserver<Response> observer = new MemoizeStreamObserver<Response>() {
@Override
public void onNext(Response value) {
super.onNext(value);
throw new RuntimeException(rejectionMessage);
}
};
subscriptionService.cancel(subscriptionObserver.streamFlowValue, observer);
assertNotNull(observer.streamFlowValue);
assertFalse(observer.isCompleted);
assertNotNull(observer.throwable);
assertInstanceOf(RuntimeException.class, observer.throwable);
assertEquals(observer.throwable.getMessage(), rejectionMessage);
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method subscribe_to_topic.
/*
* Subscription tests
* ------------------
*/
@Test
public void subscribe_to_topic() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final String type = boundedContext.getStand().getExposedTypes().iterator().next().value();
final Target target = getProjectQueryTarget();
assertEquals(type, target.getType());
final Topic topic = requestFactory.topic().forTarget(target);
final MemoizeStreamObserver<Subscription> observer = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, observer);
assertNotNull(observer.streamFlowValue);
assertTrue(observer.streamFlowValue.isInitialized());
assertEquals(observer.streamFlowValue.getTopic().getTarget().getType(), type);
assertNull(observer.throwable);
assertTrue(observer.isCompleted);
}
use of io.spine.client.Target in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method activate_subscription.
@Test
public void activate_subscription() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe to the topic
final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscriptionObserver);
subscriptionObserver.verifyState();
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activationObserver = new MemoizeStreamObserver<>();
subscriptionService.activate(subscriptionObserver.streamFlowValue, activationObserver);
// Post update to Stand directly
final ProjectId projectId = ProjectId.newBuilder().setId("some-id").build();
final Message projectState = Project.newBuilder().setId(projectId).build();
final int version = 1;
final VersionableEntity entity = mockEntity(projectId, projectState, version);
boundedContext.getStand().post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
// isCompleted set to false since we don't expect activationObserver::onCompleted to be called.
activationObserver.verifyState(false);
}
Aggregations