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()));
}
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());
}
}
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);
}
}
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);
}
}
}
}
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());
}
Aggregations