InMemoryDBSectionProcessingStrategy implements ISectionStrategy { @Override public void onLoadConfig(final IObject config) throws ConfigurationProcessingException { try { List<IObject> databaseObject = (List<IObject>) config.getValue(name); IDatabase dataBase = IOC.resolve(Keys.getOrAdd(InMemoryDatabase.class.getCanonicalName())); for (IObject collection : databaseObject) { String collectionName = (String) collection.getValue(nameFieldName); dataBase.createCollection(collectionName); List<String> documents = (List<String>) collection.getValue(documentsFieldName); for (String document : documents) { dataBase.insert(IOC.resolve(Keys.getOrAdd("IObjectByString"), document), collectionName); } } } catch (ReadValueException | InvalidArgumentException e) { throw new ConfigurationProcessingException("Error occurred loading \"inMemoryDb\" configuration section.", e); } catch (ResolutionException e) { throw new ConfigurationProcessingException("Error occurred resolving \"InMemoryDatabase\".", e); } catch (IDatabaseException e) { throw new ConfigurationProcessingException(e); } } InMemoryDBSectionProcessingStrategy(); @Override void onLoadConfig(final IObject config); @Override IFieldName getSectionName();  }
@Test public void testLoadingConfig() throws InvalidArgumentException, ResolutionException, ConfigurationProcessingException, ChangeValueException, IDatabaseException { List<String> iObjects = new LinkedList<>(); iObjects.add("{\"foo\": \"bar\"}"); iObjects.add("{\"foo1\": \"bar1\"}"); IObject inMemoryDatabaseConfig = new DSObject("{\"name\":\"my_collection_name\"}"); List<IObject> inMemoryDb = new ArrayList<>(); DSObject config = new DSObject(); inMemoryDatabaseConfig.setValue(new FieldName("documents"), iObjects); inMemoryDb.add(inMemoryDatabaseConfig); InMemoryDBSectionProcessingStrategy sectionProcessingStrategy = new InMemoryDBSectionProcessingStrategy(); config.setValue(new FieldName("inMemoryDb"), inMemoryDb); sectionProcessingStrategy.onLoadConfig(config); verify(inMemoryDatabase).createCollection("my_collection_name"); verify(inMemoryDatabase, times(2)).insert(mockObject, "my_collection_name"); }