Search in sources :

Example 66 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class XmlXmlComplexTest method testProcessXmlXmlComplexOrderAutodetectElementToAttribute.

@Test
public void testProcessXmlXmlComplexOrderAutodetectElementToAttribute() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToXml/atlasmapping-complex-order-autodetect-elementToAttribute.xml").toURI());
    AtlasSession session = context.createSession();
    String sourceXml = AtlasTestUtil.loadFileAsString("src/test/resources/xmlToXml/atlas-xml-complex-order-autodetect-element.xml");
    session.setDefaultSourceDocument(sourceXml);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><XmlOA orderId=\"8765309\"><Contact firstName=\"Ozzie\" lastName=\"Smith\" phoneNumber=\"5551212\" zipCode=\"81111\"/><Address addressLine1=\"123 Main St\" addressLine2=\"Suite 42b\" city=\"Anytown\" state=\"NY\" zipCode=\"90210\"/></XmlOA>", object);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 67 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class XmlXmlComplexTest method testProcessXmlXmlComplexOrderAutodetectAttributeToElementNS.

@Test
public void testProcessXmlXmlComplexOrderAutodetectAttributeToElementNS() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToXml/atlasmapping-complex-order-autodetect-attributeToElement-ns.xml").toURI());
    AtlasSession session = context.createSession();
    String sourceXml = AtlasTestUtil.loadFileAsString("src/test/resources/xmlToXml/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setDefaultSourceDocument(sourceXml);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    JAXBElement<XmlOrderElement> xmlOE = AtlasXmlTestHelper.unmarshal((String) object, XmlOrderElement.class);
    AtlasTestUtil.validateXmlOrderElement(xmlOE.getValue());
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) XmlOrderElement(io.atlasmap.xml.test.v2.XmlOrderElement) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 68 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class CamelAtlasmap14Test method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/camel-atlasmap-14-mapping.json");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.JSON);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(generateTwitterStatus());
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    Object output = session.getDefaultTargetDocument();
    assertEquals(String.class, output.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String) output);
    assertNotNull(outJson.get("TwitterScreenName__c"));
    assertEquals("bobvila1982", outJson.get("TwitterScreenName__c").asText());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 69 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class ConstantPropertyTest method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/constant-property-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    TargetClass output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testValue", output.getTargetName());
    assertNotEquals("testPath", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
    System.setProperty("testProp", "testProp-sysProp");
    System.setProperty("PATH", "PATH-sysProp");
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testProp-sysProp", output.getTargetName());
    assertEquals("PATH-sysProp", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
    session.getProperties().put("testProp", "testProp-runtimeProp");
    session.getProperties().put("PATH", "PATH-runtimeProp");
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testProp-runtimeProp", output.getTargetName());
    assertEquals("PATH-runtimeProp", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) Test(org.junit.Test)

Example 70 with AtlasContext

use of io.atlasmap.api.AtlasContext in project atlasmap by atlasmap.

the class OverloadedFieldActionsTest method testMappingDayOfWeekString.

@Test
public void testMappingDayOfWeekString() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(generateMappingDayOfWeek(String.class));
    AtlasSession session = context.createSession();
    SourceFlatPrimitiveClass src = new SourceFlatPrimitiveClass();
    src.setBoxedStringField("mon");
    session.setInput(src);
    context.process(session);
    Object tgt = session.getOutput();
    assertNotNull(tgt);
    assertTrue(tgt.getClass().isAssignableFrom(TargetFlatPrimitiveClass.class));
    System.out.println(((TargetFlatPrimitiveClass) tgt).getBoxedStringField());
}
Also used : TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)138 AtlasSession (io.atlasmap.api.AtlasSession)138 File (java.io.File)128 Test (org.junit.Test)119 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)111 BaseContact (io.atlasmap.java.test.BaseContact)25 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetContact (io.atlasmap.java.test.TargetContact)19 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)13 BaseOrder (io.atlasmap.java.test.BaseOrder)12 TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetTestClass (io.atlasmap.java.test.TargetTestClass)11 XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)9 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)8 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)7 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)7 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 TargetOrder (io.atlasmap.json.test.TargetOrder)4 XmlFlatPrimitiveElement (io.atlasmap.xml.test.v2.XmlFlatPrimitiveElement)4