Search in sources :

Example 26 with Validation

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

the class JavaValidationServiceTest method testValidateMappingInvalidSeparateSourceFieldType.

@Test
public void testValidateMappingInvalidSeparateSourceFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    separateFieldMapping.setId("separate.firstName.lastName");
    JavaField bIJavaField = javaModelFactory.createJavaField();
    bIJavaField.setFieldType(FieldType.BOOLEAN);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    separateFieldMapping.getInputField().add(bIJavaField);
    JavaField sOJavaField = javaModelFactory.createJavaField();
    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) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 27 with Validation

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

the class JavaValidationServiceTest method testValidateMappingInvalidCombineSourceFieldType.

@Test
public void testValidateMappingInvalidCombineSourceFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    combineFieldMapping.setId("combine.firstName.lastName");
    JavaField bIJavaField = javaModelFactory.createJavaField();
    bIJavaField.setFieldType(FieldType.STRING);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    combineFieldMapping.getInputField().add(bIJavaField);
    JavaField sOJavaField = javaModelFactory.createJavaField();
    sOJavaField.setFieldType(FieldType.BOOLEAN);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(0);
    combineFieldMapping.getOutputField().add(sOJavaField);
    atlasMapping.getMappings().getMapping().add(combineFieldMapping);
    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("combine.firstName.lastName", validation.getId());
    assertEquals("Output field 'lastName' must be of type 'STRING' for a Combine Mapping", validation.getMessage());
    assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 28 with Validation

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

the class JavaValidationServiceTest method testValidateMappingClassNotFound.

@Test
public void testValidateMappingClassNotFound() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setClassName("java.lang.String3");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(1, validations.size());
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("map.firstName.firstName", v.getId());
    assertEquals(ValidationStatus.ERROR, v.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 29 with Validation

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

the class NonNullValidatorTest method testValidateInvalid.

@Test
public void testValidateInvalid() {
    validator.validate(null, validations, null);
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validationHelper.getAllValidations().get(0);
    assertNotNull(validation);
    assertTrue("Cannot be null".equals(validation.getMessage()));
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertNull(validation.getId());
    String empty = "";
    validationHelper.getAllValidations().clear();
    validator.validate(empty, validations, "testValidateInvalid-2");
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    assertEquals(ValidationScope.MAPPING, validationHelper.getValidation().get(0).getScope());
    assertEquals("testValidateInvalid-2", validationHelper.getValidation().get(0).getId());
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.Test)

Example 30 with Validation

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

the class AtlasValidationHelperTest method setUp.

@Before
public void setUp() {
    validations = new DefaultAtlasValidationsHelper();
    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);
    atlasValidationHelper = new DefaultAtlasValidationsHelper();
}
Also used : Validation(io.atlasmap.v2.Validation) Before(org.junit.Before)

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