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);
}
}
Aggregations