Search in sources :

Example 36 with Configuration

use of org.apache.commons.configuration.Configuration in project chassis by Kixeye.

the class ConfigurationBuilderTest method fetchFromArchaius.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void fetchFromArchaius() {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"), new SimpleEntry(MODULE_1_KEY_3, MODULE_1_VALUE_3 + "-override"));
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES.replace(".properties", "." + ENVIRONMENT + ".properties"), filesCreated, new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"));
    configurationBuilder.withApplicationProperties(TEST_APP_CONFIG_PROPERTIES_SPRING_PATH);
    Configuration configuration = configurationBuilder.build();
    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2 + "-override", configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", configuration.getString(MODULE_1_KEY_3));
    Assert.assertEquals(MODULE_1_VALUE_1, DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_1, null).getValue());
    Assert.assertEquals(MODULE_1_VALUE_2 + "-override", DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_2, null).getValue());
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_3, null).getValue());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) SimpleEntry(java.util.AbstractMap.SimpleEntry) Test(org.junit.Test)

Example 37 with Configuration

use of org.apache.commons.configuration.Configuration in project zaproxy by zaproxy.

the class PluginPassiveScannerUnitTest method shouldReadConfigurationSetEvenIfThereAreMultipleUnrelatedEntries.

@Test
public void shouldReadConfigurationSetEvenIfThereAreMultipleUnrelatedEntries() {
    // given
    Configuration configuration = createEmptyConfiguration();
    addConfiguration(configuration, 0, 10, null, null);
    addConfiguration(configuration, 1, "TestClassName", Boolean.TRUE, AlertThreshold.HIGH);
    addConfiguration(configuration, 2, TestPluginPassiveScanner.PLUGIN_ID, Boolean.FALSE, AlertThreshold.MEDIUM);
    addConfiguration(configuration, 3, 1011, null, AlertThreshold.LOW);
    addConfiguration(configuration, 4, "OtherTestClassName", Boolean.FALSE, AlertThreshold.OFF);
    scanner.setEnabled(true);
    scanner.setLevel(AlertThreshold.LOW);
    // when
    scanner.setConfig(configuration);
    // then
    assertThat(scanner.isEnabled(), is(false));
    assertThat(scanner.getLevel(), is(equalTo(AlertThreshold.MEDIUM)));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.Test)

Example 38 with Configuration

use of org.apache.commons.configuration.Configuration in project zaproxy by zaproxy.

the class PluginPassiveScannerUnitTest method shouldUseClassnameToReadConfigurationSet.

@Test
public void shouldUseClassnameToReadConfigurationSet() {
    // given
    Configuration configuration = createConfiguration(TestPluginPassiveScanner.class.getCanonicalName(), Boolean.FALSE, AlertThreshold.HIGH);
    scanner.setEnabled(true);
    scanner.setLevel(AlertThreshold.LOW);
    // when
    scanner.setConfig(configuration);
    // then
    assertThat(scanner.isEnabled(), is(false));
    assertThat(scanner.getLevel(), is(equalTo(AlertThreshold.HIGH)));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.Test)

Example 39 with Configuration

use of org.apache.commons.configuration.Configuration in project zaproxy by zaproxy.

the class PluginPassiveScannerUnitTest method shouldNotPersistLevelOnSaveIfDefaultValue.

@Test
public void shouldNotPersistLevelOnSaveIfDefaultValue() {
    // Given
    Configuration configuration = createEmptyConfiguration();
    scanner.setConfig(configuration);
    scanner.setLevel(AlertThreshold.MEDIUM);
    scanner.setEnabled(true);
    // When
    scanner.save();
    // Then
    assertThat(configuration.containsKey("pscans.pscanner(0).level"), is(false));
    assertThat(configuration.containsKey("pscans.pscanner(0).id"), is(false));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.Test)

Example 40 with Configuration

use of org.apache.commons.configuration.Configuration in project zaproxy by zaproxy.

the class PluginPassiveScannerUnitTest method shouldPersistEnabledStateOnSaveIfDisabled.

@Test
public void shouldPersistEnabledStateOnSaveIfDisabled() {
    // Given
    Configuration configuration = createEmptyConfiguration();
    scanner.setConfig(configuration);
    scanner.setEnabled(false);
    // When
    scanner.save();
    // Then
    assertThat(configuration.containsKey("pscans.pscanner(0).enabled"), is(true));
    assertThat(configuration.getBoolean("pscans.pscanner(0).enabled"), is(false));
    assertThat(configuration.containsKey("pscans.pscanner(0).id"), is(true));
    assertThat(configuration.getInt("pscans.pscanner(0).id"), is(equalTo(TestPluginPassiveScanner.PLUGIN_ID)));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.commons.configuration.Configuration)185 Test (org.junit.Test)51 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)44 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)23 Test (org.testng.annotations.Test)22 File (java.io.File)14 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)13 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)11 Properties (java.util.Properties)10 HashMap (java.util.HashMap)9 AtlasException (org.apache.atlas.AtlasException)9 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)9 ArrayList (java.util.ArrayList)8 ZkUtils (kafka.utils.ZkUtils)8 ConfigurationException (org.apache.commons.configuration.ConfigurationException)8 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)7 AtlasClient (org.apache.atlas.AtlasClient)6 BeforeClass (org.testng.annotations.BeforeClass)6 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)5 IOException (java.io.IOException)5