use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class StandStorageShould method read_all_records_of_given_type_with_field_mask.
@Test
public void read_all_records_of_given_type_with_field_mask() {
final FieldMask mask = FieldMasks.maskOf(Project.getDescriptor(), 1, 2);
checkByTypeRead(mask);
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class RecordStorageShould method read_multiple_records_with_field_mask.
@SuppressWarnings({ "MethodWithMultipleLoops", "ConstantConditions" })
// Converter nullability issues
@Test
public void read_multiple_records_with_field_mask() {
final RecordStorage<I> storage = getStorage();
final int count = 10;
final List<I> ids = new LinkedList<>();
Descriptors.Descriptor typeDescriptor = null;
for (int i = 0; i < count; i++) {
final I id = newId();
final Message state = newState(id);
final EntityRecord record = newStorageRecord(state);
storage.write(id, record);
ids.add(id);
if (typeDescriptor == null) {
typeDescriptor = state.getDescriptorForType();
}
}
final int bulkCount = count / 2;
final FieldMask fieldMask = FieldMasks.maskOf(typeDescriptor, 2);
final Iterable<EntityRecord> readRecords = storage.readMultiple(ids.subList(0, bulkCount), fieldMask);
final List<EntityRecord> readList = newLinkedList(readRecords);
Verify.assertSize(bulkCount, readList);
for (EntityRecord record : readRecords) {
final Message state = unpack(record.getState());
assertMatchesMask(state, fieldMask);
}
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class RecordStorageShould method retrieve_empty_map_if_storage_is_empty.
@Test
public void retrieve_empty_map_if_storage_is_empty() {
final FieldMask nonEmptyFieldMask = FieldMask.newBuilder().addPaths("invalid-path").build();
final RecordStorage storage = getStorage();
final Map empty = storage.readAll(nonEmptyFieldMask);
assertNotNull(empty);
Verify.assertEmpty(empty);
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class RecordBasedRepositoryShould method retrieve_all_records_with_entity_filters_and_field_mask_applied.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void retrieve_all_records_with_entity_filters_and_field_mask_applied() {
final int count = 10;
final List<E> entities = createAndStoreEntities(repository, count);
final List<EntityId> ids = Lists.newLinkedList();
// Find some of the records (half of them in this case)
for (int i = 0; i < count / 2; i++) {
final Message entityId = (Message) entities.get(i).getId();
final EntityId id = EntityId.newBuilder().setId(pack(entityId)).build();
ids.add(id);
}
final EntityIdFilter filter = EntityIdFilter.newBuilder().addAllIds(ids).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(filter).build();
final Descriptors.Descriptor entityDescriptor = entities.get(0).getState().getDescriptorForType();
final FieldMask firstFieldOnly = FieldMasks.maskOf(entityDescriptor, 1);
final Iterable<E> readEntities = find(filters, firstFieldOnly);
assertSize(ids.size(), readEntities);
for (E entity : readEntities) {
assertMatches(entity, firstFieldOnly);
}
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method apply_only_non_empty_mask_to_collection.
@SuppressWarnings({ "ObjectEquality", "MethodWithMultipleLoops" })
@Test
public void apply_only_non_empty_mask_to_collection() {
final FieldMask emptyMask = Given.fieldMask();
final Collection<Project> original = new LinkedList<>();
final int count = 5;
for (int i = 0; i < count; i++) {
final Project project = Given.newProject(format("test-data--%s", i));
original.add(project);
}
final Collection<Project> processed = FieldMasks.applyMask(emptyMask, original, Given.TYPE);
assertSize(original.size(), processed);
// The argument is not returned
assertFalse(original == processed);
// A copy of the argument is returned (Collection type may differ)
final Iterator<Project> processedProjects = processed.iterator();
for (Project anOriginal : original) {
assertTrue(processedProjects.next().equals(anOriginal));
}
}
Aggregations