Search in sources :

Example 26 with Validations

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

the class JavaValidationService method validateClassConversion.

private void validateClassConversion(String mappingId, JavaField inputField, JavaField outField, List<Validation> validations) {
    Optional<AtlasConverter<?>> atlasConverter = getConversionService().findMatchingConverter(inputField.getClassName(), outField.getClassName());
    if (!atlasConverter.isPresent()) {
        Validation validation = new Validation();
        validation.setScope(ValidationScope.MAPPING);
        validation.setId(mappingId);
        validation.setMessage(String.format("Conversion from '%s' to '%s' is required but no converter is available", inputField.getClassName(), outField.getClassName()));
        validation.setStatus(ValidationStatus.WARN);
        validations.add(validation);
    } else {
        AtlasConversionInfo conversionInfo;
        // find the method that does the conversion
        Method[] methods = atlasConverter.get().getClass().getMethods();
        conversionInfo = Arrays.stream(methods).map(method -> method.getAnnotation(AtlasConversionInfo.class)).filter(atlasConversionInfo -> atlasConversionInfo != null).filter(atlasConversionInfo -> atlasConversionInfo.sourceType().compareTo(inputField.getFieldType()) == 0 && atlasConversionInfo.targetType().compareTo(outField.getFieldType()) == 0).findFirst().orElse(null);
        if (conversionInfo != null) {
            populateConversionConcerns(mappingId, conversionInfo, getFieldName(inputField), getFieldName(outField), validations);
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) DataInputStream(java.io.DataInputStream) Arrays(java.util.Arrays) FieldDirection(io.atlasmap.spi.FieldDirection) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) AtlasValidator(io.atlasmap.spi.AtlasValidator) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) BaseModuleValidationService(io.atlasmap.core.BaseModuleValidationService) NonNullValidator(io.atlasmap.validators.NonNullValidator) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) Field(io.atlasmap.v2.Field) Map(java.util.Map) AtlasConversionService(io.atlasmap.api.AtlasConversionService) Method(java.lang.reflect.Method) AtlasConverter(io.atlasmap.api.AtlasConverter) Logger(org.slf4j.Logger) IOException(java.io.IOException) ValidationStatus(io.atlasmap.v2.ValidationStatus) List(java.util.List) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) JavaField(io.atlasmap.java.v2.JavaField) Optional(java.util.Optional) InputStream(java.io.InputStream) AtlasConversionInfo(io.atlasmap.spi.AtlasConversionInfo) AtlasConverter(io.atlasmap.api.AtlasConverter) Method(java.lang.reflect.Method)

Example 27 with Validations

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

the class JavaJavaFlatMappingTest method testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues.

@Test
public void testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-flatprimitive.xml").toURI());
    AtlasSession session = context.createSession();
    BaseFlatPrimitiveClass sourceClass = generateFlatPrimitiveClassPrimitiveFieldsBoxedValues(SourceFlatPrimitiveClass.class);
    session.setDefaultSourceDocument(sourceClass);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetFlatPrimitiveClass);
    validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) object);
    Validations validations = session.getValidations();
    for (Validation v : validations.getValidation()) {
        printValidation(v);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseFlatPrimitiveClass(io.atlasmap.java.test.BaseFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Example 28 with Validations

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

the class AtlasCoreValidationTest method testJavaToJson.

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

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

the class AtlasCoreValidationTest method testMappingNameEmpty.

@Test
public void testMappingNameEmpty() 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());
        }
    }
    assertTrue(found);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.validation.AtlasMappingBaseTest)

Example 30 with Validations

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

the class AtlasCoreValidationTest method testJsonToJava.

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