use of io.spine.test.projection.ProjectId 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);
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class ProjectionTransactionShould method increment_version_on_event.
/**
* Tests the version advancement strategy for the {@link Projection}s.
*
* <p>The versioning strategy is for {@link Projection} is
* {@link io.spine.server.entity.EntityVersioning#AUTO_INCREMENT AUTO_INCREMENT}. This test
* case substitutes {@link #advance_version_from_event()}, which tested the behavior of
* {@link io.spine.server.entity.EntityVersioning#FROM_EVENT FROM_EVENT} strategy.
*/
@Test
public void increment_version_on_event() {
final Projection<ProjectId, Project, PatchedProjectBuilder> entity = createEntity();
final Version oldVersion = entity.getVersion();
final Event event = createEvent(createEventMessage());
Projection.play(entity, Collections.singleton(event));
final Version expected = Versions.increment(oldVersion);
assertEquals(expected.getNumber(), entity.getVersion().getNumber());
assertNotEquals(event.getContext().getVersion(), entity.getVersion());
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class StandPostShould method deliver_updates.
// **** Positive scenarios (unit) ****
@SuppressWarnings({ "OverlyComplexAnonymousInnerClass", "ConstantConditions" })
@Test
public void deliver_updates() {
final AggregateRepository<ProjectId, Given.StandTestAggregate> repository = Given.aggregateRepo();
final ProjectId entityId = ProjectId.newBuilder().setId("PRJ-001").build();
final Given.StandTestAggregate entity = repository.create(entityId);
final StringValue state = entity.getState();
final Version version = entity.getVersion();
final Stand innerStand = Stand.newBuilder().build();
final Stand stand = spy(innerStand);
stand.post(requestFactory.createCommandContext().getActorContext().getTenantId(), entity);
final ArgumentMatcher<EntityStateEnvelope<?, ?>> argumentMatcher = new ArgumentMatcher<EntityStateEnvelope<?, ?>>() {
@Override
public boolean matches(EntityStateEnvelope<?, ?> argument) {
final boolean entityIdMatches = argument.getEntityId().equals(entityId);
final boolean versionMatches = version.equals(argument.getEntityVersion().orNull());
final boolean stateMatches = argument.getMessage().equals(state);
return entityIdMatches && versionMatches && stateMatches;
}
};
verify(stand).update(ArgumentMatchers.argThat(argumentMatcher));
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class StandShould method setupExpectedFindAllBehaviour.
@SuppressWarnings("ConstantConditions")
private static void setupExpectedFindAllBehaviour(Map<ProjectId, Project> sampleProjects, StandTestProjectionRepository projectionRepository) {
final Set<ProjectId> projectIds = sampleProjects.keySet();
final ImmutableCollection<Given.StandTestProjection> allResults = toProjectionCollection(projectIds);
for (ProjectId projectId : projectIds) {
when(projectionRepository.find(eq(projectId))).thenReturn(Optional.of(new StandTestProjection(projectId)));
}
final Iterable<ProjectId> matchingIds = argThat(projectionIdsIterableMatcher(projectIds));
when(projectionRepository.loadAll(matchingIds, any(FieldMask.class))).thenReturn(allResults.iterator());
when(projectionRepository.loadAll()).thenReturn(allResults.iterator());
final EntityFilters matchingFilter = argThat(entityFilterMatcher(projectIds));
when(projectionRepository.find(matchingFilter, any(FieldMask.class))).thenReturn(allResults.iterator());
}
use of io.spine.test.projection.ProjectId in project core-java by SpineEventEngine.
the class StandShould method trigger_subscription_callback_upon_update_of_projection.
@Test
public void trigger_subscription_callback_upon_update_of_projection() {
final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
final Topic allProjects = requestFactory.topic().allOf(Project.class);
final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
subscribeAndActivate(stand, allProjects, memoizeCallback);
assertNull(memoizeCallback.newEntityState);
final Map.Entry<ProjectId, Project> sampleData = fillSampleProjects(1).entrySet().iterator().next();
final ProjectId projectId = sampleData.getKey();
final Project project = sampleData.getValue();
final Version stateVersion = GivenVersion.withNumber(1);
stand.update(asEnvelope(projectId, project, stateVersion));
final Any packedState = AnyPacker.pack(project);
assertEquals(packedState, memoizeCallback.newEntityState);
}
Aggregations