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