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.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());
}
use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper 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);
}
use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.
the class XmlJsonAutoConversionTest method processXmlJsonFlatMappingAutoConversion.
protected void processXmlJsonFlatMappingAutoConversion(String mappingFile, String inputFile, int num) throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File(mappingFile).toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString(inputFile);
session.setDefaultSourceDocument(source);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
switch(num) {
case 1:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion1(targetObject);
break;
case 2:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion2(targetObject);
break;
case 3:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion3(targetObject);
break;
case 4:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion4(targetObject);
break;
case 5:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion5(targetObject);
break;
case 6:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion6(targetObject);
break;
case 7:
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFieldAutoConversion7(targetObject);
break;
default:
fail("Unexpected number: " + num);
}
}
use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.
the class XmlJsonComplexTest method processXmlToJsonOrder.
protected void processXmlToJsonOrder(String mappingFile, String inputFile, boolean rooted) throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File(mappingFile).toURI());
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);
TargetOrder targetObject = null;
if (rooted) {
AtlasJsonTestRootedMapper testMapper = new AtlasJsonTestRootedMapper();
targetObject = testMapper.readValue((String) object, TargetOrder.class);
} else {
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
targetObject = testMapper.readValue((String) object, TargetOrder.class);
}
AtlasTestUtil.validateJsonOrder(targetObject);
}
use of io.atlasmap.json.test.AtlasJsonTestUnrootedMapper in project atlasmap by atlasmap.
the class JsonJsonMultiSourceTest method testProcessBasic.
@Test
public void testProcessBasic() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-multisource-basic.xml").toURI());
AtlasSession session = context.createSession();
String sourceContact = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-contact-unrooted.json");
String sourceAddress = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-address-unrooted.json");
session.setSourceDocument("con", sourceContact);
session.setSourceDocument("addr", sourceAddress);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
TargetContact targetContact = testMapper.readValue((String) object, TargetContact.class);
assertEquals("Ozzie", targetContact.getFirstName());
assertNull(targetContact.getLastName());
assertNull(targetContact.getPhoneNumber());
assertEquals("90210", targetContact.getZipCode());
}
Aggregations