List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.sonar.plugins.web.core.WebSensorTest.java
private Project loadProjectFromPom() throws Exception { MavenProject pom = loadPom(TestUtils.getResource("pom.xml")); Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId()).setPom(pom) .setConfiguration(new MapConfiguration(pom.getProperties())); project.setPom(pom);/*from ww w . jav a2 s.c o m*/ project.setLanguage(new Web(new Settings())); ProjectFileSystem projectFileSystem = mock(ProjectFileSystem.class); project.setFileSystem(projectFileSystem); when(projectFileSystem.getSourceDirs()) .thenReturn(Lists.newArrayList(TestUtils.getResource("src/main/webapp"))); return project; }
From source file:org.sonar.plugins.web.markup.AbstractWebScannerPluginTester.java
protected Project loadProjectFromPom(File pomFile) throws Exception { MavenProject pom = loadPom(pomFile); Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId()).setPom(pom) .setConfiguration(new MapConfiguration(pom.getProperties())); project.setFileSystem(new MockFileSystem()); project.setPom(pom);//from w w w.ja va 2 s . c o m project.setLanguageKey(WebConstants.LANGUAGE_KEY); project.setLanguage(Web.INSTANCE); return project; }
From source file:org.sonar.plugins.xml.AbstractXmlPluginTester.java
protected Project loadProjectFromPom(File pomFile) throws URISyntaxException { MavenProject pom = loadPom(pomFile); Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId()).setPom(pom) .setConfiguration(new MapConfiguration(pom.getProperties())); project.setFileSystem(new DefaultProjectFileSystem(project, new Languages(new Xml()))); project.setPom(pom);/*w w w .j ava 2s . co m*/ project.setLanguageKey(Xml.INSTANCE.getKey()); project.setLanguage(Xml.INSTANCE); return project; }
From source file:org.sonar.server.configuration.ConfigurationFactory.java
private Configuration getDirectoriesConfiguration(ServletContextEvent sce) { MapConfiguration result = new MapConfiguration(new HashMap()); String webAppDir = autodetectWebappDeployDirectory(sce); result.setProperty(CoreConfiguration.DEPLOY_DIR, webAppDir); return result; }
From source file:org.wisdom.configuration.ConfigurationImpl.java
/** * Gets a configuration object with all the properties starting with the given prefix. * * @param prefix the prefix (without the ending `.`) * @return a configuration object with all properties with a name starting with `prefix.`, * or {@literal null} if no properties start with the given prefix. */// w w w . j ava 2s .c o m @Override public Configuration getConfiguration(String prefix) { Map<String, Object> map = new LinkedHashMap<>(); org.apache.commons.configuration.Configuration configuration = getConfiguration(); Iterator<String> keys = configuration.getKeys(prefix); while (keys != null && keys.hasNext()) { String key = keys.next(); // Remove the prefix from the keys. if (key.length() > prefix.length()) { String newKey = key.substring(prefix.length() + 1); map.put(newKey, configuration.getProperty(key)); } // Else the key was the prefix, we skip it. } if (map.isEmpty()) { return null; } else { return new ConfigurationImpl(converters, new MapConfiguration(map)); } }
From source file:org.wisdom.database.jdbc.TestWithH2.java
@Test public void testH2Memory() throws ClassNotFoundException, SQLException { Bundle bundle = mock(Bundle.class); BundleContext context = mock(BundleContext.class); when(context.getBundle()).thenReturn(bundle); when(bundle.loadClass(anyString())).thenAnswer(new Answer<Class>() { @Override//from w ww . j ava 2 s . co m public Class answer(InvocationOnMock invocation) throws Throwable { return TestWithH2.class.getClassLoader().loadClass((String) invocation.getArguments()[0]); } }); DataSourceFactory factory = mock(DataSourceFactory.class); when(factory.createDriver(any(Properties.class))).thenReturn(new Driver()); Map<String, Object> map = ImmutableMap.<String, Object>of("default.driver", "org.h2.Driver", "default.url", "jdbc:h2:mem:wisdom", "default.logStatements", "true"); MapConfiguration h2Conf = new MapConfiguration(map); Configuration conf = new ConfigurationImpl(h2Conf); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getConfiguration(BoneCPDataSources.DB_CONFIGURATION_PREFIX)).thenReturn(conf); BoneCPDataSources sources = new BoneCPDataSources(context, configuration); sources.bindFactory(factory, ImmutableMap.of(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver")); assertThat(sources).isNotNull(); sources.onStart(); assertThat(sources.getDataSources()).hasSize(1); assertThat(sources.getDataSources()).containsKeys("default"); assertThat(sources.getDataSource()).isNotNull(); assertThat(sources.getDataSource("default")).isNotNull(); sources.getConnection().createStatement().execute(Statements.CREATE_TABLE); sources.getConnection().createStatement().execute(Statements.INSERT_CARIBOU); sources.getConnection().createStatement().execute(Statements.INSERT_DENVER); sources.getConnection().createStatement().execute(Statements.INSERT_PHOENIX); ResultSet results = sources.getConnection().createStatement().executeQuery(Statements.SELECT_WITH_LAT); assertThat(results).isNotNull(); // We have only one result (CARIBOU) results.next(); assertThat(results.getString(2)).isEqualTo("Caribou"); results.close(); sources.onStop(); }
From source file:org.wisdom.database.jdbc.TestWithH2.java
@Test public void testH2MemoryWitName() throws ClassNotFoundException, SQLException { Bundle bundle = mock(Bundle.class); BundleContext context = mock(BundleContext.class); when(context.getBundle()).thenReturn(bundle); when(bundle.loadClass(anyString())).thenAnswer(new Answer<Class>() { @Override/*from w w w .j a va2s . com*/ public Class answer(InvocationOnMock invocation) throws Throwable { return TestWithH2.class.getClassLoader().loadClass((String) invocation.getArguments()[0]); } }); DataSourceFactory factory = mock(DataSourceFactory.class); when(factory.createDriver(any(Properties.class))).thenReturn(new Driver()); Map<String, Object> map = ImmutableMap.<String, Object>of("my.driver", "org.h2.Driver", "my.url", "jdbc:h2:mem:wisdom-2", "my.logStatements", "true"); MapConfiguration h2Conf = new MapConfiguration(map); Configuration conf = new ConfigurationImpl(h2Conf); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getConfiguration(BoneCPDataSources.DB_CONFIGURATION_PREFIX)).thenReturn(conf); BoneCPDataSources sources = new BoneCPDataSources(context, configuration); sources.bindFactory(factory, ImmutableMap.of(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver")); assertThat(sources).isNotNull(); sources.onStart(); assertThat(sources.getDataSources()).hasSize(1); assertThat(sources.getDataSources()).containsKeys("my"); assertThat(sources.getDataSource("my")).isNotNull(); assertThat(sources.getDataSource()).isNull(); sources.getConnection("my").createStatement().execute(Statements.CREATE_TABLE); sources.getConnection("my").createStatement().execute(Statements.INSERT_CARIBOU); sources.getConnection("my").createStatement().execute(Statements.INSERT_DENVER); sources.getConnection("my").createStatement().execute(Statements.INSERT_PHOENIX); ResultSet results = sources.getConnection("my").createStatement().executeQuery(Statements.SELECT_WITH_LAT); assertThat(results).isNotNull(); // We have only one result (CARIBOU) results.next(); assertThat(results.getString(2)).isEqualTo("Caribou"); results.close(); sources.onStop(); }
From source file:org.wisdom.database.jdbc.TestWithH2.java
@Test public void testH2File() throws ClassNotFoundException, SQLException { Bundle bundle = mock(Bundle.class); BundleContext context = mock(BundleContext.class); when(context.getBundle()).thenReturn(bundle); when(bundle.loadClass(anyString())).thenAnswer(new Answer<Class>() { @Override//from w w w.j av a 2 s. c o m public Class answer(InvocationOnMock invocation) throws Throwable { return TestWithH2.class.getClassLoader().loadClass((String) invocation.getArguments()[0]); } }); DataSourceFactory factory = mock(DataSourceFactory.class); when(factory.createDriver(any(Properties.class))).thenReturn(new Driver()); Map<String, Object> map = ImmutableMap.<String, Object>of("default.driver", "org.h2.Driver", "default.url", "jdbc:h2:target/h2test.db", "default.logStatements", "true"); MapConfiguration h2Conf = new MapConfiguration(map); Configuration conf = new ConfigurationImpl(h2Conf); ApplicationConfiguration configuration = mock(ApplicationConfiguration.class); when(configuration.getConfiguration(BoneCPDataSources.DB_CONFIGURATION_PREFIX)).thenReturn(conf); BoneCPDataSources sources = new BoneCPDataSources(context, configuration); sources.bindFactory(factory, ImmutableMap.of(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver")); assertThat(sources).isNotNull(); sources.onStart(); assertThat(sources.getDataSources()).hasSize(1); assertThat(sources.getDataSources()).containsKeys("default"); assertThat(sources.getDataSource()).isNotNull(); assertThat(sources.getDataSource("default")).isNotNull(); sources.getConnection().createStatement().execute(Statements.CREATE_TABLE); sources.getConnection().createStatement().execute(Statements.INSERT_CARIBOU); sources.getConnection().createStatement().execute(Statements.INSERT_DENVER); sources.getConnection().createStatement().execute(Statements.INSERT_PHOENIX); ResultSet results = sources.getConnection().createStatement().executeQuery(Statements.SELECT_WITH_LAT); assertThat(results).isNotNull(); // We have only one result (CARIBOU) results.next(); assertThat(results.getString(2)).isEqualTo("Caribou"); results.close(); assertThat(DB_FILE).isFile(); sources.onStop(); }
From source file:uk.q3c.krail.quartz.scheduler.DefaultKrailSchedulerFactory.java
/** * Combines potential configuration sources as described in the javadoc for {@link SchedulerConfiguration} * * @param configuration//from ww w .j av a 2 s .c om * * @return */ protected Properties composeConfiguration(SchedulerConfiguration configuration) { // Guice module configuration only (contained in configuration) if (configuration.getConfigSectionName() == null && configuration.getPropertyFileName() == null) { return configuration.getProperties(); } // else combine all sources InheritingConfiguration ic = combinedConfigurationProvider.get(); Properties guiceProperties = configuration.getProperties(); MapConfiguration guiceConfig = new MapConfiguration(guiceProperties); ic.addConfiguration(guiceConfig); if (configuration.getConfigSectionName() != null) { applicationConfiguration.getSection(configuration.getConfigSectionName()); } Properties properties = ConfigurationConverter.getProperties(ic); return properties; }