use of io.atlasmap.java.test.SourceFlatPrimitiveClass in project atlasmap by atlasmap.
the class MultiplicityTransformationTest method testAdd.
@Test
public void testAdd() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/atlasmapping-multiplicity-transformation-add.json");
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(url.toURI());
AtlasSession session = context.createSession();
String sourceJson = new String(Files.readAllBytes(Paths.get(Thread.currentThread().getContextClassLoader().getResource("data/json-source.json").toURI())));
session.setSourceDocument("json-source", sourceJson);
String sourceXml = new String(Files.readAllBytes(Paths.get(Thread.currentThread().getContextClassLoader().getResource("data/xml-source.xml").toURI())));
session.setSourceDocument("xml-source", sourceXml);
SourceFlatPrimitiveClass sourceJava = new SourceFlatPrimitiveClass();
sourceJava.setIntArrayField(new int[] { 1, 3, 5, 7 });
sourceJava.setBoxedIntListField(Arrays.asList(new Integer[] { 2, 4, 6, 8 }));
session.setSourceDocument("java-source", sourceJava);
context.process(session);
assertFalse(session.hasErrors(), TestHelper.printAudit(session));
Object output = session.getTargetDocument("io.atlasmap.java.test.TargetFlatPrimitiveClass");
assertEquals(TargetFlatPrimitiveClass.class, output.getClass());
TargetFlatPrimitiveClass target = TargetFlatPrimitiveClass.class.cast(output);
assertEquals(Float.valueOf((1 + 3 + 5 + 7)).floatValue(), target.getFloatField(), 1e-15);
assertEquals(Double.valueOf((1 + 3 + 5 + 7)).doubleValue(), target.getDoubleField(), 1e-15);
assertEquals(1 + 3 + 5 + 7, target.getLongField());
assertEquals(2 + 4 + 6 + 8, target.getIntField());
}
Aggregations