Search in sources :

Example 11 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateShould method return_default_state_by_default.

@Test
public void return_default_state_by_default() {
    final Project state = aggregate.getState();
    assertEquals(aggregate.getDefaultState(), state);
}
Also used : AggCancelProject(io.spine.test.aggregate.command.AggCancelProject) AggStartProject(io.spine.test.aggregate.command.AggStartProject) AggCreateProject(io.spine.test.aggregate.command.AggCreateProject) AggPauseProject(io.spine.test.aggregate.command.AggPauseProject) Project(io.spine.test.aggregate.Project) Test(org.junit.Test)

Example 12 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateShould method update_state_when_the_command_is_handled.

@Test
public void update_state_when_the_command_is_handled() {
    dispatchCommand(aggregate, env(createProject));
    final Project state = aggregate.getState();
    assertEquals(ID, state.getId());
    assertEquals(Status.CREATED, state.getStatus());
}
Also used : AggCancelProject(io.spine.test.aggregate.command.AggCancelProject) AggStartProject(io.spine.test.aggregate.command.AggStartProject) AggCreateProject(io.spine.test.aggregate.command.AggCreateProject) AggPauseProject(io.spine.test.aggregate.command.AggPauseProject) Project(io.spine.test.aggregate.Project) Test(org.junit.Test)

Example 13 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateStorageShould method continue_history_reading_if_snapshot_was_not_found_in_first_batch.

@Test
public void continue_history_reading_if_snapshot_was_not_found_in_first_batch() {
    Version currentVersion = zero();
    final Snapshot snapshot = Snapshot.newBuilder().setVersion(currentVersion).build();
    storage.writeSnapshot(id, snapshot);
    final int eventCountAfterSnapshot = 10;
    for (int i = 0; i < eventCountAfterSnapshot; i++) {
        currentVersion = increment(currentVersion);
        final Project state = Project.getDefaultInstance();
        final Event event = eventFactory.createEvent(state, currentVersion);
        storage.writeEvent(id, event);
    }
    final int batchSize = 1;
    final AggregateReadRequest<ProjectId> request = new AggregateReadRequest<>(id, batchSize);
    final Optional<AggregateStateRecord> optionalStateRecord = storage.read(request);
    assertTrue(optionalStateRecord.isPresent());
    final AggregateStateRecord stateRecord = optionalStateRecord.get();
    assertEquals(snapshot, stateRecord.getSnapshot());
    assertEquals(eventCountAfterSnapshot, stateRecord.getEventCount());
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) ProjectId(io.spine.test.aggregate.ProjectId) Event(io.spine.core.Event) Test(org.junit.Test)

Example 14 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateStorageShould method sort_by_version_rather_then_by_timestamp.

@Test
public void sort_by_version_rather_then_by_timestamp() {
    final Project state = Project.getDefaultInstance();
    final Version minVersion = zero();
    final Version maxVersion = increment(minVersion);
    final Timestamp minTimestamp = Timestamps.MIN_VALUE;
    final Timestamp maxTimestamp = Timestamps.MAX_VALUE;
    // The first event is an event, which is the oldest, i.e. with the minimal version.
    final Event expectedFirst = eventFactory.createEvent(state, minVersion, maxTimestamp);
    final Event expectedSecond = eventFactory.createEvent(state, maxVersion, minTimestamp);
    storage.writeEvent(id, expectedSecond);
    storage.writeEvent(id, expectedFirst);
    final List<Event> events = storage.read(newReadRequest(id)).get().getEventList();
    assertTrue(events.indexOf(expectedFirst) < events.indexOf(expectedSecond));
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) Event(io.spine.core.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 15 with Project

use of io.spine.test.aggregate.Project in project core-java by SpineEventEngine.

the class AggregateStorageShould method write_records_and_return_sorted_by_version_descending.

@Test
public void write_records_and_return_sorted_by_version_descending() {
    final int eventsNumber = 5;
    final List<AggregateEventRecord> records = newLinkedList();
    final Timestamp timestamp = getCurrentTime();
    Version currentVersion = zero();
    for (int i = 0; i < eventsNumber; i++) {
        final Project state = Project.getDefaultInstance();
        final Event event = eventFactory.createEvent(state, currentVersion, timestamp);
        final AggregateEventRecord record = StorageRecord.create(timestamp, event);
        records.add(record);
        currentVersion = increment(currentVersion);
    }
    writeAll(id, records);
    final Iterator<AggregateEventRecord> iterator = historyBackward();
    final List<AggregateEventRecord> actual = newArrayList(iterator);
    // expected records should be in a reverse order
    reverse(records);
    assertEquals(records, actual);
}
Also used : Project(io.spine.test.aggregate.Project) Version(io.spine.core.Version) Event(io.spine.core.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Project (io.spine.test.aggregate.Project)15 Test (org.junit.Test)15 FieldMask (com.google.protobuf.FieldMask)5 ProjectId (io.spine.test.aggregate.ProjectId)4 Any (com.google.protobuf.Any)3 Event (io.spine.core.Event)3 Version (io.spine.core.Version)3 AggCancelProject (io.spine.test.aggregate.command.AggCancelProject)3 AggCreateProject (io.spine.test.aggregate.command.AggCreateProject)3 AggPauseProject (io.spine.test.aggregate.command.AggPauseProject)3 AggStartProject (io.spine.test.aggregate.command.AggStartProject)3 Timestamp (com.google.protobuf.Timestamp)2 LinkedList (java.util.LinkedList)2 CreateProject (io.spine.test.aggregate.command.CreateProject)1 StartProject (io.spine.test.aggregate.command.StartProject)1