use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class DefaultAtlasSessionTest method testGetFieldReader.
@Test
public void testGetFieldReader() {
AtlasFieldReader reader = new AtlasFieldReader() {
@Override
public void read(AtlasInternalSession session) throws AtlasException {
LOG.debug("read method");
}
};
session.setFieldReader(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, reader);
assertNotNull(session.getFieldReader(null));
assertNotNull(session.getFieldReader(""));
assertNotNull(session.getFieldReader(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID));
assertNotNull(session.getFieldReader("", AtlasFieldReader.class));
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class PropertyModuleTest method testProcessSourceFieldMapping.
@Test
public void testProcessSourceFieldMapping() throws AtlasException {
PropertyField field = mock(PropertyField.class);
when(field.getValue()).thenReturn("fieldValue");
Head head = mock(Head.class);
when(head.getSourceField()).thenReturn(field);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(head);
DefaultAtlasConversionService atlasConversionService = mock(DefaultAtlasConversionService.class);
when(atlasConversionService.fieldTypeFromClass(any(String.class))).thenReturn(FieldType.ANY);
module.setConversionService(atlasConversionService);
module.processSourceFieldMapping(session);
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSDocument.
@Test
public void testReadDocumentMixedNamespacesNoNSDocument() throws Exception {
String doc = getDocumentString("src/test/resources/simple_example.xml");
reader.setDocument(doc, false);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
// there is no namespace on the document but there is this field....
xmlField.setPath("/ns: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.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentElementWithMultipleNamespaceComplex.
@Test
public void testReadDocumentElementWithMultipleNamespaceComplex() throws Exception {
String doc = getDocumentString("src/test/resources/complex_example_multiple_ns.xml");
reader.setDocument(doc, true);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/q:order/id/@y:custId");
assertNull(xmlField.getValue());
Map<String, String> namespaces = new LinkedHashMap<>();
namespaces.put("http://www.example.com/q/", "q");
namespaces.put("http://www.example.com/y/", "y");
namespaces.put("http://www.example.com/x/", "");
reader.setNamespaces(namespaces);
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("cx"));
XmlField xmlField2 = AtlasXmlModelFactory.createXmlField();
xmlField2.setPath("/orders/order/id/@y:custId");
assertNull(xmlField2.getValue());
when(session.head().getSourceField()).thenReturn(xmlField2);
reader.read(session);
assertNotNull(xmlField2.getValue());
assertThat(xmlField2.getValue(), is("aa"));
XmlField xmlField3 = AtlasXmlModelFactory.createXmlField();
xmlField3.setPath("/orders/q:order[1]/id/@y:custId");
assertNull(xmlField3.getValue());
when(session.head().getSourceField()).thenReturn(xmlField3);
reader.read(session);
assertNotNull(xmlField3.getValue());
assertThat(xmlField3.getValue(), is("ea"));
}
use of io.atlasmap.spi.AtlasInternalSession 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"));
}
Aggregations