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