use of io.atlasmap.core.DefaultAtlasSession 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());
}
Aggregations