use of io.spine.server.entity.VersionableEntity 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);
}
use of io.spine.server.entity.VersionableEntity in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method mockEntity.
private static VersionableEntity mockEntity(ProjectId projectId, Message projectState, int version) {
final VersionableEntity entity = mock(AbstractVersionableEntity.class);
when(entity.getState()).thenReturn(projectState);
when(entity.getId()).thenReturn(projectId);
when(entity.getVersion()).thenReturn(newVersion(version, Time.getCurrentTime()));
return entity;
}
use of io.spine.server.entity.VersionableEntity in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method cancel_subscription_on_topic.
@Test
public void cancel_subscription_on_topic() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe
final MemoizeStreamObserver<Subscription> subscribeObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscribeObserver);
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activateSubscription = spy(new MemoizeStreamObserver<SubscriptionUpdate>());
subscriptionService.activate(subscribeObserver.streamFlowValue, activateSubscription);
// Cancel subscription
subscriptionService.cancel(subscribeObserver.streamFlowValue, new MemoizeStreamObserver<Response>());
// Post update to Stand
final ProjectId projectId = ProjectId.newBuilder().setId("some-other-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);
// The update must not be handled by the observer
verify(activateSubscription, never()).onNext(any(SubscriptionUpdate.class));
verify(activateSubscription, never()).onCompleted();
}
use of io.spine.server.entity.VersionableEntity in project core-java by SpineEventEngine.
the class StandPostShould method use_delivery_from_builder.
@SuppressWarnings("MagicNumber")
@Test
public void use_delivery_from_builder() {
final StandUpdateDelivery delivery = spy(new StandUpdateDelivery() {
@Override
protected boolean shouldPostponeDelivery(EntityStateEnvelope deliverable, Stand consumer) {
return false;
}
});
final Stand.Builder builder = Stand.newBuilder().setDelivery(delivery);
final Stand stand = builder.build();
Assert.assertNotNull(stand);
final Object id = Identifier.newUuid();
final StringValue state = StringValue.getDefaultInstance();
final VersionableEntity entity = mock(AbstractVersionableEntity.class);
when(entity.getState()).thenReturn(state);
when(entity.getId()).thenReturn(id);
when(entity.getVersion()).thenReturn(newVersion(17, Time.getCurrentTime()));
final CommandContext context = requestFactory.createCommandContext();
stand.post(context.getActorContext().getTenantId(), entity);
final EntityStateEnvelope envelope = EntityStateEnvelope.of(entity, context.getActorContext().getTenantId());
verify(delivery).deliverNow(eq(envelope), eq(Consumers.idOf(stand)));
}
Aggregations