Search in sources :

Example 1 with DefaultAtlasContext

use of io.atlasmap.core.DefaultAtlasContext in project atlasmap by atlasmap.

the class DefaultAtlasContextCollectionExpansionTest method shouldNotExponentialyGrowExpandedCollectionMappings.

@Test
public void shouldNotExponentialyGrowExpandedCollectionMappings() throws Exception {
    final AtlasMapping mapping = new AtlasMapping();
    final DefaultAtlasContext context = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping) {

        protected void init() {
        // hijack initialization
        }
    };
    context.setSourceModules(Collections.singletonMap("source", new JsonModule()));
    final DefaultAtlasSession session = (DefaultAtlasSession) context.createSession();
    session.setSourceDocument("source", "{ \"array\": [ { \"property\": 1 }, { \"property\": 2 }, { \"property\": 3 } ] }");
    final Collection baseMapping = new Collection();
    baseMapping.setMappingType(MappingType.COLLECTION);
    final Mappings mappings = new Mappings();
    final Mapping singleMapping = new Mapping();
    singleMapping.setMappingType(MappingType.MAP);
    final JsonField nestedArrayField = new JsonField();
    nestedArrayField.setDocId("source");
    nestedArrayField.setPath("/array<>/property");
    singleMapping.getInputField().add(nestedArrayField);
    mappings.getMapping().add(singleMapping);
    baseMapping.setMappings(mappings);
    Method m = DefaultAtlasContext.class.getDeclaredMethod("unwrapCollectionMappings", new Class[] { DefaultAtlasSession.class, BaseMapping.class });
    m.setAccessible(true);
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
    assertEquals(1, List.class.cast(m.invoke(context, new Object[] { session, baseMapping })).size());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) DefaultAtlasContext(io.atlasmap.core.DefaultAtlasContext) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Method(java.lang.reflect.Method) JsonModule(io.atlasmap.json.module.JsonModule) DefaultAtlasSession(io.atlasmap.core.DefaultAtlasSession) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultAtlasContext (io.atlasmap.core.DefaultAtlasContext)1 DefaultAtlasSession (io.atlasmap.core.DefaultAtlasSession)1 JsonModule (io.atlasmap.json.module.JsonModule)1 JsonField (io.atlasmap.json.v2.JsonField)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 Collection (io.atlasmap.v2.Collection)1 Mapping (io.atlasmap.v2.Mapping)1 Mappings (io.atlasmap.v2.Mappings)1 Method (java.lang.reflect.Method)1 Test (org.junit.jupiter.api.Test)1