Search in sources :

Example 1 with RejectionReactingRepository

use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingRepository in project core-java by SpineEventEngine.

the class AggregateRepositoryShould method allow_aggregates_react_on_rejections.

@Test
public void allow_aggregates_react_on_rejections() {
    boundedContext.register(new RejectingRepository());
    final RejectionReactingRepository repository = new RejectionReactingRepository();
    boundedContext.register(repository);
    final ProjectId parentId = givenAggregateId("rejectingParent");
    final ProjectId childId1 = givenAggregateId("acceptingChild-1");
    final ProjectId childId2 = givenAggregateId("acceptingChild-2");
    final ProjectId childId3 = givenAggregateId("acceptingChild-3");
    final StreamObserver<Ack> observer = StreamObservers.noOpObserver();
    final CommandBus commandBus = boundedContext.getCommandBus();
    // Create the parent project.
    final ImmutableSet<ProjectId> childProjects = ImmutableSet.of(childId1, childId2, childId3);
    final Command createParent = requestFactory.createCommand(AggCreateProjectWithChildren.newBuilder().setProjectId(parentId).addAllChildProjectId(childProjects).build());
    commandBus.post(createParent, observer);
    // Fire a command which would cause rejection.
    final Command startProject = requestFactory.createCommand(AggStartProjectWithChildren.newBuilder().setProjectId(parentId).build());
    commandBus.post(startProject, observer);
    for (ProjectId childProject : childProjects) {
        final Optional<RejectionReactingAggregate> optional = repository.find(childProject);
        assertTrue(optional.isPresent());
        // Check that all the aggregates:
        // 1. got Rejections.AggCannotStartArchivedProject;
        // 2. produced the state the event;
        // 3. applied the event.
        final String value = optional.get().getState().getValue();
        assertEquals(RejectionReactingAggregate.PARENT_ARCHIVED, value);
    }
}
Also used : RejectingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectingRepository) RejectionReactingRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingRepository) Command(io.spine.core.Command) RejectionReactingAggregate(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingAggregate) ProjectId(io.spine.test.aggregate.ProjectId) Ack(io.spine.core.Ack) CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Aggregations

Ack (io.spine.core.Ack)1 Command (io.spine.core.Command)1 RejectingRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectingRepository)1 RejectionReactingAggregate (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingAggregate)1 RejectionReactingRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.RejectionReactingRepository)1 CommandBus (io.spine.server.commandbus.CommandBus)1 ProjectId (io.spine.test.aggregate.ProjectId)1 Test (org.junit.Test)1