Search in sources :

Example 51 with BoundedContext

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

the class ProjectionRepositoryShould method throw_exception_on_attempt_to_register_in_bc_with_no_messages_handled.

@Test(expected = IllegalStateException.class)
public void throw_exception_on_attempt_to_register_in_bc_with_no_messages_handled() {
    final SensoryDeprivedProjectionRepository repo = new SensoryDeprivedProjectionRepository();
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(false).build();
    repo.setBoundedContext(boundedContext);
    repo.onRegistered();
}
Also used : SensoryDeprivedProjectionRepository(io.spine.server.projection.given.ProjectionRepositoryTestEnv.SensoryDeprivedProjectionRepository) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 52 with BoundedContext

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

the class ProcessManagerRepository method onRegistered.

/**
 * {@inheritDoc}
 *
 * <p>Registers with the {@code CommandBus} for dispatching commands
 * (via {@linkplain DelegatingCommandDispatcher delegating dispatcher}).
 *
 * <p>Registers with the {@code IntegrationBus} for dispatching external events and rejections.
 *
 * <p>Ensures there is at least one message handler declared by the class of the managed
 * process manager:
 *
 * <ul>
 *     <li>command handler methods;</li>
 *     <li>domestic or external event reactor methods;</li>
 *     <li>domestic or external rejection reactor methods.</li>
 * </ul>
 *
 * <p>Throws an {@code IllegalStateException} otherwise.
 */
// It's fine, as reflects the logic.
@SuppressWarnings("MethodWithMoreThanThreeNegations")
@Override
public void onRegistered() {
    super.onRegistered();
    final BoundedContext boundedContext = getBoundedContext();
    final DelegatingRejectionDispatcher<I> rejDispatcher = DelegatingRejectionDispatcher.of(this);
    final boolean handlesCommands = register(boundedContext.getCommandBus(), DelegatingCommandDispatcher.of(this));
    final boolean handlesDomesticRejections = register(boundedContext.getRejectionBus(), rejDispatcher);
    final boolean handlesExternalRejections = register(boundedContext.getIntegrationBus(), rejDispatcher.getExternalDispatcher());
    final boolean handlesDomesticEvents = !getMessageClasses().isEmpty();
    final boolean handlesExternalEvents = !getExternalEventDispatcher().getMessageClasses().isEmpty();
    final boolean subscribesToEvents = handlesDomesticEvents || handlesExternalEvents;
    final boolean reactsUponRejections = handlesDomesticRejections || handlesExternalRejections;
    if (!handlesCommands && !subscribesToEvents && !reactsUponRejections) {
        throw newIllegalStateException("Process managers of the repository %s have no command handlers, " + "and do not react upon any rejections or events.", this);
    }
    this.commandErrorHandler = CommandErrorHandler.with(boundedContext.getRejectionBus());
}
Also used : SPI(io.spine.annotation.SPI) BoundedContext(io.spine.server.BoundedContext)

Example 53 with BoundedContext

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

the class BoundedContextShould method not_notify_integration_event_subscriber_if_event_is_invalid.

@Test
public void not_notify_integration_event_subscriber_if_event_is_invalid() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(true).build();
    // Unsupported message.
    final Any invalidMsg = AnyPacker.pack(BcProjectCreated.getDefaultInstance());
    final IntegrationEvent event = Given.AnIntegrationEvent.projectCreated().toBuilder().setMessage(invalidMsg).build();
    final MemoizingObserver<Ack> observer = memoizingObserver();
    boundedContext.notify(event, observer);
    assertEquals(ERROR, observer.firstResponse().getStatus().getStatusCase());
}
Also used : Ack(io.spine.core.Ack) IntegrationEvent(io.spine.server.integration.IntegrationEvent) BoundedContext(io.spine.server.BoundedContext) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 54 with BoundedContext

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

the class BoundedContextShould method propagate_registered_repositories_to_stand.

@Test
public void propagate_registered_repositories_to_stand() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().build();
    final Stand stand = Spy.ofClass(Stand.class).on(boundedContext);
    verify(stand, never()).registerTypeSupplier(any(Repository.class));
    final ProjectAggregateRepository repository = new ProjectAggregateRepository();
    boundedContext.register(repository);
    verify(stand).registerTypeSupplier(eq(repository));
}
Also used : Stand(io.spine.server.stand.Stand) ProjectReportRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectReportRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) SecretProjectRepository(io.spine.server.bc.given.BoundedContextTestEnv.SecretProjectRepository) Repository(io.spine.server.entity.Repository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) AnotherProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.AnotherProjectAggregateRepository) ProjectAggregateRepository(io.spine.server.bc.given.BoundedContextTestEnv.ProjectAggregateRepository) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 55 with BoundedContext

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

the class CommandDispatcherRegistryShould method setUp.

@Before
public void setUp() {
    ModelTests.clearModel();
    final BoundedContext boundedContext = BoundedContext.newBuilder().setName(getClass().getSimpleName()).build();
    eventBus = boundedContext.getEventBus();
    registry = new CommandDispatcherRegistry();
}
Also used : BoundedContext(io.spine.server.BoundedContext) Before(org.junit.Before)

Aggregations

BoundedContext (io.spine.server.BoundedContext)58 Test (org.junit.Test)34 Event (io.spine.core.Event)12 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)12 Before (org.junit.Before)9 Rejection (io.spine.core.Rejection)6 Ack (io.spine.core.Ack)5 Message (com.google.protobuf.Message)4 Error (io.spine.base.Error)4 TypeUrl (io.spine.type.TypeUrl)4 Any (com.google.protobuf.Any)3 StringValue (com.google.protobuf.StringValue)3 Command (io.spine.core.Command)3 CommandEnvelope (io.spine.core.CommandEnvelope)3 TenantId (io.spine.core.TenantId)3 CustomerAggregateRepository (io.spine.server.Given.CustomerAggregateRepository)3 EventBus (io.spine.server.event.EventBus)3 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 NullPointerTester (com.google.common.testing.NullPointerTester)2