Search in sources :

Example 1 with FieldMask

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

the class ProjectionStorageShould method perform_bulk_read_with_field_mask_operation.

@SuppressWarnings({ "MethodWithMultipleLoops", "BreakStatement" })
@Test
public void perform_bulk_read_with_field_mask_operation() {
    // Get a subset of IDs
    final List<I> ids = fillStorage(10).subList(0, 5);
    final String projectDescriptor = Project.getDescriptor().getFullName();
    final FieldMask fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".status");
    final Iterable<EntityRecord> read = storage.readMultiple(ids, fieldMask);
    assertSize(ids.size(), read);
    // Check data consistency
    for (EntityRecord record : read) {
        final Project state = checkProjectIdIsInList(record, ids);
        assertMatchesMask(state, fieldMask);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.projection.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 2 with FieldMask

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

the class QueryFactoryShould method checkFieldMaskEmpty.

private static void checkFieldMaskEmpty(Query query) {
    final FieldMask fieldMask = query.getFieldMask();
    assertNotNull(fieldMask);
    assertEquals(FieldMask.getDefaultInstance(), fieldMask);
}
Also used : FieldMask(com.google.protobuf.FieldMask)

Example 3 with FieldMask

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

the class QueryFactoryShould method verifySinglePathInQuery.

private static void verifySinglePathInQuery(String expectedEntityPath, Query query) {
    final FieldMask fieldMask = query.getFieldMask();
    // as we set the only path value.
    assertEquals(1, fieldMask.getPathsCount());
    final String firstPath = fieldMask.getPaths(0);
    assertEquals(expectedEntityPath, firstPath);
}
Also used : FieldMask(com.google.protobuf.FieldMask)

Example 4 with FieldMask

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

the class QueryBuilderShould method create_queries_with_field_mask.

@Test
public void create_queries_with_field_mask() {
    final String fieldName = "TestEntity.firstField";
    final Query query = factory().query().select(TestEntity.class).withMask(fieldName).build();
    assertNotNull(query);
    assertTrue(query.hasFieldMask());
    final FieldMask mask = query.getFieldMask();
    final Collection<String> fieldNames = mask.getPathsList();
    assertSize(1, fieldNames);
    assertContains(fieldName, fieldNames);
}
Also used : Query(io.spine.client.Query) Matchers.containsString(org.hamcrest.Matchers.containsString) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 5 with FieldMask

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

the class ProjectionStorageShould method retrieve_empty_map_if_storage_is_empty.

// because the behaviour to test is different
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
@Test
public void retrieve_empty_map_if_storage_is_empty() {
    final Map<I, EntityRecord> noMaskEntiries = storage.readAll();
    final FieldMask nonEmptyMask = FieldMask.newBuilder().addPaths("invalid_path").build();
    final Map<I, EntityRecord> maskedEntries = storage.readAll(nonEmptyMask);
    assertEmpty(noMaskEntiries);
    assertEmpty(maskedEntries);
    // Same type
    assertEquals(noMaskEntiries, maskedEntries);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

FieldMask (com.google.protobuf.FieldMask)29 Test (org.junit.Test)20 Any (com.google.protobuf.Any)7 EntityRecord (io.spine.server.entity.EntityRecord)6 Descriptors (com.google.protobuf.Descriptors)5 Message (com.google.protobuf.Message)5 Query (io.spine.client.Query)5 Project (io.spine.test.aggregate.Project)5 LinkedList (java.util.LinkedList)4 EntityFilters (io.spine.client.EntityFilters)3 Target (io.spine.client.Target)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ImmutableList (com.google.common.collect.ImmutableList)2 Version (io.spine.base.Version)2 EntityId (io.spine.client.EntityId)2 EntityIdFilter (io.spine.client.EntityIdFilter)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