use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class NonNullValidatorTest method testValidateInvalid.
@Test
public void testValidateInvalid() {
validator.validate(null, validations, null);
assertTrue(validationHelper.hasErrors());
assertEquals(Integer.valueOf(1), Integer.valueOf(validationHelper.getCount()));
Validation validation = validationHelper.getAllValidations().get(0);
assertNotNull(validation);
assertTrue("Cannot be null".equals(validation.getMessage()));
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertNull(validation.getId());
String empty = "";
validationHelper.getAllValidations().clear();
validator.validate(empty, validations, "testValidateInvalid-2");
assertTrue(validationHelper.hasErrors());
assertEquals(Integer.valueOf(1), Integer.valueOf(validationHelper.getCount()));
assertEquals(ValidationScope.MAPPING, validationHelper.getValidation().get(0).getScope());
assertEquals("testValidateInvalid-2", validationHelper.getValidation().get(0).getId());
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class DefaultAtlasSessionTest method testGetSetValidations.
@Test
public void testGetSetValidations() {
assertNotNull(session.getValidations());
assertNotNull(session.getValidations().getValidation());
assertTrue(session.getValidations().getValidation().size() == 0);
Validations validations = new Validations();
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId("bar");
validations.getValidation().add(validation);
session.setValidations(validations);
assertNotNull(session.getValidations());
assertNotNull(session.getValidations().getValidation());
assertTrue(session.getValidations().getValidation().size() == 1);
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class JsonValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.
@Test
public void testValidateMappingInvalidCombineInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
combineFieldMapping.setId("combine.firstName.lastName");
JsonField bIJavaField = new JsonField();
bIJavaField.setFieldType(FieldType.STRING);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
combineFieldMapping.getInputField().add(bIJavaField);
JsonField sOJavaField = new JsonField();
sOJavaField.setFieldType(FieldType.BOOLEAN);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
combineFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(combineFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(Integer.valueOf(1), Integer.valueOf(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("combine.firstName.lastName", validation.getId());
assertEquals("Target field 'lastName' must be of type 'STRING' for a Combine Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class JsonValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.
@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
separateFieldMapping.setId("separate.firstName.lastName");
JsonField bIJavaField = new JsonField();
bIJavaField.setFieldType(FieldType.BOOLEAN);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
separateFieldMapping.getInputField().add(bIJavaField);
JsonField sOJavaField = new JsonField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
separateFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(separateFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(Integer.valueOf(1), Integer.valueOf(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("separate.firstName.lastName", validation.getId());
assertEquals("Source field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.v2.Validation in project atlasmap by atlasmap.
the class DefaultAtlasContext method processValidation.
@Override
public void processValidation(AtlasSession userSession) throws AtlasException {
if (!(userSession instanceof DefaultAtlasSession)) {
throw new AtlasException(String.format("Unsupported session class '%s'", userSession.getClass().getName()));
}
if (!this.equals(userSession.getAtlasContext())) {
throw new AtlasException("Cannot execute AtlasSession created by the other AtlasContext");
}
DefaultAtlasSession session = (DefaultAtlasSession) userSession;
if (LOG.isDebugEnabled()) {
LOG.debug("Begin processValidation {}", session);
}
List<Validation> validations = getContextFactory().getValidationService().validateMapping(session.getMapping());
if (validations != null && !validations.isEmpty()) {
session.getValidations().getValidation().addAll(validations);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Detected {} core validation notices", validations == null ? 0 : validations.size());
}
for (AtlasModule module : getSourceModules().values()) {
module.processPreValidation(session);
}
for (AtlasModule module : getTargetModules().values()) {
module.processPreValidation(session);
}
if (LOG.isDebugEnabled()) {
LOG.debug("End processValidation {}", session);
}
}
Aggregations