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");
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations