List of usage examples for org.apache.commons.configuration Configuration setProperty
void setProperty(String key, Object value);
From source file:org.apache.whirr.ClusterSpec.java
public Configuration getConfigurationForKeysWithPrefix(String prefix) { Configuration c = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(prefix); it.hasNext();) { String key = it.next();// w ww . j ava 2s . c o m c.setProperty(key, config.getProperty(key)); } return c; }
From source file:org.apache.whirr.ClusterSpec.java
public Configuration getConfigurationForKeysMatching(Pattern pattern) { Configuration c = new PropertiesConfiguration(); for (@SuppressWarnings("unchecked") Iterator<String> it = config.getKeys(); it.hasNext();) { String key = it.next();/* ww w . j av a 2s .c om*/ if (pattern.matcher(key).matches()) { c.setProperty(key, config.getProperty(key)); } } return c; }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test public void testDefaultsCanBeOverridden() throws ConfigurationException, JSchException, IOException { Configuration conf = new PropertiesConfiguration(); conf.setProperty(ClusterSpec.Property.RUN_URL_BASE.getConfigName(), "http://example.org"); ClusterSpec spec = ClusterSpec.withNoDefaults(conf); assertThat(spec.getRunUrlBase(), is("http://example.org")); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test public void testGetConfigurationForKeysWithPrefix() throws ConfigurationException, JSchException, IOException { Configuration conf = new PropertiesConfiguration(); conf.setProperty("a.b", 1); conf.setProperty("b.a", 2); conf.setProperty("a.c", 3); ClusterSpec spec = ClusterSpec.withNoDefaults(conf); Configuration prefixConf = spec.getConfigurationForKeysWithPrefix("a"); List<String> prefixKeys = Lists.newArrayList(); Iterators.addAll(prefixKeys, prefixConf.getKeys()); assertThat(prefixKeys.size(), is(2)); assertThat(prefixKeys.get(0), is("a.b")); assertThat(prefixKeys.get(1), is("a.c")); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test public void testEnvVariableInterpolation() { Map<String, String> envMap = System.getenv(); assertThat(envMap.isEmpty(), is(false)); String undefinedEnvVar = "UNDEFINED_ENV_VAR"; assertThat(envMap.containsKey(undefinedEnvVar), is(false)); Entry<String, String> firstEntry = Iterables.get(envMap.entrySet(), 0); Configuration conf = new PropertiesConfiguration(); conf.setProperty("a", String.format("${env:%s}", firstEntry.getKey())); conf.setProperty("b", String.format("${env:%s}", undefinedEnvVar)); assertThat(conf.getString("a"), is(firstEntry.getValue())); assertThat(conf.getString("b"), is(String.format("${env:%s}", undefinedEnvVar))); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test public void testDefaultPublicKey() throws ConfigurationException, JSchException, IOException { Map<String, File> keys = KeyPair.generateTemporaryFiles(); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", keys.get("private").getAbsolutePath()); // If no public-key-file is specified it should append .pub to the private-key-file ClusterSpec spec = ClusterSpec.withNoDefaults(conf); Assert.assertEquals(IOUtils.toString(new FileReader(keys.get("public"))), spec.getPublicKey()); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testDummyPrivateKey() throws JSchException, IOException, ConfigurationException { File privateKeyFile = File.createTempFile("private", "key"); privateKeyFile.deleteOnExit();/*from w w w . jav a2 s .co m*/ Files.write( ("-----BEGIN RSA PRIVATE KEY-----\n" + "DUMMY FILE\n" + "-----END RSA PRIVATE KEY-----").getBytes(), privateKeyFile); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", privateKeyFile.getAbsolutePath()); ClusterSpec.withNoDefaults(conf); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testEncryptedPrivateKey() throws JSchException, IOException, ConfigurationException { File privateKey = KeyPair.generateTemporaryFiles("dummy").get("private"); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath()); ClusterSpec.withNoDefaults(conf);/*from ww w .j ava 2 s.c o m*/ }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testMissingPrivateKey() throws ConfigurationException { Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", "/dummy/path/that/does/not/exists"); ClusterSpec.withNoDefaults(conf);/*from ww w.jav a2s . c o m*/ }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testMissingPublicKey() throws JSchException, IOException, ConfigurationException { File privateKey = KeyPair.generateTemporaryFiles().get("private"); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath()); conf.setProperty("whirr.public-key-file", "/dummy/path/that/does/not/exists"); ClusterSpec.withNoDefaults(conf);//from w w w . j ava 2 s . c om }