Search in sources :

Example 1 with ReloadingStrategy

use of org.apache.commons.configuration.reloading.ReloadingStrategy in project herd by FINRAOS.

the class ReloadablePropertySourceTest method getNewPropertiesConfiguration.

/**
 * Gets a new properties configuration that will re-load the properties from a file every time it is called.
 *
 * @return the properties configuration.
 * @throws ConfigurationException if the properties configuration couldn't be created.
 */
private PropertiesConfiguration getNewPropertiesConfiguration() throws ConfigurationException {
    // Create a new properties configuration.
    // We are using this instead of a database configuration for easier testing.
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesFile);
    // Create a reloading strategy that will always reload when asked.
    // There were some problems using the FileChangedReloadingStrategy where it wasn't detecting changed files and causing some methods in this
    // JUnit to fail.
    propertiesConfiguration.setReloadingStrategy(new ReloadingStrategy() {

        @Override
        public void setConfiguration(FileConfiguration configuration) {
        }

        @Override
        public void init() {
        }

        @Override
        public boolean reloadingRequired() {
            // Tell the caller that the properties should always be reloaded.
            return true;
        }

        @Override
        public void reloadingPerformed() {
        }
    });
    return propertiesConfiguration;
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) ReloadingStrategy(org.apache.commons.configuration.reloading.ReloadingStrategy) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

FileConfiguration (org.apache.commons.configuration.FileConfiguration)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 ReloadingStrategy (org.apache.commons.configuration.reloading.ReloadingStrategy)1