Search in sources :

Example 41 with FieldDescriptor

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

the class FieldValidatorFactoryShould method create_ByteString_field_validator.

@Test
public void create_ByteString_field_validator() {
    final FieldDescriptor field = RequiredByteStringFieldValue.getDescriptor().getFields().get(0);
    final FieldValidator validator = FieldValidatorFactory.create(field, new Object(), FIELD_PATH);
    assertTrue(validator instanceof ByteStringFieldValidator);
}
Also used : ByteStringFieldValidator(io.spine.validate.ByteStringFieldValidator) FloatFieldValidator(io.spine.validate.FloatFieldValidator) StringFieldValidator(io.spine.validate.StringFieldValidator) LongFieldValidator(io.spine.validate.LongFieldValidator) BooleanFieldValidator(io.spine.validate.BooleanFieldValidator) ByteStringFieldValidator(io.spine.validate.ByteStringFieldValidator) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 42 with FieldDescriptor

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

the class FieldValidatorFactoryShould method create_Enum_field_validator.

@Test
public void create_Enum_field_validator() {
    final FieldDescriptor field = RequiredEnumFieldValue.getDescriptor().getFields().get(0);
    final FieldValidator validator = FieldValidatorFactory.create(field, new Object(), FIELD_PATH);
    assertTrue(validator instanceof EnumFieldValidator);
}
Also used : ByteStringFieldValidator(io.spine.validate.ByteStringFieldValidator) FloatFieldValidator(io.spine.validate.FloatFieldValidator) StringFieldValidator(io.spine.validate.StringFieldValidator) LongFieldValidator(io.spine.validate.LongFieldValidator) BooleanFieldValidator(io.spine.validate.BooleanFieldValidator) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 43 with FieldDescriptor

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

the class FieldValidatorFactoryShould method create_double_field_validator.

@Test
public void create_double_field_validator() {
    final FieldDescriptor field = DoubleValue.getDescriptor().getFields().get(0);
    final FieldValidator validator = FieldValidatorFactory.create(field, 0, FIELD_PATH);
    assertTrue(validator instanceof DoubleFieldValidator);
}
Also used : ByteStringFieldValidator(io.spine.validate.ByteStringFieldValidator) FloatFieldValidator(io.spine.validate.FloatFieldValidator) StringFieldValidator(io.spine.validate.StringFieldValidator) LongFieldValidator(io.spine.validate.LongFieldValidator) BooleanFieldValidator(io.spine.validate.BooleanFieldValidator) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 44 with FieldDescriptor

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

the class ReferenceValidatorShould method skip_mapping_if_no_mapping_function_is_defined.

@Test
public void skip_mapping_if_no_mapping_function_is_defined() {
    final EventEnricher mockEnricher = mock(EventEnricher.class);
    when(mockEnricher.functionFor(any(Class.class), any(Class.class))).thenReturn(Optional.<EnrichmentFunction<?, ?>>absent());
    final ReferenceValidator validator = new ReferenceValidator(mockEnricher, UserDeletedEvent.class, EnrichmentBoundWithMultipleFieldsWithDifferentNames.class);
    final ValidationResult result = validator.validate();
    final List<EnrichmentFunction<?, ?>> functions = result.getFunctions();
    assertTrue(functions.isEmpty());
    final Multimap<FieldDescriptor, FieldDescriptor> fields = result.getFieldMap();
    assertEmpty(fields);
}
Also used : ValidationResult(io.spine.server.event.enrich.ReferenceValidator.ValidationResult) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 45 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project beam by apache.

the class ProtobufUtil method verifyDeterministic.

/**
   * Recursively checks whether the specified class uses any Protocol Buffers fields that cannot
   * be deterministically encoded.
   *
   * @throws NonDeterministicException if the object cannot be encoded deterministically.
   */
static void verifyDeterministic(ProtoCoder<?> coder) throws NonDeterministicException {
    Class<? extends Message> message = coder.getMessageType();
    ExtensionRegistry registry = coder.getExtensionRegistry();
    Set<Descriptor> descriptors = getRecursiveDescriptorsForClass(message, registry);
    for (Descriptor d : descriptors) {
        for (FieldDescriptor fd : d.getFields()) {
            // be encoded deterministically.
            if (fd.isMapField()) {
                String reason = String.format("Protocol Buffers message %s transitively includes Map field %s (from file %s)." + " Maps cannot be deterministically encoded.", message.getName(), fd.getFullName(), fd.getFile().getFullName());
                throw new NonDeterministicException(coder, reason);
            }
        }
    }
}
Also used : NonDeterministicException(org.apache.beam.sdk.coders.Coder.NonDeterministicException) GenericDescriptor(com.google.protobuf.Descriptors.GenericDescriptor) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)45 Descriptor (com.google.protobuf.Descriptors.Descriptor)18 Test (org.junit.Test)14 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)11 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)11 BooleanFieldValidator (io.spine.validate.BooleanFieldValidator)9 ByteStringFieldValidator (io.spine.validate.ByteStringFieldValidator)9 FloatFieldValidator (io.spine.validate.FloatFieldValidator)9 LongFieldValidator (io.spine.validate.LongFieldValidator)9 StringFieldValidator (io.spine.validate.StringFieldValidator)9 TypicalData (protos.TypicalData)5 ArrayList (java.util.ArrayList)4 ByteString (com.google.protobuf.ByteString)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)3 ValidationResult (io.spine.server.event.enrich.ReferenceValidator.ValidationResult)3 Map (java.util.Map)3 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 Collection (java.util.Collection)2 TypicalDataMessage (protos.TypicalDataMessage)2 ImageAnnotatorClient (com.google.cloud.vision.spi.v1.ImageAnnotatorClient)1