Search in sources :

Example 21 with XmlField

use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentSetAttributeValueAsString.

@Test
public void testReadDocumentSetAttributeValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order/id/@custId");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertThat(xmlField.getValue(), is("a"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 22 with XmlField

use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSOnPaths.

@Test
public void testReadDocumentMixedNamespacesNoNSOnPaths() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example_single_ns.xml");
    reader.setDocument(doc, true);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    // there is a namespace on the document but there is not on the paths....
    xmlField.setPath("/orders/order/id");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertThat(xmlField.getValue(), is("12312"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 23 with XmlField

use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.

the class XmlFieldReaderTest method readFromFile.

private AtlasInternalSession readFromFile(String fieldPath, FieldType fieldType, Path path) throws Exception {
    String input = new String(Files.readAllBytes(path));
    reader.setDocument(input, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath(fieldPath);
    xmlField.setPrimitive(Boolean.TRUE);
    xmlField.setFieldType(fieldType);
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField)

Example 24 with XmlField

use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceSetElementValueAsString.

@Test
public void testReadDocumentWithMultipleNamespaceSetElementValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example_multiple_ns.xml");
    reader.setDocument(doc, true);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/x:orders/order/y:id/@custId");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertThat(xmlField.getValue(), is("a"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 25 with XmlField

use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentSetElementValueAsString.

@Test
public void testReadDocumentSetElementValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order/id");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertThat(xmlField.getValue(), is("12312"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Aggregations

XmlField (io.atlasmap.xml.v2.XmlField)46 Test (org.junit.Test)31 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)21 Head (io.atlasmap.spi.AtlasInternalSession.Head)21 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)11 XmlDocument (io.atlasmap.xml.v2.XmlDocument)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Mapping (io.atlasmap.v2.Mapping)7 Field (io.atlasmap.v2.Field)6 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)6 File (java.io.File)6 Validation (io.atlasmap.v2.Validation)4 FieldType (io.atlasmap.v2.FieldType)3 Restriction (io.atlasmap.xml.v2.Restriction)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)2 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)2