Search in sources :

Example 51 with Validation

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());
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.jupiter.api.Test)

Example 52 with Validation

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);
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) Test(org.junit.jupiter.api.Test)

Example 53 with Validation

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());
}
Also used : Validation(io.atlasmap.v2.Validation) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test)

Example 54 with Validation

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());
}
Also used : Validation(io.atlasmap.v2.Validation) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test)

Example 55 with Validation

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);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasModule(io.atlasmap.spi.AtlasModule) AtlasException(io.atlasmap.api.AtlasException)

Aggregations

Validation (io.atlasmap.v2.Validation)55 AtlasMapping (io.atlasmap.v2.AtlasMapping)18 Field (io.atlasmap.v2.Field)16 Test (org.junit.jupiter.api.Test)16 Mapping (io.atlasmap.v2.Mapping)14 Validations (io.atlasmap.v2.Validations)10 JavaField (io.atlasmap.java.v2.JavaField)6 BaseMapping (io.atlasmap.v2.BaseMapping)6 FieldType (io.atlasmap.v2.FieldType)6 AtlasException (io.atlasmap.api.AtlasException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AtlasConversionConcern (io.atlasmap.spi.AtlasConversionConcern)4 AtlasConversionInfo (io.atlasmap.spi.AtlasConversionInfo)4 FieldGroup (io.atlasmap.v2.FieldGroup)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 Method (java.lang.reflect.Method)4 Arrays (java.util.Arrays)4 Optional (java.util.Optional)4