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 core-java by SpineEventEngine.
the class EventMessageEnricher method setFields.
// it is assured that
@SuppressWarnings({ "ConstantConditions", "MethodWithMultipleLoops" })
private // collections are not null
void setFields(Message.Builder builder, S eventMsg) {
for (FieldDescriptor srcField : fieldMap.keySet()) {
final Object srcFieldValue = getSrcFieldValue(srcField, eventMsg);
final Class<?> sourceFieldClass = srcFieldValue.getClass();
final Collection<EnrichmentFunction> functions = fieldFunctions.get(sourceFieldClass);
final Collection<FieldDescriptor> targetFields = fieldMap.get(srcField);
for (FieldDescriptor targetField : targetFields) {
final Optional<EnrichmentFunction> function = FluentIterable.from(functions).firstMatch(SupportsFieldConversion.of(sourceFieldClass, Field.getFieldClass(targetField)));
@SuppressWarnings({ "unchecked", /* the model is checked during */
"OptionalGetWithoutIsPresent" }) final Object targetValue = function.get().apply(srcFieldValue);
if (targetValue != null) {
builder.setField(targetField, targetValue);
}
}
}
}
use of com.google.protobuf.Descriptors.FieldDescriptor in project core-java by SpineEventEngine.
the class ReferenceValidator method validate.
/**
* Returns those fields and functions, that may be used for the enrichment at the moment.
*
* @return a {@code ValidationResult} data transfer object, containing the valid fields and
* functions.
*/
ValidationResult validate() {
final List<EnrichmentFunction<?, ?>> functions = new LinkedList<>();
final Multimap<FieldDescriptor, FieldDescriptor> fields = LinkedListMultimap.create();
for (FieldDescriptor enrichmentField : enrichmentDescriptor.getFields()) {
final Collection<FieldDescriptor> sourceFields = findSourceFields(enrichmentField);
putEnrichmentsByField(functions, fields, enrichmentField, sourceFields);
}
final ImmutableMultimap<FieldDescriptor, FieldDescriptor> sourceToTargetMap = ImmutableMultimap.copyOf(fields);
final ImmutableList<EnrichmentFunction<?, ?>> enrichmentFunctions = ImmutableList.copyOf(functions);
final ValidationResult result = new ValidationResult(enrichmentFunctions, sourceToTargetMap);
return result;
}
use of com.google.protobuf.Descriptors.FieldDescriptor in project core-java by SpineEventEngine.
the class FieldShould method assertReturnsFieldClass.
private static void assertReturnsFieldClass(Class<?> expectedClass, Descriptor msgDescriptor) {
final FieldDescriptor field = msgDescriptor.getFields().get(0);
assertEquals(expectedClass, Field.getFieldClass(field));
}
Aggregations