Search in sources :

Example 1 with VersionableEntity

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);
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.aggregate.ProjectId) SubscriptionUpdate(io.spine.client.SubscriptionUpdate) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 2 with VersionableEntity

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;
}
Also used : AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity)

Example 3 with VersionableEntity

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();
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.aggregate.ProjectId) SubscriptionUpdate(io.spine.client.SubscriptionUpdate) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Response(io.spine.core.Response) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 4 with VersionableEntity

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)));
}
Also used : EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope) CommandContext(io.spine.core.CommandContext) StringValue(com.google.protobuf.StringValue) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Test(org.junit.Test)

Aggregations

AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)4 VersionableEntity (io.spine.server.entity.VersionableEntity)4 Test (org.junit.Test)3 Message (com.google.protobuf.Message)2 Subscription (io.spine.client.Subscription)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 Target (io.spine.client.Target)2 Topic (io.spine.client.Topic)2 ProjectId (io.spine.test.aggregate.ProjectId)2 StringValue (com.google.protobuf.StringValue)1 CommandContext (io.spine.core.CommandContext)1 Response (io.spine.core.Response)1 EntityStateEnvelope (io.spine.server.entity.EntityStateEnvelope)1