Search in sources :

Example 1 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, Collection<EntityRecord> records) {
    assertSize(ids.size(), records);
    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 : records) {
        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)

Example 2 with ProjectId

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

the class ProjectionStorageShould method read_all_messages.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void read_all_messages() {
    final List<ProjectId> ids = fillStorage(5);
    final Iterator<EntityRecord> read = storage.readAll();
    final Collection<EntityRecord> readRecords = newArrayList(read);
    assertSize(ids.size(), readRecords);
    for (EntityRecord record : readRecords) {
        final Project state = AnyPacker.unpack(record.getState());
        final ProjectId id = state.getId();
        assertContains(id, ids);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Test(org.junit.Test)

Example 3 with ProjectId

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

the class ProjectionStorageShould method perform_read_bulk_operations.

@SuppressWarnings({ "MethodWithMultipleLoops", "BreakStatement" })
@Test
public void perform_read_bulk_operations() {
    // Get a subset of IDs
    final List<ProjectId> ids = fillStorage(10).subList(0, 5);
    final Iterator<EntityRecord> read = storage.readMultiple(ids);
    final Collection<EntityRecord> readRecords = newArrayList(read);
    assertSize(ids.size(), readRecords);
    // Check data consistency
    for (EntityRecord record : readRecords) {
        checkProjectIdIsInList(record, ids);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) ProjectId(io.spine.test.storage.ProjectId) Test(org.junit.Test)

Example 4 with ProjectId

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

the class ProjectionStorageShould method checkProjectIdIsInList.

@SuppressWarnings("BreakStatement")
private static Project checkProjectIdIsInList(EntityRecord project, List<ProjectId> ids) {
    final Any packedState = project.getState();
    final Project state = AnyPacker.unpack(packedState);
    final ProjectId id = state.getId();
    boolean isIdPresent = false;
    for (ProjectId genericId : ids) {
        isIdPresent = genericId.equals(id);
        if (isIdPresent) {
            break;
        }
    }
    assertTrue(isIdPresent);
    return state;
}
Also used : Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any)

Example 5 with ProjectId

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

the class ProjectionStorageShould method perform_bulk_read_with_field_mask_operation.

@SuppressWarnings({ "MethodWithMultipleLoops", "BreakStatement" })
@Test
public void perform_bulk_read_with_field_mask_operation() {
    // Get a subset of IDs
    final List<ProjectId> ids = fillStorage(10).subList(0, 5);
    final String projectDescriptor = Project.getDescriptor().getFullName();
    final FieldMask fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".status");
    final Iterator<EntityRecord> read = storage.readMultiple(ids, fieldMask);
    final Collection<EntityRecord> readRecords = newArrayList(read);
    assertSize(ids.size(), readRecords);
    // Check data consistency
    for (EntityRecord record : readRecords) {
        final Project state = checkProjectIdIsInList(record, ids);
        assertMatchesMask(state, fieldMask);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

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