Search in sources :

Example 46 with Validations

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

the class BaseModuleValidationService method validateMapping.

@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
    List<Validation> validations = new ArrayList<>();
    if (getMode() == AtlasModuleMode.UNSET) {
        Validation validation = new Validation();
        validation.setMessage(String.format("No mode specified for %s/%s, skipping module validations", this.getModuleDetail().name(), this.getClass().getSimpleName()));
    }
    if (mapping != null && mapping.getMappings() != null && mapping.getMappings().getMapping() != null && !mapping.getMappings().getMapping().isEmpty()) {
        validateMappingEntries(mapping.getMappings().getMapping(), validations);
    }
    boolean found = false;
    for (DataSource ds : mapping.getDataSource()) {
        if (ds.getUri() != null && ds.getUri().startsWith(getModuleDetail().uri())) {
            found = true;
            break;
        }
    }
    if (!found) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.DATA_SOURCE);
        validation.setMessage(String.format("No DataSource with '%s' uri specified", getModuleDetail().uri()));
        validation.setStatus(ValidationStatus.ERROR);
        validations.add(validation);
    }
    return validations;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Example 47 with Validations

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

the class BaseModuleValidationService method validateMapMapping.

protected void validateMapMapping(Mapping mapping, List<Validation> validations) {
    Field sourceField = null;
    Field targetField = null;
    String mappingId = mapping.getId();
    if (mapping != null && mapping.getInputField() != null && mapping.getInputField().size() > 0) {
        sourceField = mapping.getInputField().get(0);
        if (getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
            validateField(mappingId, sourceField, FieldDirection.SOURCE, validations);
        }
    }
    if (mapping != null && mapping.getOutputField() != null && mapping.getOutputField().size() > 0) {
        targetField = mapping.getOutputField().get(0);
        if (getMode() == AtlasModuleMode.TARGET && matchDocIdOrNull(targetField.getDocId())) {
            validateField(mappingId, targetField, FieldDirection.TARGET, validations);
        }
    }
    if (sourceField != null && targetField != null && getMode() == AtlasModuleMode.SOURCE && matchDocIdOrNull(sourceField.getDocId())) {
        // FIXME Run only for SOURCE to avoid duplicate validation...
        // we should convert per module validations to plugin style
        validateSourceAndTargetTypes(mappingId, sourceField, targetField, validations);
    }
}
Also used : Field(io.atlasmap.v2.Field)

Example 48 with Validations

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

the class AtlasCoreValidationTest method testJavaToXml.

@Test
public void testJavaToXml() 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 49 with Validations

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

the class AtlasCoreValidationTest method testMappingNameNull.

@Test
public void testMappingNameNull() throws AtlasException {
    assertNotNull(context);
    assertNotNull(session);
    context.processValidation(session);
    Validations validations = session.getValidations();
    assertNotNull(validations);
    assertNotNull(validations.getValidation());
    assertFalse(validations.getValidation().isEmpty());
    boolean found = false;
    for (Validation v : validations.getValidation()) {
        if ("Mapping name must not be null nor empty".equals(v.getMessage())) {
            found = true;
            assertEquals(ValidationStatus.ERROR, v.getStatus());
            assertEquals(ValidationScope.ALL, v.getScope());
        }
        System.out.println(AtlasValidationTestHelper.validationToString(v));
    }
    assertTrue(found);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Example 50 with Validations

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

the class AtlasCoreValidationTest method testXmlToJson.

@Test
public void testXmlToJson() 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)

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