use of io.spine.test.aggregate.ProjectId in project core-java by SpineEventEngine.
the class SubscriptionServiceShould method activate_subscription.
@Test
public void activate_subscription() {
final BoundedContext boundedContext = setupBoundedContextWithProjectAggregateRepo();
final SubscriptionService subscriptionService = SubscriptionService.newBuilder().add(boundedContext).build();
final Target target = getProjectQueryTarget();
final Topic topic = requestFactory.topic().forTarget(target);
// Subscribe to the topic
final MemoizeStreamObserver<Subscription> subscriptionObserver = new MemoizeStreamObserver<>();
subscriptionService.subscribe(topic, subscriptionObserver);
subscriptionObserver.verifyState();
// Activate subscription
final MemoizeStreamObserver<SubscriptionUpdate> activationObserver = new MemoizeStreamObserver<>();
subscriptionService.activate(subscriptionObserver.streamFlowValue, activationObserver);
// Post update to Stand directly
final ProjectId projectId = ProjectId.newBuilder().setId("some-id").build();
final Message projectState = Project.newBuilder().setId(projectId).build();
final int version = 1;
final VersionableEntity entity = mockEntity(projectId, projectState, version);
boundedContext.getStand().post(entity, requestFactory.createCommandContext());
// isCompleted set to false since we don't expect activationObserver::onCompleted to be called.
activationObserver.verifyState(false);
}
use of io.spine.test.aggregate.ProjectId in project core-java by SpineEventEngine.
the class AggregateCommandEndpointShould method repeat_command_dispatching_if_event_count_is_changed_during_dispatching.
@Test
public void repeat_command_dispatching_if_event_count_is_changed_during_dispatching() {
@SuppressWarnings("unchecked") final AggregateStorage<ProjectId> storage = mock(AggregateStorage.class);
final CommandEnvelope cmd = CommandEnvelope.of(createProject(projectId));
// Change reported event count upon the second invocation and trigger re-dispatch.
doReturn(0, 1).when(storage).readEventCountAfterLastSnapshot(projectId);
doReturn(Optional.absent()).when(storage).read(projectId);
doReturn(storage).when(repositorySpy).aggregateStorage();
doReturn(Optional.absent()).when(storage).readLifecycleFlags(projectId);
repositorySpy.dispatch(cmd);
// Load should be executed twice due to repeated dispatching.
verify(repositorySpy, times(2)).loadOrCreate(projectId);
// Reading event count is executed 2 times per dispatch (so 2 * 2)
// plus once upon storing the state.
verify(storage, times(2 * 2 + 1)).readEventCountAfterLastSnapshot(projectId);
}
use of io.spine.test.aggregate.ProjectId in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method reject_invalid_AggregateStateRecord_instance.
@Test(expected = IllegalStateException.class)
public void reject_invalid_AggregateStateRecord_instance() {
final ProjectId id = Sample.messageOfType(ProjectId.class);
final AggregateStorage<ProjectId> storage = givenAggregateStorageMock();
doReturn(Optional.of(AggregateStateRecord.getDefaultInstance())).when(storage).read(id);
repositorySpy.loadOrCreate(id);
}
use of io.spine.test.aggregate.ProjectId in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method createAndStore.
private void createAndStore(String id) {
final ProjectId projectId = ProjectId.newBuilder().setId(id).build();
final ProjectAggregate aggregate = givenAggregateWithUncommittedEvents(projectId);
repository.store(aggregate);
}
use of io.spine.test.aggregate.ProjectId in project core-java by SpineEventEngine.
the class AggregateShould method import_events.
@Test
public void import_events() {
final String projectName = getClass().getSimpleName();
final ProjectId id = aggregate.getId();
final ImportEvents importCmd = ImportEvents.newBuilder().setProjectId(id).addEvent(event(projectCreated(id, projectName), 1)).addEvent(event(taskAdded(id), 2)).build();
aggregate.dispatchCommands(command(importCmd));
assertTrue(aggregate.isProjectCreatedEventApplied);
assertTrue(aggregate.isTaskAddedEventApplied);
}
Aggregations