Search in sources :

Example 6 with SourceFlatPrimitiveClass

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());
}
Also used : TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)6 AtlasSession (io.atlasmap.api.AtlasSession)6 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)6 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)6 File (java.io.File)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)2 SourceCollectionsClass (io.atlasmap.java.test.SourceCollectionsClass)1 TargetCollectionsClass (io.atlasmap.java.test.TargetCollectionsClass)1 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1