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