Search in sources :

Example 1 with Project

use of io.spine.test.storage.Project 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 Project

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

the class StandStorageShould method checkByTypeRead.

// OK for this test.
@SuppressWarnings({ "MethodWithMultipleLoops", "ConstantConditions" })
private void checkByTypeRead(FieldMask fieldMask) {
    final boolean withFieldMask = !fieldMask.equals(FieldMask.getDefaultInstance());
    final StandStorage storage = getStorage();
    final TypeUrl type = TypeUrl.from(Project.getDescriptor());
    final int projectsCount = 4;
    final List<AggregateStateId> projectIds = fill(storage, projectsCount, DEFAULT_ID_SUPPLIER);
    final int tasksCount = 5;
    for (int i = 0; i < tasksCount; i++) {
        final TaskId genericId = TaskId.newBuilder().setId(i).build();
        final AggregateStateId id = AggregateStateId.of(genericId, TypeUrl.from(Task.getDescriptor()));
        final Task task = Task.newBuilder().setTaskId(genericId).setTitle("Test task").setDescription("With description").build();
        final EntityRecord record = newRecord(task);
        storage.write(id, record);
    }
    final ImmutableCollection<EntityRecord> readRecords = withFieldMask ? storage.readAllByType(TypeUrl.from(Project.getDescriptor()), fieldMask) : storage.readAllByType(TypeUrl.from(Project.getDescriptor()));
    final Set<EntityRecord> readDistinct = Sets.newHashSet(readRecords);
    assertSize(projectsCount, readDistinct);
    for (EntityRecord record : readDistinct) {
        final Any state = record.getState();
        final Project project = AnyPacker.unpack(state);
        final AggregateStateId restored = AggregateStateId.of(project.getId(), type);
        assertContains(restored, projectIds);
        if (withFieldMask) {
            assertMatchesMask(project, fieldMask);
        }
    }
}
Also used : Task(io.spine.test.storage.Task) TaskId(io.spine.test.storage.TaskId) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) StandStorage(io.spine.server.stand.StandStorage)

Aggregations

Any (com.google.protobuf.Any)2 EntityRecord (io.spine.server.entity.EntityRecord)2 Project (io.spine.test.storage.Project)2 StandStorage (io.spine.server.stand.StandStorage)1 ProjectId (io.spine.test.storage.ProjectId)1 Task (io.spine.test.storage.Task)1 TaskId (io.spine.test.storage.TaskId)1 TypeUrl (io.spine.type.TypeUrl)1 Nullable (javax.annotation.Nullable)1