Search in sources :

Example 41 with AtlasContext

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

the class JsonJsonFlatMappingTest method testProcessJsonJsonBoxedFlatMappingPrimitiveUnrooted.

@Test
public void testProcessJsonJsonBoxedFlatMappingPrimitiveUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-boxedflatprimitive-unrooted.xml"));
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-boxedflatprimitive-unrooted.json");
    session.setDefaultSourceDocument(source);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
    AtlasTestUtil.validateJsonFlatPrimitiveBoxedPrimitiveFields(targetObject);
}
Also used : TargetFlatPrimitive(io.atlasmap.json.test.TargetFlatPrimitive) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Example 42 with AtlasContext

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

the class JsonJsonFlatMappingTest method testProcessJsonJsonFlatPrimitiveRooted.

@Test
public void testProcessJsonJsonFlatPrimitiveRooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-flatprimitive-rooted.xml"));
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-flatprimitive-rooted.json");
    session.setDefaultSourceDocument(source);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestRootedMapper testMapper = new AtlasJsonTestRootedMapper();
    TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
    AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
}
Also used : TargetFlatPrimitive(io.atlasmap.json.test.TargetFlatPrimitive) AtlasJsonTestRootedMapper(io.atlasmap.json.test.AtlasJsonTestRootedMapper) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Example 43 with AtlasContext

use of io.atlasmap.api.AtlasContext 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 44 with AtlasContext

use of io.atlasmap.api.AtlasContext 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 45 with AtlasContext

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

the class MultidocFlatMappingTest method testProcessJavaJavaFlatFieldMapping.

@Test
public void testProcessJavaJavaFlatFieldMapping() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-flatprimitive.xml").toURI());
    AtlasSession session = context.createSession();
    BaseFlatPrimitiveClass sourceJava = generateFlatPrimitiveClass(SourceFlatPrimitiveClass.class);
    session.setSourceDocument("SourceJava", sourceJava);
    String sourceJson = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-flatprimitive-unrooted.json");
    session.setSourceDocument("SourceJson", sourceJson);
    String sourceXml = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-flatprimitive-attribute.xml");
    session.setSourceDocument("SourceXml", sourceXml);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object targetJava = session.getTargetDocument("TargetJava");
    assertNotNull(targetJava);
    assertTrue(targetJava instanceof TargetFlatPrimitiveClass);
    validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) targetJava);
    Object targetJson = session.getTargetDocument("TargetJson");
    assertNotNull(targetJson);
    assertTrue(targetJson instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    TargetFlatPrimitive targetObject = testMapper.readValue((String) targetJson, TargetFlatPrimitive.class);
    AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
    Object targetXml = session.getTargetDocument("TargetXml");
    assertNotNull(targetXml);
    assertTrue(targetXml instanceof String);
    assertEquals(targetXml.toString(), "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><XmlFPA booleanField=\"false\" byteField=\"99\" charField=\"a\" doubleField=\"5.0E7\" floatField=\"4.0E7\" intField=\"2\" longField=\"30000\" shortField=\"1\"/>", targetXml);
}
Also used : TargetFlatPrimitive(io.atlasmap.json.test.TargetFlatPrimitive) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseFlatPrimitiveClass(io.atlasmap.java.test.BaseFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

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