Search in sources :

Example 16 with Validation

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

the class StringLengthValidatorTest method testValidateInvalid.

@Test
public void testValidateInvalid() {
    String pass = "";
    validator.validate(pass, validations, "testValidateInvalid");
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getAllValidations().size()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("testValidateInvalid", validation.getId());
    assertTrue("Must be of this length".equals(validation.getMessage()));
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.Test)

Example 17 with Validation

use of io.atlasmap.v2.Validation 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 18 with Validation

use of io.atlasmap.v2.Validation 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 19 with Validation

use of io.atlasmap.v2.Validation 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 20 with Validation

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

the class JavaValidationServiceTest method testValidateAtlasMappingFileConversionRequired.

@Test
public void testValidateAtlasMappingFileConversionRequired() 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.COMPLEX);
    in.setClassName("io.atlasmap.java.module.MockJavaClass");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.STRING);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertThat(1, is(validationHelper.getCount()));
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("map.firstName.firstName", v.getId());
    assertEquals(ValidationStatus.WARN, 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)

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