use of io.atlasmap.api.AtlasContextFactory in project atlasmap by atlasmap.
the class XMLAttributeTest method test.
@Test
public void test() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/atlasmapping-xml-attribute-ns.json");
AtlasContextFactory factory = DefaultAtlasContextFactory.getInstance();
AtlasContext context = factory.createContext(url.toURI());
AtlasSession session = context.createSession();
String xmlSource = TestHelper.readStringFromFile("data/xml-source-attribute-ns.xml");
session.setSourceDocument("po-example-schema-f81424a0-8871-4483-abaf-059cc432ea78", xmlSource);
context.process(session);
assertFalse(session.hasErrors(), TestHelper.printAudit(session));
assertFalse(session.hasWarns(), TestHelper.printAudit(session));
Object target = session.getTargetDocument("po-example-schema-b12bc688-7bf3-4626-97a2-d8c3981ecd3a");
assertNotNull(target, "target XML is null");
HashMap<String, String> namespaces = new HashMap<>();
namespaces.put("ns1", "http://tempuri.org/po.xsd");
XmlAssert.assertThat(target).withNamespaceContext(namespaces).valueByXPath("//ns1:purchaseOrder/@ns1:orderDate").isEqualTo("1985-05-02");
XmlAssert.assertThat(target).withNamespaceContext(namespaces).valueByXPath("//ns1:purchaseOrder/ns1:comment").isEqualTo("1985-05-02");
}
use of io.atlasmap.api.AtlasContextFactory in project atlasmap by atlasmap.
the class Main method process.
/**
* Processes AtlasMap data mapping.
* @throws Exception unexpected error
*/
public void process() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("atlasmapping.json");
AtlasContextFactory factory = DefaultAtlasContextFactory.getInstance();
AtlasContext context = factory.createContext(url.toURI());
AtlasSession session = context.createSession();
url = Thread.currentThread().getContextClassLoader().getResource("order.json");
String source = new String(Files.readAllBytes(Paths.get(url.toURI())));
System.out.println("Source document:\n" + source);
session.setSourceDocument("JSONSchemaSource", source);
context.process(session);
String targetDoc = (String) session.getTargetDocument("XMLInstanceSource");
printXML(targetDoc);
}
Aggregations