use of io.spine.server.event.enrich.ReferenceValidator.ValidationResult in project core-java by SpineEventEngine.
the class ReferenceValidatorShould method store_valid_map_of_enrichment_fields_after_validation.
@Test
public void store_valid_map_of_enrichment_fields_after_validation() {
final ReferenceValidator validator = new ReferenceValidator(eventEnricher, UserDeletedEvent.class, EnrichmentBoundWithMultipleFieldsWithDifferentNames.class);
final ValidationResult result = validator.validate();
final Multimap<FieldDescriptor, FieldDescriptor> fieldMap = result.getFieldMap();
assertNotNull(fieldMap);
assertFalse(fieldMap.isEmpty());
assertSize(1, fieldMap);
final Iterator<? extends Map.Entry<?, ? extends Collection<?>>> fieldsIterator = fieldMap.asMap().entrySet().iterator();
assertTrue(fieldsIterator.hasNext());
final Map.Entry<?, ? extends Collection<?>> entry = fieldsIterator.next();
@SuppressWarnings("unchecked") final Map.Entry<FieldDescriptor, Collection<FieldDescriptor>> fieldEntry = (Map.Entry<FieldDescriptor, Collection<FieldDescriptor>>) entry;
final FieldDescriptor eventField = fieldEntry.getKey();
final String eventFieldName = eventField.getName();
assertEquals("deleted_uid", eventFieldName);
final Collection<FieldDescriptor> enrichmentFields = fieldEntry.getValue();
assertFalse(enrichmentFields.isEmpty());
assertSize(1, enrichmentFields);
final Iterator<FieldDescriptor> enrichmentFieldIterator = enrichmentFields.iterator();
assertTrue(enrichmentFieldIterator.hasNext());
final FieldDescriptor enrichmentField = enrichmentFieldIterator.next();
final String enrichmentFieldName = enrichmentField.getName();
assertEquals(USER_GOOGLE_UID_FIELD, enrichmentFieldName);
}
use of io.spine.server.event.enrich.ReferenceValidator.ValidationResult in project core-java by SpineEventEngine.
the class ReferenceValidatorShould method handle_separator_spaces_in_by_argument.
@Test
public void handle_separator_spaces_in_by_argument() {
final ReferenceValidator validator = new ReferenceValidator(eventEnricher, TaskAdded.class, EnrichmentBoundWithFieldsSeparatedWithSpaces.class);
final ValidationResult result = validator.validate();
final Multimap<FieldDescriptor, FieldDescriptor> fieldMap = result.getFieldMap();
assertFalse(fieldMap.isEmpty());
assertSize(1, fieldMap);
final Iterator<Map.Entry<FieldDescriptor, Collection<FieldDescriptor>>> mapIterator = fieldMap.asMap().entrySet().iterator();
assertTrue(mapIterator.hasNext());
final Map.Entry<FieldDescriptor, Collection<FieldDescriptor>> singleEntry = mapIterator.next();
final FieldDescriptor boundField = singleEntry.getKey();
final String boundFieldName = boundField.getName();
assertEquals("project_id", boundFieldName);
final Collection<FieldDescriptor> targets = singleEntry.getValue();
assertSize(1, targets);
final FieldDescriptor targetField = targets.iterator().next();
final String targetFieldName = targetField.getName();
assertEquals(USER_GOOGLE_UID_FIELD, targetFieldName);
}
use of io.spine.server.event.enrich.ReferenceValidator.ValidationResult 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);
}
Aggregations