use of io.spine.test.aggregate.event.AggProjectArchived in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method route_events_to_aggregates.
@Test
public void route_events_to_aggregates() {
final ProjectAggregate parent = givenStoredAggregate();
final ProjectAggregate child = givenStoredAggregate();
assertTrue(repository.find(parent.getId()).isPresent());
assertTrue(repository.find(child.getId()).isPresent());
final TestEventFactory factory = TestEventFactory.newInstance(getClass());
final AggProjectArchived msg = AggProjectArchived.newBuilder().setProjectId(parent.getId()).addChildProjectId(child.getId()).build();
final Event event = factory.createEvent(msg);
boundedContext.getEventBus().post(event);
// Check that the child aggregate was archived.
final Optional<ProjectAggregate> childAfterArchive = repository.find(child.getId());
assertTrue(childAfterArchive.isPresent());
assertTrue(childAfterArchive.get().isArchived());
// The parent should not be archived since the dispatch route uses only
// child aggregates from the `ProjectArchived` event.
final Optional<ProjectAggregate> parentAfterArchive = repository.find(parent.getId());
assertTrue(parentAfterArchive.isPresent());
assertFalse(parentAfterArchive.get().isArchived());
}
use of io.spine.test.aggregate.event.AggProjectArchived in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method allow_aggregates_react_on_events.
@Test
public void allow_aggregates_react_on_events() {
final ReactingRepository repository = new ReactingRepository();
boundedContext.register(repository);
final ProjectId parentId = givenAggregateId("parent");
final ProjectId childId = givenAggregateId("child");
/**
* Create event factory for which producer ID would be the `parentId`.
* Custom routing set by {@linkplain ReactingRepository()} would use
* child IDs from the event.
*/
final TestEventFactory factory = TestEventFactory.newInstance(Identifier.pack(parentId), getClass());
final AggProjectArchived msg = AggProjectArchived.newBuilder().setProjectId(parentId).addChildProjectId(childId).build();
final Event event = factory.createEvent(msg);
// Posting this event should archive the aggregate.
boundedContext.getEventBus().post(event);
// Check that the aggregate marked itself as `archived`, and therefore became invisible
// to regular queries.
final Optional<ReactingAggregate> optional = repository.find(childId);
// The aggregate was created because of dispatching.
assertTrue(optional.isPresent());
// The proper method was called, which we check by the state the aggregate got.
assertEquals(ReactingAggregate.PROJECT_ARCHIVED, optional.get().getState().getValue());
}
Aggregations