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);
}
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));
}
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));
}
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));
}
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);
}
}
Aggregations