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