Search in sources :

Example 36 with BoundedContext

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

the class AggregatePartShould method createNullPointerTester.

private NullPointerTester createNullPointerTester() throws NoSuchMethodException {
    final Constructor constructor = AnAggregateRoot.class.getDeclaredConstructor(BoundedContext.class, String.class);
    final NullPointerTester tester = new NullPointerTester();
    tester.setDefault(Constructor.class, constructor).setDefault(BoundedContext.class, boundedContext).setDefault(AggregateRoot.class, root);
    return tester;
}
Also used : Constructor(java.lang.reflect.Constructor) BoundedContext(io.spine.server.BoundedContext) NullPointerTester(com.google.common.testing.NullPointerTester)

Example 37 with BoundedContext

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

the class AggregateRootShould method pass_null_tolerance_test.

@Test
public void pass_null_tolerance_test() throws NoSuchMethodException {
    final Constructor<AnAggregateRoot> ctor = AnAggregateRoot.class.getDeclaredConstructor(BoundedContext.class, String.class);
    new NullPointerTester().setDefault(Constructor.class, ctor).setDefault(BoundedContext.class, boundedContext).testStaticMethods(AggregateRoot.class, NullPointerTester.Visibility.PACKAGE);
}
Also used : AnAggregateRoot(io.spine.server.aggregate.given.AggregateRootTestEnv.AnAggregateRoot) BoundedContext(io.spine.server.BoundedContext) NullPointerTester(com.google.common.testing.NullPointerTester) Test(org.junit.Test)

Example 38 with BoundedContext

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

the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_an_event_react.

/**
 * Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
 * value returned from a reaction on an event stores a single event.
 *
 * <p>The first event is produced while handling a command by the
 * {@link TaskAggregate#handle(AggAssignTask) TaskAggregate#handle(AggAssignTask)}.
 * Then as a reaction to this event a single event should be fired as part of the pair by
 * {@link TaskAggregate#on(AggTaskAssigned) TaskAggregate#on(AggTaskAssigned)}.
 */
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_an_event_react() {
    final BoundedContext boundedContext = newTaskBoundedContext();
    final TenantId tenantId = newTenantId();
    final Command command = command(assignTask(), tenantId);
    final MemoizingObserver<Ack> observer = memoizingObserver();
    boundedContext.getCommandBus().post(command, observer);
    assertNull(observer.getError());
    final List<Ack> responses = observer.responses();
    assertSize(1, responses);
    final Ack response = responses.get(0);
    final io.spine.core.Status status = response.getStatus();
    final Error emptyError = Error.getDefaultInstance();
    assertEquals(emptyError, status.getError());
    final Rejection emptyRejection = Rejection.getDefaultInstance();
    assertEquals(emptyRejection, status.getRejection());
    final List<Event> events = readAllEvents(boundedContext, tenantId);
    assertSize(2, events);
    final Event sourceEvent = events.get(0);
    final TypeUrl taskAssignedType = TypeUrl.from(AggTaskAssigned.getDescriptor());
    assertEquals(typeUrlOf(sourceEvent), taskAssignedType);
    final Event reactionEvent = events.get(1);
    final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
    assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) TypeUrl(io.spine.type.TypeUrl) AggregateMessageDispatcher.dispatchRejection(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection) Rejection(io.spine.core.Rejection) AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) AggregateTestEnv.newTaskBoundedContext(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext) Test(org.junit.Test)

Example 39 with BoundedContext

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

the class AggregateShould method create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react.

/**
 * Ensures that a {@linkplain io.spine.server.tuple.Pair pair} with an empty second optional
 * value returned from a reaction on a rejection stores a single event.
 *
 * <p>The rejection is fired by the {@link TaskAggregate#handle(AggReassignTask)
 * TaskAggregate.handle(AggReassignTask)}
 * and handled by the {@link TaskAggregate#on(Rejections.AggCannotReassignUnassignedTask)
 * TaskAggregate.on(AggCannotReassignUnassignedTask)}.
 */
@Test
public void create_single_event_for_a_pair_of_events_with_empty_for_a_rejection_react() {
    final BoundedContext boundedContext = newTaskBoundedContext();
    final TenantId tenantId = newTenantId();
    final Command command = command(reassignTask(), tenantId);
    final MemoizingObserver<Ack> observer = memoizingObserver();
    boundedContext.getCommandBus().post(command, observer);
    assertNull(observer.getError());
    final List<Ack> responses = observer.responses();
    assertSize(1, responses);
    final Ack response = responses.get(0);
    final io.spine.core.Status status = response.getStatus();
    final Error emptyError = Error.getDefaultInstance();
    assertEquals(emptyError, status.getError());
    final Rejection emptyRejection = Rejection.getDefaultInstance();
    assertEquals(emptyRejection, status.getRejection());
    final List<Event> events = readAllEvents(boundedContext, tenantId);
    assertSize(1, events);
    final Event reactionEvent = events.get(0);
    final TypeUrl userNotifiedType = TypeUrl.from(AggUserNotified.getDescriptor());
    assertEquals(typeUrlOf(reactionEvent), userNotifiedType);
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) TypeUrl(io.spine.type.TypeUrl) AggregateMessageDispatcher.dispatchRejection(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection) Rejection(io.spine.core.Rejection) AggregateTestEnv.newTenantId(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId) TenantId(io.spine.core.TenantId) Command(io.spine.core.Command) AggregateMessageDispatcher.dispatchCommand(io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) AggregateTestEnv.newTaskBoundedContext(io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext) Test(org.junit.Test)

Example 40 with BoundedContext

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

the class EventStoreServiceBuilderShould method setUp.

@Before
public void setUp() {
    final BoundedContext bc = BoundedContext.newBuilder().setMultitenant(true).build();
    storageFactory = bc.getStorageFactory();
    builder = EventStore.newServiceBuilder();
}
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