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"));
}
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);
}
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());
}
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);
}
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"));
}
Aggregations