Search in sources :

Example 1 with AtlasContextFactory

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");
}
Also used : HashMap(java.util.HashMap) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasContextFactory(io.atlasmap.api.AtlasContextFactory) Test(org.junit.jupiter.api.Test)

Example 2 with AtlasContextFactory

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);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasContextFactory(io.atlasmap.api.AtlasContextFactory)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)2 AtlasContextFactory (io.atlasmap.api.AtlasContextFactory)2 AtlasSession (io.atlasmap.api.AtlasSession)2 DefaultAtlasContextFactory (io.atlasmap.core.DefaultAtlasContextFactory)2 URL (java.net.URL)2 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1