Search in sources :

Example 1 with EntityStateEnvelope

use of io.spine.server.entity.EntityStateEnvelope in project core-java by SpineEventEngine.

the class Stand method post.

/**
     * Posts the state of an {@link VersionableEntity} to this {@link Stand}.
     *
     * @param entity         the entity which state should be delivered to the {@code Stand}
     * @param commandContext the context of the command, which triggered the entity state update.
     */
public void post(final VersionableEntity entity, CommandContext commandContext) {
    final TenantId tenantId = commandContext.getActorContext().getTenantId();
    final EntityStateEnvelope envelope = EntityStateEnvelope.of(entity, tenantId);
    delivery.deliver(envelope);
}
Also used : TenantId(io.spine.users.TenantId) EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope)

Example 2 with EntityStateEnvelope

use of io.spine.server.entity.EntityStateEnvelope in project core-java by SpineEventEngine.

the class StandPostShould method deliver_updates.

// **** Positive scenarios (unit) ****
@SuppressWarnings({ "OverlyComplexAnonymousInnerClass", "ConstantConditions" })
@Test
public void deliver_updates() {
    final AggregateRepository<ProjectId, Given.StandTestAggregate> repository = Given.aggregateRepo();
    final ProjectId entityId = ProjectId.newBuilder().setId("PRJ-001").build();
    final Given.StandTestAggregate entity = repository.create(entityId);
    final StringValue state = entity.getState();
    final Version version = entity.getVersion();
    final Stand innerStand = Stand.newBuilder().build();
    final Stand stand = spy(innerStand);
    stand.post(entity, requestFactory.createCommandContext());
    final ArgumentMatcher<EntityStateEnvelope<?, ?>> argumentMatcher = new ArgumentMatcher<EntityStateEnvelope<?, ?>>() {

        @Override
        public boolean matches(EntityStateEnvelope<?, ?> argument) {
            final boolean entityIdMatches = argument.getEntityId().equals(entityId);
            final boolean versionMatches = version.equals(argument.getEntityVersion().orNull());
            final boolean stateMatches = argument.getMessage().equals(state);
            return entityIdMatches && versionMatches && stateMatches;
        }
    };
    verify(stand).update(ArgumentMatchers.argThat(argumentMatcher));
}
Also used : EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope) Versions.newVersion(io.spine.base.Versions.newVersion) Version(io.spine.base.Version) ArgumentMatcher(org.mockito.ArgumentMatcher) ProjectId(io.spine.test.projection.ProjectId) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 3 with EntityStateEnvelope

use of io.spine.server.entity.EntityStateEnvelope 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 = Identifiers.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(entity, context);
    final EntityStateEnvelope envelope = EntityStateEnvelope.of(entity, context.getActorContext().getTenantId());
    verify(delivery).deliverNow(eq(envelope), eq(Stand.class));
}
Also used : EntityStateEnvelope(io.spine.server.entity.EntityStateEnvelope) CommandContext(io.spine.base.CommandContext) StringValue(com.google.protobuf.StringValue) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Test(org.junit.Test)

Aggregations

EntityStateEnvelope (io.spine.server.entity.EntityStateEnvelope)3 StringValue (com.google.protobuf.StringValue)2 Test (org.junit.Test)2 CommandContext (io.spine.base.CommandContext)1 Version (io.spine.base.Version)1 Versions.newVersion (io.spine.base.Versions.newVersion)1 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)1 VersionableEntity (io.spine.server.entity.VersionableEntity)1 ProjectId (io.spine.test.projection.ProjectId)1 TenantId (io.spine.users.TenantId)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1