Search in sources :

Example 1 with PrjProjectStarted

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);
}
Also used : PrjProjectStarted(io.spine.test.projection.event.PrjProjectStarted) ProjectId(io.spine.test.projection.ProjectId) TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) Test(org.junit.Test)

Aggregations

TestProjection (io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection)1 ProjectId (io.spine.test.projection.ProjectId)1 PrjProjectStarted (io.spine.test.projection.event.PrjProjectStarted)1 Test (org.junit.Test)1