Search in sources :

Example 1 with ValidationResult

use of io.spine.server.outbus.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(enricher, 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);
}
Also used : Collection(java.util.Collection) ValidationResult(io.spine.server.outbus.enrich.ReferenceValidator.ValidationResult) Map(java.util.Map) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 2 with ValidationResult

use of io.spine.server.outbus.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 Enricher<?, ?> mockEnricher = mock(Enricher.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.outbus.enrich.ReferenceValidator.ValidationResult) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 3 with ValidationResult

use of io.spine.server.outbus.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(enricher, 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);
}
Also used : ValidationResult(io.spine.server.outbus.enrich.ReferenceValidator.ValidationResult) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Collection(java.util.Collection) Map(java.util.Map) Test(org.junit.Test)

Aggregations

FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ValidationResult (io.spine.server.outbus.enrich.ReferenceValidator.ValidationResult)3 Test (org.junit.Test)3 Collection (java.util.Collection)2 Map (java.util.Map)2