Search in sources :

Example 6 with ProjectId

use of io.spine.test.storage.ProjectId in project core-java by SpineEventEngine.

the class ProjectionStorageShould method fillStorage.

// Converter nullability issues
@SuppressWarnings("ConstantConditions")
private List<ProjectId> fillStorage(int count) {
    final List<ProjectId> ids = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        final ProjectId id = newId();
        final Project state = Given.project(id, format("project-%d", i));
        final Any packedState = AnyPacker.pack(state);
        final EntityRecord rawRecord = EntityRecord.newBuilder().setState(packedState).setVersion(GivenVersion.withNumber(1)).build();
        final EntityRecordWithColumns record = withLifecycleColumns(rawRecord);
        storage.write(id, record);
        ids.add(id);
    }
    return ids;
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) LinkedList(java.util.LinkedList) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns)

Example 7 with ProjectId

use of io.spine.test.storage.ProjectId in project core-java by SpineEventEngine.

the class ProjectionStorageShould method read_all_messages_with_field_mask.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void read_all_messages_with_field_mask() {
    final List<ProjectId> ids = fillStorage(5);
    final String projectDescriptor = Project.getDescriptor().getFullName();
    @SuppressWarnings("DuplicateStringLiteralInspection") final FieldMask // clashes with non-related tests.
    fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".name");
    final Iterator<EntityRecord> read = storage.readAll(fieldMask);
    final Collection<EntityRecord> readRecords = newArrayList(read);
    assertSize(ids.size(), readRecords);
    for (EntityRecord record : readRecords) {
        final Any packedState = record.getState();
        final Project state = AnyPacker.unpack(packedState);
        assertMatchesMask(state, fieldMask);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 8 with ProjectId

use of io.spine.test.storage.ProjectId in project core-java by SpineEventEngine.

the class StandStorageShould method checkIds.

protected void checkIds(List<AggregateStateId> ids, Iterator<EntityRecord> records) {
    final Collection<EntityRecord> recordsToCheck = newArrayList(records);
    assertSize(ids.size(), recordsToCheck);
    final Collection<ProjectId> projectIds = Collections2.transform(ids, new Function<AggregateStateId, ProjectId>() {

        @Nullable
        @Override
        public ProjectId apply(@Nullable AggregateStateId input) {
            if (input == null) {
                return null;
            }
            return (ProjectId) input.getAggregateId();
        }
    });
    for (EntityRecord record : recordsToCheck) {
        final Any packedState = record.getState();
        final Project state = AnyPacker.unpack(packedState);
        final ProjectId id = state.getId();
        assertContains(id, projectIds);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any) Nullable(javax.annotation.Nullable)

Aggregations

ProjectId (io.spine.test.storage.ProjectId)8 EntityRecord (io.spine.server.entity.EntityRecord)7 Project (io.spine.test.storage.Project)7 Any (com.google.protobuf.Any)5 Test (org.junit.Test)4 FieldMask (com.google.protobuf.FieldMask)2 Nullable (javax.annotation.Nullable)2 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1 LinkedList (java.util.LinkedList)1