Search in sources :

Example 96 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class IntegrationBusShould method dispatch_events_from_one_BC_to_external_subscribers_of_another_BC.

@Test
public void dispatch_events_from_one_BC_to_external_subscribers_of_another_BC() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    contextWithExternalSubscribers(transportFactory);
    assertNull(ProjectEventsSubscriber.getExternalEvent());
    final Event event = projectCreated();
    sourceContext.getEventBus().post(event);
    assertEquals(AnyPacker.unpack(event.getMessage()), ProjectEventsSubscriber.getExternalEvent());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 97 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class IntegrationBusShould method emit_unsupported_external_message_exception_if_message_type_is_unknown.

@Test
public void emit_unsupported_external_message_exception_if_message_type_is_unknown() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext boundedContext = contextWithTransport(transportFactory);
    final Event event = projectCreated();
    final BoundedContextName boundedContextName = BoundedContext.newName("External context ID");
    final ExternalMessage externalMessage = ExternalMessages.of(event, boundedContextName);
    final MemoizingObserver<Ack> observer = StreamObservers.memoizingObserver();
    boundedContext.getIntegrationBus().post(externalMessage, observer);
    final Error error = observer.firstResponse().getStatus().getError();
    assertFalse(Validate.isDefault(error));
    assertEquals(ExternalMessageValidationError.getDescriptor().getFullName(), error.getType());
    assertTrue(UNSUPPORTED_EXTERNAL_MESSAGE.getNumber() == error.getCode());
}
Also used : Ack(io.spine.core.Ack) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) Error(io.spine.base.Error) BoundedContext(io.spine.server.BoundedContext) BoundedContextName(io.spine.core.BoundedContextName) Test(org.junit.Test)

Example 98 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class IntegrationBusShould method avoid_dispatching_events_from_one_BC_to_domestic_entity_subscribers_of_another_BC.

@Test
public void avoid_dispatching_events_from_one_BC_to_domestic_entity_subscribers_of_another_BC() {
    final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
    final BoundedContext sourceContext = contextWithTransport(transportFactory);
    final BoundedContext destContext = contextWithExtEntitySubscribers(transportFactory);
    assertNull(ProjectDetails.getDomesticEvent());
    final Event event = projectStarted();
    sourceContext.getEventBus().post(event);
    assertNotEquals(AnyPacker.unpack(event.getMessage()), ProjectDetails.getDomesticEvent());
    assertNull(ProjectDetails.getDomesticEvent());
    destContext.getEventBus().post(event);
    assertEquals(AnyPacker.unpack(event.getMessage()), ProjectDetails.getDomesticEvent());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 99 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class PmMessageDeliveryShould method postpone_events_dispatched_to_reactor_method.

@Test
public void postpone_events_dispatched_to_reactor_method() {
    assertNull(ReactingProjectWizard.getEventReceived());
    final Event event = projectStarted();
    boundedContext.getEventBus().post(event);
    assertNull(ReactingProjectWizard.getEventReceived());
    final EventEnvelope expectedEnvelope = EventEnvelope.of(event);
    final PostponingEventDelivery delivery = repository.getEventEndpointDelivery();
    final Map<ProjectId, EventEnvelope> postponedEvents = delivery.getPostponedEvents();
    assertTrue(postponedEvents.size() == 1 && postponedEvents.containsValue(expectedEnvelope));
    final ProjectId projectId = postponedEvents.keySet().iterator().next();
    delivery.deliverNow(projectId, postponedEvents.get(projectId));
    final PmProjectStarted deliveredEventMsg = ReactingProjectWizard.getEventReceived();
    assertNotNull(deliveredEventMsg);
    assertEquals(Events.getMessage(event), deliveredEventMsg);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) ProjectId(io.spine.test.procman.ProjectId) Event(io.spine.core.Event) PmProjectStarted(io.spine.test.procman.event.PmProjectStarted) PostponingEventDelivery(io.spine.server.procman.given.PmMessageDeliveryTestEnv.PostponingEventDelivery) Test(org.junit.Test)

Example 100 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class PmMessageDeliveryTestEnv method projectStarted.

public static Event projectStarted() {
    final ProjectId projectId = projectId();
    final TestEventFactory eventFactory = TestEventFactory.newInstance(AnyPacker.pack(projectId), PmMessageDeliveryTestEnv.class);
    final PmProjectStarted msg = PmProjectStarted.newBuilder().setProjectId(projectId).build();
    final Event result = eventFactory.createEvent(msg);
    return result;
}
Also used : TestEventFactory(io.spine.server.command.TestEventFactory) ProjectId(io.spine.test.procman.ProjectId) Event(io.spine.core.Event) PmProjectStarted(io.spine.test.procman.event.PmProjectStarted)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3