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