Search in sources :

Example 66 with Field

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

the class XmlValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.

@Test
public void testValidateMappingInvalidCombineInputFieldType() {
    AtlasMapping atlasMapping = getAtlasMappingFullValid();
    Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    combineFieldMapping.setId("combine.firstName.lastName");
    XmlField bIJavaField = xmlModelFactory.createXmlField();
    bIJavaField.setFieldType(FieldType.STRING);
    bIJavaField.setValue(Boolean.TRUE);
    bIJavaField.setPath("firstName");
    combineFieldMapping.getInputField().add(bIJavaField);
    XmlField sOJavaField = xmlModelFactory.createXmlField();
    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(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("combine.firstName.lastName", validation.getId());
    assertEquals("Output 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) AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 67 with Field

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

the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNamespaces.

@Test
public void testMultipleNamespaces() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-schemaset.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(3, answer.getXmlNamespaces().getXmlNamespace().size());
    for (XmlNamespace namespace : answer.getXmlNamespaces().getXmlNamespace()) {
        switch(namespace.getAlias()) {
            case "tns":
                Assert.assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "first":
                Assert.assertEquals("io.atlasmap.xml.test:First", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "second":
                Assert.assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            default:
                Assert.fail(String.format("Unknown alias '%s'", namespace.getAlias()));
        }
    }
    List<Field> fields = answer.getFields().getField();
    Assert.assertEquals(1, fields.size());
    XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
    Assert.assertEquals("tns:RootDocument", complex.getName());
    List<XmlField> rootFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(4, rootFields.size());
    for (XmlField xmlField : rootFields) {
        switch(xmlField.getName()) {
            case "tns:Name":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Name", xmlField.getPath());
                break;
            case "tns:Value":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Value", xmlField.getPath());
                break;
            case "first:FirstElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/first:FirstElement", xmlField.getPath());
                List<XmlField> firstFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, firstFields.size());
                for (XmlField firstField : firstFields) {
                    switch(firstField.getName()) {
                        case "first:Name":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Name", firstField.getPath());
                            break;
                        case "first:Value":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Value", firstField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", firstField.getPath()));
                    }
                }
                break;
            case "second:SecondElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/second:SecondElement", xmlField.getPath());
                List<XmlField> secondFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, secondFields.size());
                for (XmlField secondField : secondFields) {
                    switch(secondField.getName()) {
                        case "second:Name":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Name", secondField.getPath());
                            break;
                        case "second:Value":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Value", secondField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", secondField.getPath()));
                    }
                }
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Example 68 with Field

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

the class BaseXmlInspectionServiceTest method debugFields.

protected void debugFields(Fields xmlFields) {
    for (Field field : xmlFields.getField()) {
        Assert.assertTrue(field instanceof XmlField);
        XmlField xmlField = (XmlField) field;
        printXmlField(xmlField);
        if (xmlField instanceof XmlComplexType) {
            debugFields(((XmlComplexType) xmlField).getXmlFields());
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField)

Example 69 with Field

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

the class XmlSchemaInspectionMultipleNamespacesTest method testSyndesis.

@Test
public void testSyndesis() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-syndesis.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
    XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
    Assert.assertEquals("tns", namespace.getAlias());
    Assert.assertEquals("http://syndesis.io/v1/swagger-connector-template/request", namespace.getUri());
    Assert.assertEquals(null, namespace.isTargetNamespace());
    List<Field> fields = answer.getFields().getField();
    Assert.assertEquals(1, fields.size());
    XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
    Assert.assertEquals("tns:request", complex.getName());
    List<XmlField> rootFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(1, rootFields.size());
    complex = XmlComplexType.class.cast(rootFields.get(0));
    Assert.assertEquals("tns:body", complex.getName());
    List<XmlField> bodyFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(1, bodyFields.size());
    complex = XmlComplexType.class.cast(bodyFields.get(0));
    Assert.assertEquals("Pet", complex.getName());
    List<XmlField> petFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(6, petFields.size());
    for (XmlField xmlField : petFields) {
        switch(xmlField.getName()) {
            case "id":
                Assert.assertEquals(FieldType.DECIMAL, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/id", xmlField.getPath());
                break;
            case "Category":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/Category", xmlField.getPath());
                List<XmlField> categoryFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, categoryFields.size());
                for (XmlField categoryField : categoryFields) {
                    switch(categoryField.getName()) {
                        case "id":
                            Assert.assertEquals(FieldType.DECIMAL, categoryField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/Category/id", categoryField.getPath());
                            break;
                        case "name":
                            Assert.assertEquals(FieldType.STRING, categoryField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/Category/name", categoryField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", categoryField.getPath()));
                    }
                }
                break;
            case "name":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/name", xmlField.getPath());
                break;
            case "photoUrl":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl", xmlField.getPath());
                List<XmlField> photoUrlFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(1, photoUrlFields.size());
                XmlField photoUrlField = photoUrlFields.get(0);
                Assert.assertEquals(FieldType.STRING, photoUrlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl/photoUrl", photoUrlField.getPath());
                break;
            case "tag":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/tag", xmlField.getPath());
                List<XmlField> tagFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(1, tagFields.size());
                XmlField tagField = tagFields.get(0);
                Assert.assertEquals(FieldType.COMPLEX, tagField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag", tagField.getPath());
                List<XmlField> tagTagFields = XmlComplexType.class.cast(tagField).getXmlFields().getXmlField();
                Assert.assertEquals(2, tagTagFields.size());
                for (XmlField tagTagField : tagTagFields) {
                    switch(tagTagField.getName()) {
                        case "id":
                            Assert.assertEquals(FieldType.DECIMAL, tagTagField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/id", tagTagField.getPath());
                            break;
                        case "name":
                            Assert.assertEquals(FieldType.STRING, tagTagField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/name", tagTagField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", tagTagField.getPath()));
                    }
                }
                break;
            case "status":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/status", xmlField.getPath());
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Example 70 with Field

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

the class XmlFieldReaderTest method testXmlFieldDoubleMinRangeOut.

@Test
public void testXmlFieldDoubleMinRangeOut() throws Exception {
    String fieldPath = "/primitive/value";
    FieldType fieldType = FieldType.DOUBLE;
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-double-min-range-out.xml");
    AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
    assertEquals(0.0, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.Test)

Aggregations

Field (io.atlasmap.v2.Field)66 Test (org.junit.Test)27 JavaField (io.atlasmap.java.v2.JavaField)26 AtlasMapping (io.atlasmap.v2.AtlasMapping)26 Mapping (io.atlasmap.v2.Mapping)25 BaseMapping (io.atlasmap.v2.BaseMapping)17 SimpleField (io.atlasmap.v2.SimpleField)17 Validation (io.atlasmap.v2.Validation)14 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)13 AtlasException (io.atlasmap.api.AtlasException)12 FieldType (io.atlasmap.v2.FieldType)12 JsonField (io.atlasmap.json.v2.JsonField)10 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 XmlField (io.atlasmap.xml.v2.XmlField)9 LookupTable (io.atlasmap.v2.LookupTable)8 ArrayList (java.util.ArrayList)8 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 ConstantField (io.atlasmap.v2.ConstantField)7 JavaClass (io.atlasmap.java.v2.JavaClass)6 Head (io.atlasmap.spi.AtlasInternalSession.Head)6