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