Search in sources :

Example 1 with ProjectId

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);
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.aggregate.ProjectId) SubscriptionUpdate(io.spine.client.SubscriptionUpdate) AbstractVersionableEntity(io.spine.server.entity.AbstractVersionableEntity) VersionableEntity(io.spine.server.entity.VersionableEntity) Target(io.spine.client.Target) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test)

Example 2 with ProjectId

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);
}
Also used : ProjectId(io.spine.test.aggregate.ProjectId) CommandEnvelope(io.spine.envelope.CommandEnvelope) Test(org.junit.Test)

Example 3 with 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);
}
Also used : ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Example 4 with ProjectId

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);
}
Also used : ProjectId(io.spine.test.aggregate.ProjectId)

Example 5 with ProjectId

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);
}
Also used : ImportEvents(io.spine.test.aggregate.command.ImportEvents) ProjectId(io.spine.test.aggregate.ProjectId) Test(org.junit.Test)

Aggregations

ProjectId (io.spine.test.aggregate.ProjectId)16 Test (org.junit.Test)12 Any (com.google.protobuf.Any)3 Project (io.spine.test.aggregate.Project)3 Message (com.google.protobuf.Message)2 Subscription (io.spine.client.Subscription)2 SubscriptionUpdate (io.spine.client.SubscriptionUpdate)2 Target (io.spine.client.Target)2 Topic (io.spine.client.Topic)2 AbstractVersionableEntity (io.spine.server.entity.AbstractVersionableEntity)2 VersionableEntity (io.spine.server.entity.VersionableEntity)2 Before (org.junit.Before)2 Response (io.spine.base.Response)1 CommandEnvelope (io.spine.envelope.CommandEnvelope)1 ProjectDefinition (io.spine.test.aggregate.ProjectDefinition)1 ImportEvents (io.spine.test.aggregate.command.ImportEvents)1