use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.
the class AtlasEndpointTest method perform.
private void perform(List<DataSource> dataSources, String sourceDocId, String targetDocId, boolean fromStream) throws Exception {
final AtlasMapping mapping = new AtlasMapping();
mapping.getDataSource().addAll(dataSources);
final AtlasContext context = spy(AtlasContext.class);
final AtlasSession session = spy(AtlasSession.class);
when(context.createSession()).thenReturn(session);
when(session.getMapping()).thenReturn(mapping);
when(session.getAudits()).thenReturn(new Audits());
final AtlasEndpoint endpoint = new AtlasEndpoint("atlas:test.xml", new AtlasComponent(), "test.xml");
endpoint.setAtlasContext(context);
final Exchange exchange = spy(Exchange.class);
final Message inMessage = spy(Message.class);
when(inMessage.getBody()).thenReturn(fromStream ? new ByteArrayInputStream("{test}".getBytes()) : "{test}");
when(inMessage.getBody(String.class)).thenReturn("{test}");
when(exchange.getIn()).thenReturn(inMessage);
if (sourceDocId == null) {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setDefaultSourceDocument({})", invocation.getArgument(0).toString());
assertEquals("{test}", invocation.getArgument(0).toString());
return null;
}
}).when(session).setDefaultSourceDocument(any());
} else {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setSourceDocument({}, {})", invocation.getArgument(0), invocation.getArgument(1));
assertEquals(sourceDocId, invocation.getArgument(0));
assertEquals("{test}", invocation.getArgument(1));
return null;
}
}).when(session).setSourceDocument(any(), any());
}
final Message outMessage = spy(Message.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
LOG.debug("setBody({})", invocation.getArgument(0).toString());
assertEquals("<target/>", invocation.getArgument(0));
return null;
}
}).when(outMessage).setBody(any());
doNothing().when(outMessage).setHeaders(any());
doNothing().when(outMessage).setAttachments(any());
if (targetDocId == null) {
when(session.getDefaultTargetDocument()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
LOG.debug("getDefaultTargetDocument()");
return "<target/>";
}
});
} else {
when(session.getTargetDocument(any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
LOG.debug("getTargetDocument({})", invocation.getArgument(0).toString());
assertEquals(targetDocId, invocation.getArgument(0));
return "<target/>";
}
});
}
when(exchange.getOut()).thenReturn(outMessage);
endpoint.onExchange(exchange);
}
use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.
the class XmlXmlAutoConversionTest method executeMapper.
protected JAXBElement<XmlFlatPrimitiveElement> executeMapper(String fileName) throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File(fileName).toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString("src/test/resources/xmlToXml/atlas-xml-flatprimitive-attribute-autoconversion.xml");
session.setDefaultSourceDocument(source);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
JAXBElement<XmlFlatPrimitiveElement> xmlFPE = AtlasXmlTestHelper.unmarshal((String) object, XmlFlatPrimitiveElement.class);
return xmlFPE;
}
use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.
the class XmlXmlCollectionConverstionTest method testProcessCollectionListSimple.
@Test
public void testProcessCollectionListSimple() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToXml/atlasmapping-collection-list-simple.xml").toURI());
// contact<>.firstName -> contact<>.name
String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
input += "<XmlOA>";
for (int i = 0; i < 3; i++) {
input += "<contact><firstName>name" + i + "</firstName></contact>";
}
input += "</XmlOA>";
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(input);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
String output = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
output += "<XmlOA>";
for (int i = 0; i < 3; i++) {
output += "<contact><name>name" + i + "</name></contact>";
}
output += "</XmlOA>";
assertEquals(output, object);
}
use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.
the class XmlXmlCollectionConverstionTest method testProcessCollectionFromNonCollection.
@Test
public void testProcessCollectionFromNonCollection() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToXml/atlasmapping-collection-from-noncollection.xml").toURI());
// contact.firstName -> contact<>.name
String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
input += "<XmlOA>";
input += "<contact><firstName>name76</firstName></contact>";
input += "</XmlOA>";
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(input);
context.process(session);
String output = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
output += "<XmlOA>";
output += "<contact><name>name76</name></contact>";
output += "</XmlOA>";
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
assertEquals(output, object);
}
use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.
the class XmlXmlCollectionConverstionTest method testProcessCollectionArraySimple.
@Test
public void testProcessCollectionArraySimple() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToXml/atlasmapping-collection-array-simple.xml").toURI());
// contact[].firstName -> contact[].name
String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
input += "<XmlOA>";
for (int i = 0; i < 3; i++) {
input += "<contact><firstName>name" + i + "</firstName></contact>";
}
input += "</XmlOA>";
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(input);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
String output = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
output += "<XmlOA>";
for (int i = 0; i < 3; i++) {
output += "<contact><name>name" + i + "</name></contact>";
}
output += "</XmlOA>";
assertEquals(output, object);
}
Aggregations