Search in sources :

Example 26 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JavaJsonCombineTest method testProcessCombineOutOfOrder.

@Test
public void testProcessCombineOutOfOrder() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-combine-outoforder.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper mapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetContact targetContact = mapper.readValue((String) object, io.atlasmap.json.test.TargetContact.class);
    assertEquals("Ozzie Smith 5551212 81111", targetContact.getFirstName());
    assertNull(targetContact.getLastName());
    assertNull(targetContact.getPhoneNumber());
    assertNull(targetContact.getZipCode());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 27 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JsonJsonAutoConversionTest method executeMapping.

protected TargetFlatPrimitive executeMapping(String fileName) throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File(fileName).toURI());
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-flatprimitive-unrooted-autoconversion.json");
    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();
    return testMapper.readValue((String) object, TargetFlatPrimitive.class);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession)

Example 28 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JsonJsonCollectionConversionTest method testProcessCollectionListSimple.

@Test
public void testProcessCollectionListSimple() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-collection-list-simple.xml").toURI());
    // contact<>.firstName -> contact<>.name
    String input = "{ \"contact\": [";
    for (int i = 0; i < 3; i++) {
        input += "{ \"firstName\": \"name" + i + "\"}";
        input += (i == 2) ? "" : ",";
    }
    input += "] }";
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(input);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    String output = "{\"contact\":[";
    for (int i = 0; i < 3; i++) {
        output += "{\"name\":\"name" + i + "\"}";
        output += (i == 2) ? "" : ",";
    }
    output += "]}";
    assertEquals(output, object);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 29 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JsonJsonCollectionConversionTest method testProcessCollectionToNonCollection.

@Test
public void testProcessCollectionToNonCollection() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-collection-to-noncollection.xml").toURI());
    // contact<>.firstName -> contact.name
    String input = "{ \"contact\": [";
    for (int i = 0; i < 3; i++) {
        input += "{ \"firstName\": \"name" + i + "\"}";
        input += (i == 2) ? "" : ",";
    }
    input += "] }";
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(input);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    String output = "{\"contact\":{\"name\":\"name2\"}}";
    assertEquals(output, object);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 30 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JsonJsonComplexTest method testProcessJsonJsonComplexOrderAutodetectUnrooted.

@Test
public void testProcessJsonJsonComplexOrderAutodetectUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-complex-order-autodetect-unrooted.xml").toURI());
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-complex-order-autodetect-unrooted.json");
    session.setDefaultSourceDocument(source);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    TargetOrder targetObject = testMapper.readValue((String) object, TargetOrder.class);
    AtlasTestUtil.validateJsonOrder(targetObject);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) TargetOrder(io.atlasmap.json.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Aggregations

AtlasSession (io.atlasmap.api.AtlasSession)157 AtlasContext (io.atlasmap.api.AtlasContext)140 Test (org.junit.Test)134 File (java.io.File)129 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)123 TargetContact (io.atlasmap.java.test.TargetContact)31 BaseContact (io.atlasmap.java.test.BaseContact)26 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)13 BaseOrder (io.atlasmap.java.test.BaseOrder)12 TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetTestClass (io.atlasmap.java.test.TargetTestClass)11 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)9 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)8 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)7 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)7 URL (java.net.URL)4 Message (org.apache.camel.Message)4