Search in sources :

Example 1 with TestProjection

use of io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method dispatch_event_to_archived_projection.

@Test
public void dispatch_event_to_archived_projection() {
    final PrjProjectArchived projectArchived = GivenEventMessage.projectArchived();
    checkDispatchesEvent(projectArchived);
    final ProjectId projectId = projectArchived.getProjectId();
    TestProjection projection = repository().findOrCreate(projectId);
    assertTrue(projection.isArchived());
    // Dispatch an event to the archived projection.
    checkDispatchesEvent(GivenEventMessage.taskAdded());
    projection = repository().findOrCreate(projectId);
    final List<Task> addedTasks = projection.getState().getTaskList();
    assertFalse(addedTasks.isEmpty());
    // Check that the projection was not re-created before dispatching.
    assertTrue(projection.isArchived());
}
Also used : Task(io.spine.test.projection.Task) PrjProjectArchived(io.spine.test.projection.event.PrjProjectArchived) ProjectId(io.spine.test.projection.ProjectId) TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) Test(org.junit.Test)

Example 2 with TestProjection

use of io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method dispatch_event_to_deleted_projection.

@Test
public void dispatch_event_to_deleted_projection() {
    final PrjProjectDeleted projectDeleted = GivenEventMessage.projectDeleted();
    checkDispatchesEvent(projectDeleted);
    final ProjectId projectId = projectDeleted.getProjectId();
    TestProjection projection = repository().findOrCreate(projectId);
    assertTrue(projection.isDeleted());
    // Dispatch an event to the deleted projection.
    checkDispatchesEvent(GivenEventMessage.taskAdded());
    projection = repository().findOrCreate(projectId);
    final List<Task> addedTasks = projection.getState().getTaskList();
    assertTrue(projection.isDeleted());
    // Check that the projection was not re-created before dispatching.
    assertFalse(addedTasks.isEmpty());
}
Also used : Task(io.spine.test.projection.Task) PrjProjectDeleted(io.spine.test.projection.event.PrjProjectDeleted) ProjectId(io.spine.test.projection.ProjectId) TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) Test(org.junit.Test)

Example 3 with TestProjection

use of io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method createEntities.

@Override
protected List<TestProjection> createEntities(int count) {
    final List<TestProjection> projections = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        final TestProjection projection = Given.projectionOfClass(TestProjection.class).withId(createId(i)).build();
        projections.add(projection);
    }
    return projections;
}
Also used : TestProjection(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection) LinkedList(java.util.LinkedList)

Example 4 with TestProjection

use of io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection 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)4 ProjectId (io.spine.test.projection.ProjectId)3 Test (org.junit.Test)3 Task (io.spine.test.projection.Task)2 PrjProjectArchived (io.spine.test.projection.event.PrjProjectArchived)1 PrjProjectDeleted (io.spine.test.projection.event.PrjProjectDeleted)1 PrjProjectStarted (io.spine.test.projection.event.PrjProjectStarted)1 LinkedList (java.util.LinkedList)1