Search in sources :

Example 26 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper 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.json").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(session.hasErrors(), printAudit(session));
    Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
    TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
    assertEquals(Integer.valueOf(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(Integer.valueOf(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    HashMap<String, String> ns = new HashMap<>();
    ns.put("ns", "http://atlasmap.io/xml/test/v2");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:orderId").isEqualTo("8765309");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:firstName").isEqualTo("Ozzie");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:lastName").isEqualTo("Smith");
}
Also used : HashMap(java.util.HashMap) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 27 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper 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.json"));
    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.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 28 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class JsonJsonFlatMappingTest method testProcessJsonJsonFlatPrimitiveUnrooted.

@Test
public void testProcessJsonJsonFlatPrimitiveUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-flatprimitive-unrooted.json"));
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-flatprimitive-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.validateJsonFlatPrimitivePrimitiveFields(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.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 29 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class JsonJsonFlatMappingTest method testProcessJsonJsonFlatPrimitiveUnrooted.

@Test
public void testProcessJsonJsonFlatPrimitiveUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-flatprimitive-unrooted.xml"));
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-flatprimitive-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.validateJsonFlatPrimitivePrimitiveFields(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 30 with AtlasJsonTestUnrootedMapper

use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.

the class XmlJsonFlatMappingTest method processXmlToJsonUnrooted.

protected void processXmlToJsonUnrooted(String mappingFile, String inputFile, boolean boxed) throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File(mappingFile));
    AtlasSession session = context.createSession();
    String sourceXml = AtlasTestUtil.loadFileAsString(inputFile);
    session.setDefaultSourceDocument(sourceXml);
    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);
    if (boxed) {
        AtlasTestUtil.validateJsonFlatPrimitiveBoxedPrimitiveFields(targetObject);
    } else {
        AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(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)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)50 AtlasSession (io.atlasmap.api.AtlasSession)50 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)50 File (java.io.File)50 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)20 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)20 Test (org.junit.Test)20 Test (org.junit.jupiter.api.Test)20 BaseContact (io.atlasmap.java.test.BaseContact)18 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)16 BaseOrder (io.atlasmap.java.test.BaseOrder)6 TargetOrder (io.atlasmap.json.test.TargetOrder)6 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)4 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)4 TargetTestClass (io.atlasmap.java.test.TargetTestClass)4 TargetContact (io.atlasmap.java.test.TargetContact)2 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)2 TargetContact (io.atlasmap.json.test.TargetContact)2 XmlOrderElement (io.atlasmap.xml.test.v2.XmlOrderElement)2