Search in sources :

Example 11 with Validation

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

the class XmlValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.

@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    separateFieldMapping.setId("separate.firstName.lastName");
    XmlField bIJavaField = xmlModelFactory.createXmlField();
    bIJavaField.setFieldType(FieldType.BOOLEAN);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    separateFieldMapping.getInputField().add(bIJavaField);
    XmlField sOJavaField = xmlModelFactory.createXmlField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(0);
    separateFieldMapping.getOutputField().add(sOJavaField);
    atlasMapping.getMappings().getMapping().add(separateFieldMapping);
    validations.addAll(sourceValidationService.validateMapping(atlasMapping));
    validations.addAll(targetValidationService.validateMapping(atlasMapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("separate.firstName.lastName", validation.getId());
    assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
    assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 12 with Validation

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

the class XmlValidationService method validateModuleField.

@Override
protected void validateModuleField(String mappingId, XmlField field, FieldDirection direction, List<Validation> validations) {
    // TODO check that it is a valid type on the AtlasContext
    validatorMap.get("xml.field.type.not.null").validate(field, validations, mappingId, ValidationStatus.WARN);
    if (direction == FieldDirection.SOURCE) {
        if (field != null) {
            validatorMap.get("input.field.type.not.null").validate(field.getFieldType(), validations, mappingId, ValidationStatus.WARN);
        }
    } else {
        if (field != null) {
            validatorMap.get("output.field.type.not.null").validate(field.getFieldType(), validations, mappingId, ValidationStatus.WARN);
        }
    }
    if (field != null) {
        if ((field.getName() == null && field.getPath() == null)) {
            Validation validation = new Validation();
            validation.setScope(ValidationScope.MAPPING);
            validation.setId(mappingId);
            validation.setMessage("One of path or name must be specified");
            validation.setStatus(ValidationStatus.ERROR);
            validations.add(validation);
        } else if (field.getName() != null && field.getPath() == null) {
            validatorMap.get("xml.field.name.not.null").validate(field.getName(), validations, mappingId);
        } else if (field.getName() == null && field.getPath() != null) {
            validatorMap.get("xml.field.path.not.null").validate(field.getPath(), validations, mappingId);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 13 with Validation

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

the class AtlasValidationTestHelperTest method setUp.

@Before
public void setUp() {
    validations = new AtlasValidationTestHelper();
    error = new Validation();
    error.setScope(ValidationScope.ALL);
    error.setMessage("Error message");
    error.setStatus(ValidationStatus.ERROR);
    validations.addValidation(error);
    warning = new Validation();
    warning.setScope(ValidationScope.DATA_SOURCE);
    warning.setId("atlas:testDataSource");
    warning.setMessage("Warning message");
    warning.setStatus(ValidationStatus.WARN);
    validations.addValidation(warning);
    info = new Validation();
    info.setScope(ValidationScope.MAPPING);
    info.setId("0001");
    info.setMessage("Information message");
    info.setStatus(ValidationStatus.INFO);
    validations.addValidation(info);
}
Also used : Validation(io.atlasmap.v2.Validation) Before(org.junit.Before)

Example 14 with Validation

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

the class DefaultAtlasValidationServiceTest method testValidateAtlasMappingFileHappyPath.

@Test
public void testValidateAtlasMappingFileHappyPath() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    assertNotNull(mapping);
    // validation
    validations.addAll(validationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Example 15 with Validation

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

the class DefaultAtlasValidationServiceTest method testValidateAtlasMappingFileHappyPath2.

@Test
public void testValidateAtlasMappingFileHappyPath2() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    assertNotNull(mapping);
    // validation
    validations.addAll(validationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Aggregations

Validation (io.atlasmap.v2.Validation)39 AtlasMapping (io.atlasmap.v2.AtlasMapping)17 Test (org.junit.Test)17 Mapping (io.atlasmap.v2.Mapping)14 Field (io.atlasmap.v2.Field)7 BaseMapping (io.atlasmap.v2.BaseMapping)6 JavaField (io.atlasmap.java.v2.JavaField)5 Validations (io.atlasmap.v2.Validations)5 DataSource (io.atlasmap.v2.DataSource)3 ArrayList (java.util.ArrayList)3 AtlasConversionService (io.atlasmap.api.AtlasConversionService)2 AtlasConverter (io.atlasmap.api.AtlasConverter)2 AtlasException (io.atlasmap.api.AtlasException)2 JsonField (io.atlasmap.json.v2.JsonField)2 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)2 AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)2 AtlasModule (io.atlasmap.spi.AtlasModule)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 FieldDirection (io.atlasmap.spi.FieldDirection)2 FieldType (io.atlasmap.v2.FieldType)2