Search in sources :

Example 66 with StringValue

use of com.google.protobuf.StringValue in project core-java by SpineEventEngine.

the class Given method validEvent.

static Event validEvent() {
    final Command cmd = validCommand();
    final PrjProjectCreated eventMessage = PrjProjectCreated.newBuilder().setProjectId(ProjectId.newBuilder().setId("12345AD0")).build();
    final StringValue producerId = toMessage(Given.class.getSimpleName());
    final EventFactory eventFactory = EventFactory.on(CommandEnvelope.of(cmd), Identifier.pack(producerId));
    final Event event = eventFactory.createEvent(eventMessage, Tests.<Version>nullRef());
    final Event result = event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(Enrichment.newBuilder().setDoNotEnrich(true)).build()).build();
    return result;
}
Also used : PrjProjectCreated(io.spine.test.projection.event.PrjProjectCreated) Command(io.spine.core.Command) EventFactory(io.spine.server.event.EventFactory) Event(io.spine.core.Event) StringValue(com.google.protobuf.StringValue)

Example 67 with StringValue

use of com.google.protobuf.StringValue 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)

Example 68 with StringValue

use of com.google.protobuf.StringValue 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(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
    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.core.Versions.newVersion) Version(io.spine.core.Version) ArgumentMatcher(org.mockito.ArgumentMatcher) ProjectId(io.spine.test.projection.ProjectId) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 69 with StringValue

use of com.google.protobuf.StringValue in project core-java by SpineEventEngine.

the class ColumnFiltersShould method create_ordering_filters_for_strings.

@Test
public void create_ordering_filters_for_strings() {
    final String string = "abc";
    final ColumnFilter filter = gt("stringColumn", string);
    assertNotNull(filter);
    assertEquals(GREATER_THAN, filter.getOperator());
    final StringValue value = AnyPacker.unpack(filter.getValue());
    assertEquals(string, value.getValue());
}
Also used : StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 70 with StringValue

use of com.google.protobuf.StringValue in project core-java by SpineEventEngine.

the class CommandAttributeShould method set_and_get_message_attribute.

@Test
public void set_and_get_message_attribute() {
    final CommandAttribute<StringValue> attr = new CommandAttribute<StringValue>("str-val") {
    };
    final StringValue value = toMessage(getClass().getName());
    assertSetGet(attr, value);
}
Also used : StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Aggregations

StringValue (com.google.protobuf.StringValue)75 Test (org.junit.Test)65 Timestamp (com.google.protobuf.Timestamp)8 Command (io.spine.base.Command)5 Command (io.spine.core.Command)5 Any (com.google.protobuf.Any)4 BoolValue (com.google.protobuf.BoolValue)4 Identifiers.idToString (io.spine.base.Identifiers.idToString)4 CommandContext (io.spine.core.CommandContext)4 Event (io.spine.core.Event)4 Wrapper.forString (io.spine.protobuf.Wrapper.forString)4 CommandBus (io.spine.server.commandbus.CommandBus)4 EventFactory (io.spine.server.event.EventFactory)4 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)4 Before (org.junit.Before)4 Optional (com.google.common.base.Optional)3 Message (com.google.protobuf.Message)3 Event (io.spine.base.Event)3 TestActorRequestFactory (io.spine.client.TestActorRequestFactory)3 CommandEnvelope (io.spine.core.CommandEnvelope)3