Search in sources :

Example 51 with Validations

use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testJsonToXml.

@Test
public void testJsonToXml() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertTrue(validations.getValidation().isEmpty());
}
Also used : Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Example 52 with Validations

use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.

the class AtlasCoreValidationTest method testXmlToJava.

@Test
public void testXmlToJava() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertTrue(validations.getValidation().isEmpty());
}
Also used : Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Example 53 with Validations

use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.

the class DefaultAtlasValidationService method validateLookupFieldMapping.

// mapping field validations
private void validateLookupFieldMapping(List<Mapping> fieldMappings, LookupTables lookupTables, List<Validation> validations, Set<String> usedIds) {
    Set<String> lookupFieldMappingTableNameRefs = fieldMappings.stream().map(Mapping::getLookupTableName).collect(Collectors.toSet());
    Set<String> tableNames = lookupTables.getLookupTable().stream().map(LookupTable::getName).collect(Collectors.toSet());
    if (!lookupFieldMappingTableNameRefs.isEmpty() && !tableNames.isEmpty()) {
        Set<String> disjoint = Stream.concat(lookupFieldMappingTableNameRefs.stream(), tableNames.stream()).collect(Collectors.toMap(Function.identity(), t -> true, (a, b) -> null)).keySet();
        if (!disjoint.isEmpty()) {
            boolean isInFieldList = !lookupFieldMappingTableNameRefs.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            boolean isInTableNameList = !tableNames.stream().filter(disjoint::contains).collect(Collectors.toList()).isEmpty();
            // which list has the disjoin.... if its the lookup fields then ERROR
            if (isInFieldList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("One ore more LookupFieldMapping references a non existent LookupTable name in the mapping: " + disjoint.toString());
                validation.setStatus(ValidationStatus.ERROR);
                validations.add(validation);
            }
            // uses it, else WARN
            if (isInTableNameList) {
                Validation validation = new Validation();
                validation.setScope(ValidationScope.LOOKUP_TABLE);
                validation.setMessage("A LookupTable is defined but not used by any LookupField: " + disjoint.toString());
                validation.setStatus(ValidationStatus.WARN);
                validations.add(validation);
            }
        }
    }
    for (Mapping fieldMapping : fieldMappings) {
        String mappingId = fieldMapping.getId();
        validateMappingId(mappingId, usedIds, validations);
        if (fieldMapping.getInputField() != null) {
            Validators.MAP_INPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getInputField(), validations, mappingId);
        }
        Validators.MAP_OUTPUT_NOT_NULL.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        if (fieldMapping.getOutputField() != null) {
            Validators.MAP_OUTPUT_FIELD_NOT_EMPTY.get().validate(fieldMapping.getOutputField(), validations, mappingId, ValidationStatus.WARN);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 54 with Validations

use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.

the class LookupTableNameValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    LookupTables lookupTables = (LookupTables) target;
    List<LookupTable> tables = lookupTables.getLookupTable();
    List<LookupTable> deduped = Collections.unmodifiableList(tables).stream().filter(distinctByKey(LookupTable::getName)).collect(Collectors.toList());
    if (deduped.size() != tables.size()) {
        String dupedName = findDuplicatedName(tables);
        Validation validation = new Validation();
        validation.setScope(ValidationScope.LOOKUP_TABLE);
        validation.setId(id);
        validation.setMessage(String.format(violationMessage, dupedName));
        validation.setStatus(status);
        validations.add(validation);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) LookupTables(io.atlasmap.v2.LookupTables) LookupTable(io.atlasmap.v2.LookupTable)

Example 55 with Validations

use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.

the class NonNullValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    if (target == null) {
        Validation validation = new Validation();
        validation.setScope(scope);
        validation.setId(id);
        validation.setMessage(violationMessage);
        validation.setStatus(status);
        validations.add(validation);
    } else if (target.getClass().isAssignableFrom(String.class)) {
        String value = (String) target;
        if (value.trim().isEmpty()) {
            // TODO: Add support for target value
            Validation validation = new Validation();
            validation.setScope(scope);
            validation.setId(id);
            validation.setMessage(violationMessage);
            validation.setStatus(status);
            validations.add(validation);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Aggregations

Validation (io.atlasmap.v2.Validation)36 Test (org.junit.Test)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)17 Mapping (io.atlasmap.v2.Mapping)17 Validations (io.atlasmap.v2.Validations)15 DataSource (io.atlasmap.v2.DataSource)10 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)9 FieldType (io.atlasmap.v2.FieldType)9 ValidationScope (io.atlasmap.v2.ValidationScope)9 ValidationStatus (io.atlasmap.v2.ValidationStatus)9 List (java.util.List)9 Before (org.junit.Before)9 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)8 Field (io.atlasmap.v2.Field)8 MappingType (io.atlasmap.v2.MappingType)8 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)7 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)7