Search in sources :

Example 16 with FieldMask

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));
    }
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 17 with FieldMask

use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.

the class FieldMasksShould method create_masks_for_given_field_tags.

@Test
public void create_masks_for_given_field_tags() {
    final Descriptors.Descriptor descriptor = Project.getDescriptor();
    final int[] fieldNumbers = { 1, 2, 3 };
    @SuppressWarnings("DuplicateStringLiteralInspection") final String[] fieldNames = { "id", "name", "task" };
    final FieldMask mask = FieldMasks.maskOf(descriptor, fieldNumbers);
    final List<String> paths = mask.getPathsList();
    assertSize(fieldNumbers.length, paths);
    for (int i = 0; i < paths.size(); i++) {
        final String expectedPath = descriptor.getFullName() + '.' + fieldNames[i];
        assertEquals(expectedPath, paths.get(i));
    }
}
Also used : Descriptors(com.google.protobuf.Descriptors) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 18 with FieldMask

use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.

the class FieldMasksShould method apply_mask_to_message_collections.

@SuppressWarnings({ "MethodWithMultipleLoops", "ObjectEquality" })
@Test
public void apply_mask_to_message_collections() {
    final FieldMask fieldMask = Given.fieldMask(Project.STATUS_FIELD_NUMBER, Project.TASK_FIELD_NUMBER);
    final int count = 5;
    final Collection<Project> original = new LinkedList<>();
    for (int i = 0; i < count; i++) {
        final Project project = Given.newProject(format("project-%s", i));
        original.add(project);
    }
    final Collection<Project> masked = FieldMasks.applyMask(fieldMask, original, Given.TYPE);
    assertSize(original.size(), masked);
    // Collection references are not the same
    assertFalse(original == masked);
    for (Project project : masked) {
        assertMatchesMask(project, fieldMask);
        // Can't check repeated fields with assertMatchesMask
        assertFalse(project.getTaskList().isEmpty());
    }
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 19 with FieldMask

use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.

the class FieldMasksShould method retrieve_default_field_mask_if_no_field_tags_requested.

@Test
public void retrieve_default_field_mask_if_no_field_tags_requested() {
    final Descriptors.Descriptor descriptor = Project.getDescriptor();
    final FieldMask mask = FieldMasks.maskOf(descriptor);
    assertEquals(FieldMask.getDefaultInstance(), mask);
}
Also used : Descriptors(com.google.protobuf.Descriptors) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 20 with FieldMask

use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.

the class DefaultEntityStorageConverterShould method create_instance_with_FieldMask.

@Test
public void create_instance_with_FieldMask() throws Exception {
    final FieldMask fieldMask = FieldMask.newBuilder().addPaths("foo.bar").build();
    final EntityStorageConverter<Long, TestEntity, StringValue> withMasks = converter.withFieldMask(fieldMask);
    assertEquals(fieldMask, withMasks.getFieldMask());
}
Also used : StringValue(com.google.protobuf.StringValue) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

FieldMask (com.google.protobuf.FieldMask)31 Test (org.junit.Test)22 Any (com.google.protobuf.Any)7 EntityRecord (io.spine.server.entity.EntityRecord)7 Descriptors (com.google.protobuf.Descriptors)5 Message (com.google.protobuf.Message)5 Project (io.spine.test.aggregate.Project)5 LinkedList (java.util.LinkedList)4 EntityFilters (io.spine.client.EntityFilters)3 Project (io.spine.test.storage.Project)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ImmutableList (com.google.common.collect.ImmutableList)2 Query (io.spine.client.Query)2 Target (io.spine.client.Target)2 Version (io.spine.core.Version)2 GivenVersion (io.spine.core.given.GivenVersion)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 TestEntity (io.spine.test.client.TestEntity)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2