List of usage examples for org.apache.commons.configuration2 ImmutableConfiguration getString
String getString(String key);
From source file:org.mitre.mpf.wfm.util.TestPropertiesUtil.java
@Test public void testBuilderGetConfiguration() { ImmutableConfiguration mpfPropertiesconfig = mpfPropertiesConfigurationBuilder.getCompleteConfiguration(); Assert.assertEquals(1, mpfPropertiesconfig.getInt(FRAME_INTERVAL_KEY)); String mpfHome = System.getenv(MPF_HOME_ENV_VAR); Assert.assertNotNull(mpfHome);//from w w w .j av a 2 s . c o m // ensure "${mpf.share.path}" and $MPF_HOME are interpolated Assert.assertEquals(mpfHome + "/share/models/", mpfPropertiesconfig.getString(MODELS_DIR_KEY)); // attempt to resolve every property value Iterator<String> keyIterator = mpfPropertiesconfig.getKeys(); while (keyIterator.hasNext()) { String key = keyIterator.next(); // this call does interpolation String value = mpfPropertiesconfig.getString(key); System.out.println(key + " = " + value); // DEBUG // NOTE: mpf.version.timestamp is set via maven filtering, so the next assert will fail if this test is run // through IntelliJ unless "mvn compile" is run first. That can be done on the command line, or by adding a // "Run Maven Goal" to the "Before launch" section of the IntelliJ test configuration and setting the // "Command line" to "compile". Assert.assertFalse( key + " has a value of \"" + value + "\", which contains \"${\". Failed interpolation?", value.contains("${")); } }
From source file:org.mitre.mpf.wfm.util.TestPropertiesUtil.java
@Test public void testBuilderSave() throws ConfigurationException, IOException { ImmutableConfiguration mpfPropertiesconfig = mpfPropertiesConfigurationBuilder.getCompleteConfiguration(); List<PropertyModel> newCustomPropertyModels = new ArrayList<>(); newCustomPropertyModels.add(new PropertyModel(FRAME_INTERVAL_KEY, "4", false)); newCustomPropertyModels.add(new PropertyModel(MODELS_DIR_KEY, "${" + SHARE_PATH_KEY + "}/new/dir/", false)); newCustomPropertyModels.add(new PropertyModel(TIMEOUT_KEY, "60", false)); ImmutableConfiguration newMpfPropertiesConfig = mpfPropertiesConfigurationBuilder .setAndSaveCustomProperties(newCustomPropertyModels); String mpfHome = System.getenv(MPF_HOME_ENV_VAR); Assert.assertNotNull(mpfHome);//from w w w.ja va2 s .com // ensure that current config isn't modified Assert.assertEquals(1, mpfPropertiesconfig.getInt(FRAME_INTERVAL_KEY)); Assert.assertEquals(mpfHome + "/share/models/", mpfPropertiesconfig.getString(MODELS_DIR_KEY)); Assert.assertEquals(30, mpfPropertiesconfig.getInt(TIMEOUT_KEY)); // get updated config mpfPropertiesconfig = newMpfPropertiesConfig; // mpfPropertiesConfigurationBuilder.getConfiguration(); // ensure detection value sticks Assert.assertEquals(4, mpfPropertiesconfig.getInt(FRAME_INTERVAL_KEY)); // ensure that interpolation is performed on recently-set values Assert.assertEquals(mpfHome + "/share/new/dir/", mpfPropertiesconfig.getString(MODELS_DIR_KEY)); // ensure non-detection value doesn't stick Assert.assertEquals(30, mpfPropertiesconfig.getInt(TIMEOUT_KEY)); // ensure all values written to disk Configurations configs = new Configurations(); FileBasedConfigurationBuilder<PropertiesConfiguration> mpfCustomPropertiesConfigBuilder = configs .propertiesBuilder(customPropFile.getURL()); Configuration mpfCustomPropertiesConfig = mpfCustomPropertiesConfigBuilder.getConfiguration(); Assert.assertEquals(4, mpfCustomPropertiesConfig.getInt(FRAME_INTERVAL_KEY)); Assert.assertEquals("${" + SHARE_PATH_KEY + "}/new/dir/", mpfCustomPropertiesConfig.getString(MODELS_DIR_KEY)); Assert.assertEquals(60, mpfCustomPropertiesConfig.getInt(TIMEOUT_KEY)); // reset mpfCustomPropertiesConfig.clear(); mpfCustomPropertiesConfigBuilder.save(); }