Search in sources :

Example 36 with XmlField

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

the class XmlFieldReaderTest method testReadDocumentSetValueFromAttrAsString.

@Test
public void testReadDocumentSetValueFromAttrAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/@totalCost");
    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("12525.00"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 37 with XmlField

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

the class XmlFieldWriterTest method testThrowExceptionOnNullXmlField.

@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullXmlField() throws Exception {
    createWriter();
    XmlField field = null;
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(mock(Field.class));
    when(session.head().getTargetField()).thenReturn(field);
    writer.write(session);
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 38 with XmlField

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

the class XmlFieldReaderTest method testReadDocumentMisMatchedFieldNameAT416.

@Test
public void testReadDocumentMisMatchedFieldNameAT416() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    // correct field name should be id or id[1]
    xmlField.setPath("/orders/order/id1");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNull(xmlField.getValue());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 39 with XmlField

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

the class XmlFieldReaderTest method testThrowExceptionOnNullDocument.

@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullDocument() throws Exception {
    reader.setDocument(null, false);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(new XmlField());
    reader.read(session);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 40 with XmlField

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

the class XmlFieldReaderTest method testReadDocumentSetElementValueComplex.

@Test
public void testReadDocumentSetElementValueComplex() throws Exception {
    String doc = getDocumentString("src/test/resources/complex_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order[3]/id[1]");
    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("54554555"));
}
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