use of io.spine.test.projection.event.PrjProjectStarted in project core-java by SpineEventEngine.
the class ProjectionRepositoryShould method dispatch_event_and_load_projection.
/*
* Tests
************/
@Test
public void dispatch_event_and_load_projection() {
final PrjProjectStarted msg = GivenEventMessage.projectStarted();
// Ensure no instances are present in the repository now.
assertFalse(repository().loadAll().hasNext());
// And no instances of `TestProjection` processed the event message we are going to post.
assertTrue(TestProjection.whoProcessed(msg).isEmpty());
// Post an event message and grab the ID of the projection, which processed it.
checkDispatchesEvent(msg);
final Set<ProjectId> projectIds = TestProjection.whoProcessed(msg);
assertTrue(projectIds.size() == 1);
final ProjectId receiverId = projectIds.iterator().next();
// Check that the projection item has actually been stored and now can be loaded.
final Iterator<TestProjection> allItems = repository().loadAll();
assertTrue(allItems.hasNext());
final TestProjection storedProjection = allItems.next();
assertFalse(allItems.hasNext());
// Check that the stored instance has the same ID as the instance that handled the event.
assertEquals(storedProjection.getId(), receiverId);
}
Aggregations