Search in sources :

Example 21 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project ninja by ninjaframework.

the class MockNinjaProperties method createWithMode.

/**
     * Create a mock ninja properties, with the given args as the properties.
     *
     * The arguments must be in key value pairs, every second argument being the
     * value for the key name in the previous argument.
     *
     * @param mode The mode
     * @param args The key value pairs.
     * @throws AssertionError If an odd number of arguments is supplied.
     */
public static MockNinjaProperties createWithMode(String mode, String contextPath, String... args) {
    assertTrue("You must supply an even number of arguments to form key value pairs", args.length % 2 == 0);
    PropertiesConfiguration props = new PropertiesConfiguration();
    props.setDelimiterParsingDisabled(true);
    for (int i = 0; i < args.length; i += 2) {
        props.addProperty(args[i], args[i + 1]);
    }
    return new MockNinjaProperties(mode, contextPath, props);
}
Also used : PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 22 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project ninja by ninjaframework.

the class NinjaPropertiesImplToolTest method testProdThrowsError.

@Test(expected = RuntimeException.class)
public void testProdThrowsError() throws Exception {
    PropertiesConfiguration defaultConfiguration = new PropertiesConfiguration();
    Configuration compositeConfiguration = new PropertiesConfiguration();
    String uuid = UUID.randomUUID().toString();
    String baseDirWithoutTrailingSlash = "/tmp/ninja-test-" + uuid;
    boolean isProd = true;
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash, defaultConfiguration, compositeConfiguration);
    FileUtils.deleteDirectory(new File(baseDirWithoutTrailingSlash));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File) Test(org.junit.Test)

Example 23 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project ninja by ninjaframework.

the class NinjaPropertiesImplToolTest method testNothingHappensWhenApplicationSecretIsThere.

@Test
public void testNothingHappensWhenApplicationSecretIsThere() throws Exception {
    PropertiesConfiguration defaultConfiguration = new PropertiesConfiguration();
    Configuration compositeConfiguration = new PropertiesConfiguration();
    compositeConfiguration.setProperty(NinjaConstant.applicationSecret, "secret");
    String uuid = UUID.randomUUID().toString();
    String baseDirWithoutTrailingSlash = "/tmp/ninja-test-" + uuid;
    boolean isProd = true;
    // works in prod mode
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash, defaultConfiguration, compositeConfiguration);
    assertFalse(new File(baseDirWithoutTrailingSlash + "src/main/java/conf/application.conf").exists());
    isProd = false;
    // also works in the other modes:
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash, defaultConfiguration, compositeConfiguration);
    assertFalse(new File(baseDirWithoutTrailingSlash + "src/main/java/conf/application.conf").exists());
    FileUtils.deleteDirectory(new File(baseDirWithoutTrailingSlash));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File) Test(org.junit.Test)

Example 24 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project ninja by ninjaframework.

the class NinjaPropertiesImplToolTest method testMissingSecretCreatesNewOneInDevMode.

@Test
public void testMissingSecretCreatesNewOneInDevMode() throws Exception {
    String uuid = UUID.randomUUID().toString();
    String baseDirWithoutTrailingSlash = "/tmp/ninja-test-" + uuid;
    String devConf = baseDirWithoutTrailingSlash + File.separator + "src/main/java/conf/application.conf";
    PropertiesConfiguration defaultConfiguration = new PropertiesConfiguration();
    defaultConfiguration.setFileName(devConf);
    Configuration compositeConfiguration = new PropertiesConfiguration();
    boolean isProd = false;
    NinjaPropertiesImplTool.checkThatApplicationSecretIsSet(isProd, baseDirWithoutTrailingSlash, defaultConfiguration, compositeConfiguration);
    assertTrue(compositeConfiguration.getString(NinjaConstant.applicationSecret).length() == 64);
    assertTrue(defaultConfiguration.getString(NinjaConstant.applicationSecret).length() == 64);
    assertTrue(Files.toString(new File(devConf), Charsets.UTF_8).contains(NinjaConstant.applicationSecret));
    // tear down
    FileUtils.deleteDirectory(new File(baseDirWithoutTrailingSlash));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File) Test(org.junit.Test)

Example 25 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project gocd by gocd.

the class AgentAutoRegistrationPropertiesImpl method scrubRegistrationProperties.

@Override
public void scrubRegistrationProperties() {
    if (!exist()) {
        return;
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
        layout.setLineSeparator("\n");
        layout.load(reader());
        try (FileWriter out = new FileWriter(this.configFile)) {
            layout.save(out);
        }
        loadProperties();
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfigurationLayout(org.apache.commons.configuration.PropertiesConfigurationLayout)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)102 File (java.io.File)37 Configuration (org.apache.commons.configuration.Configuration)29 ConfigurationException (org.apache.commons.configuration.ConfigurationException)26 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 FileInputStream (java.io.FileInputStream)6 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)4 FileBasedInstanceDataManagerConfig (com.linkedin.pinot.core.data.manager.config.FileBasedInstanceDataManagerConfig)4