Search in sources :

Example 21 with Validations

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

the class JsonValidationServiceTest method testValidateMappingSourceToTargetFormatConcerns.

@Test
public void testValidateMappingSourceToTargetFormatConcerns() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JsonField in = (JsonField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.STRING);
    JsonField out = (JsonField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.LONG);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertThat(2, is(validationHelper.getCount()));
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("format")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) Assert.assertThat(org.junit.Assert.assertThat) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) After(org.junit.After) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Collector(java.util.stream.Collector) Before(org.junit.Before) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) MockField(io.atlasmap.v2.MockField) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) Assert.assertFalse(org.junit.Assert.assertFalse) AtlasJsonModelFactory(io.atlasmap.json.v2.AtlasJsonModelFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JsonField(io.atlasmap.json.v2.JsonField) Assert.assertEquals(org.junit.Assert.assertEquals) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 22 with Validations

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

the class JsonModule method processPreValidation.

@Override
public void processPreValidation(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null) {
        throw new AtlasValidationException("Invalid session: Session and AtlasMapping must be specified");
    }
    Validations validations = atlasSession.getValidations();
    JsonValidationService jsonValidationService = new JsonValidationService(getConversionService());
    jsonValidationService.setDocId(getDocId());
    List<Validation> jsonValidations = jsonValidationService.validateMapping(atlasSession.getMapping());
    if (jsonValidations != null && !jsonValidations.isEmpty()) {
        validations.getValidation().addAll(jsonValidations);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Detected " + jsonValidations.size() + " json validation notices");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreValidation completed", getDocId());
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) AtlasValidationException(io.atlasmap.api.AtlasValidationException)

Example 23 with Validations

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

the class StringLengthValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    String value = (String) target;
    if (value.isEmpty() || value.length() > maxLength || value.length() < minLength) {
        Validation validation = new Validation();
        validation.setScope(scope);
        validation.setId(id);
        validation.setMessage(String.format(violationMessage, target.toString()));
        validation.setStatus(status);
        validations.add(validation);
    }
}
Also used : Validation(io.atlasmap.v2.Validation)

Example 24 with Validations

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

the class StringPatternValidator method validate.

@Override
public void validate(Object target, List<Validation> validations, String id, ValidationStatus status) {
    Pattern regEx = Pattern.compile(pattern);
    if (target != null && supports(target.getClass())) {
        String value = (String) target;
        Matcher m = regEx.matcher(value);
        if (useMatch) {
            if (!m.matches()) {
                Validation validation = new Validation();
                validation.setScope(scope);
                validation.setId(id);
                validation.setMessage(String.format(violationMessage, target.toString()));
                validation.setStatus(status);
                validations.add(validation);
            }
        } else {
            if (m.find()) {
                Validation validation = new Validation();
                validation.setScope(scope);
                validation.setId(id);
                validation.setMessage(String.format(violationMessage, target.toString()));
                validation.setStatus(status);
                validations.add(validation);
            }
        }
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 25 with Validations

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

the class JavaValidationServiceTest method testValidateMappingSourceToTargetRangeConcerns.

@Test
public void testValidateMappingSourceToTargetRangeConcerns() 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.setFieldType(FieldType.DOUBLE);
    in.setClassName("java.lang.Double");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.LONG);
    out.setClassName("java.lang.Long");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertThat(1, is(validationHelper.getCount()));
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) AtlasJavaModelFactory(io.atlasmap.java.v2.AtlasJavaModelFactory) Assert.assertThat(org.junit.Assert.assertThat) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) After(org.junit.After) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Collector(java.util.stream.Collector) Before(org.junit.Before) AtlasConstants(io.atlasmap.api.AtlasConstants) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) MockField(io.atlasmap.v2.MockField) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) Assert.assertFalse(org.junit.Assert.assertFalse) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Assert.assertEquals(org.junit.Assert.assertEquals) 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)

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