use of io.spine.test.storage.TaskId 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);
}
}
}
Aggregations