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