Search in sources :

Example 1 with XmlOrderElement

use of io.atlasmap.xml.test.v2.XmlOrderElement in project atlasmap by atlasmap.

the class MultidocComplexTest method testProcessComplexBasicNullContact.

@Test
public void testProcessComplexBasicNullContact() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
    AtlasSession session = context.createSession();
    BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    javaSourceOrder.setContact(null);
    session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
    String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
    session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
    String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    TargetTestClass targetTestClass = (TargetTestClass) session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), targetTestClass.getClass().getName());
    assertEquals(TargetContact.class.getName(), targetTestClass.getContact().getClass().getName());
    assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
    assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
    assertEquals("Smith", targetTestClass.getContact().getLastName());
    Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
    assertTrue(jsonTargetOrder instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
    assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertNull(jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
    assertEquals("8765309", xmlOE.getOrderId());
    assertEquals(null, xmlOE.getContact().getLastName());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) XmlOrderElement(io.atlasmap.xml.test.v2.XmlOrderElement) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 2 with XmlOrderElement

use of io.atlasmap.xml.test.v2.XmlOrderElement in project atlasmap by atlasmap.

the class MultidocComplexTest method testProcessBasic.

@Test
public void testProcessBasic() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
    AtlasSession session = context.createSession();
    BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
    String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
    session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
    String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
    TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
    assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
    assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
    assertEquals("Smith", targetTestClass.getContact().getLastName());
    Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
    assertTrue(jsonTargetOrder instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
    assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
    assertEquals("8765309", xmlOE.getOrderId());
    assertEquals("Ozzie", xmlOE.getContact().getFirstName());
    assertEquals("Smith", xmlOE.getContact().getLastName());
}
Also used : AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) XmlOrderElement(io.atlasmap.xml.test.v2.XmlOrderElement) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 3 with XmlOrderElement

use of io.atlasmap.xml.test.v2.XmlOrderElement 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)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)3 AtlasSession (io.atlasmap.api.AtlasSession)3 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)3 XmlOrderElement (io.atlasmap.xml.test.v2.XmlOrderElement)3 File (java.io.File)3 Test (org.junit.Test)3 BaseOrder (io.atlasmap.java.test.BaseOrder)2 TargetTestClass (io.atlasmap.java.test.TargetTestClass)2 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)2 TargetContact (io.atlasmap.java.test.TargetContact)1