use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentSetAttributeValueComplex.
@Test
public void testReadDocumentSetAttributeValueComplex() throws Exception {
Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
reader.setDocument(doc);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/order[2]/id[1]/@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());
assertEquals("b", xmlField.getValue());
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testThrowExceptionOnNullXmlField.
@Test
public void testThrowExceptionOnNullXmlField() throws Exception {
Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
reader.setDocument(doc);
XmlField xmlField = null;
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(xmlField);
assertThrows(AtlasException.class, () -> {
reader.read(session);
});
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentSetElementValueComplex.
@Test
public void testReadDocumentSetElementValueComplex() throws Exception {
Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
reader.setDocument(doc);
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());
assertEquals("54554555", xmlField.getValue());
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceComplex.
@Test
public void testReadDocumentWithMultipleNamespaceComplex() throws Exception {
Document doc = getDocumentFromFile("src/test/resources/complex_example_ns.xml", true);
reader.setDocument(doc);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/order[2]/id[1]/@y: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());
assertEquals("b", xmlField.getValue());
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class BaseDefaultAtlasContextTest method mockAtlasModule.
private BaseAtlasModule mockAtlasModule() throws AtlasException {
BaseAtlasModule module = spy(BaseAtlasModule.class);
when(module.getConversionService()).thenReturn(DefaultAtlasConversionService.getInstance());
when(module.createField()).thenReturn(new SimpleField());
when(module.isSupportedField(any(Field.class))).thenReturn(true);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
reader.read(session);
return null;
}
}).when(module).readSourceValue(any());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
LookupTable table = session.head().getLookupTable();
Field source = session.head().getSourceField();
Field target = session.head().getTargetField();
Object value = source.getValue();
if (table != null) {
for (LookupEntry e : table.getLookupEntry()) {
if (value.equals(e.getSourceValue())) {
value = e.getTargetValue();
}
}
}
target.setValue(value);
return null;
}
}).when(module).populateTargetField(any());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
writer.write(session);
return null;
}
}).when(module).writeTargetValue(any());
return module;
}
Aggregations