DatabaseSectionStrategy implements ISectionStrategy { @Override public void onLoadConfig(final IObject config) throws ConfigurationProcessingException { try { List<IObject> databaseObjects = (List<IObject>) config.getValue(sectionFN); for (IObject databaseObj : databaseObjects) { Object databaseOpts = IOC.resolve(Keys.getOrAdd((String) databaseObj.getValue(typeFN)), databaseObj.getValue(configFN)); IOC.register(Keys.getOrAdd((String) databaseObj.getValue(keyFN)), new SingletonStrategy(databaseOpts)); } } catch (ReadValueException | InvalidArgumentException | RegistrationException e) { throw new ConfigurationProcessingException("Error occurred loading \"database\" configuration section.", e); } catch (ResolutionException e) { throw new ConfigurationProcessingException("Error occurred resolving \"database\".", e); } } DatabaseSectionStrategy(); @Override void onLoadConfig(final IObject config); @Override IFieldName getSectionName();  }
@Test public void testLoadingConfig() throws InvalidArgumentException, ResolutionException, ConfigurationProcessingException { DSObject config = new DSObject("\n" + " {\n" + " \"database\": [\n" + " {\n" + " \"key\": \"databaseKey\"," + " \"type\": \"TestStrategy\",\n" + " \"config\": {}\n" + " }\n" + " ]\n" + " }"); DatabaseSectionStrategy strategy = new DatabaseSectionStrategy(); strategy.onLoadConfig(config); assertSame(configMock, IOC.resolve(Keys.getOrAdd("databaseKey"))); }