Example usage for org.apache.commons.configuration BaseConfiguration BaseConfiguration

List of usage examples for org.apache.commons.configuration BaseConfiguration BaseConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration BaseConfiguration BaseConfiguration.

Prototype

BaseConfiguration

Source Link

Usage

From source file:com.comcast.viper.flume2storm.zookeeper.ZkClientConfigurationTest.java

@Test
public void testFromConfiguration() throws F2SConfigurationException {
    String connectionStr = "host1.whatever.org";
    int sessionTimeout = 1111;
    int connectionTimeout = 2222;
    int reconnectionDelay = 3333;
    int terminationTimeout = 4444;
    Configuration config = new BaseConfiguration();
    config.addProperty(ZkClientConfiguration.CONNECTION_STRING, connectionStr);
    config.addProperty(ZkClientConfiguration.SESSION_TIMEOUT, sessionTimeout);
    config.addProperty(ZkClientConfiguration.CONNECTION_TIMEOUT, connectionTimeout);
    config.addProperty(ZkClientConfiguration.RECONNECTION_DELAY, reconnectionDelay);
    config.addProperty(ZkClientConfiguration.TERMINATION_TIMEOUT, terminationTimeout);

    ZkClientConfiguration zkClientConfiguration = ZkClientConfiguration.from(config);
    Assert.assertEquals(connectionStr, zkClientConfiguration.getConnectionStr());
    Assert.assertEquals(sessionTimeout, zkClientConfiguration.getSessionTimeout());
    Assert.assertEquals(connectionTimeout, zkClientConfiguration.getConnectionTimeout());
    Assert.assertEquals(reconnectionDelay, zkClientConfiguration.getReconnectionDelay());
    Assert.assertEquals(terminationTimeout, zkClientConfiguration.getTerminationTimeout());
}

From source file:com.orientechnologies.orient.server.distributed.OrientdbEdgeTest.java

protected static OrientGraphFactory getGraphFactory() throws Exception {
    Configuration conf = new BaseConfiguration();

    conf.setProperty("storage.url", "remote:localhost/test");
    conf.setProperty("storage.pool-min", "1");
    conf.setProperty("storage.pool-max", "10");
    conf.setProperty("storage.user", "admin");
    conf.setProperty("storage.password", "admin");

    OGlobalConfiguration.CLIENT_CONNECT_POOL_WAIT_TIMEOUT.setValue(15000);

    verifyDatabaseExists(conf);/*  ww  w .j ava  2 s.co m*/

    return new OrientGraphFactory(conf.getString("storage.url"), conf.getString("storage.user"),
            conf.getString("storage.password")).setupPool(conf.getInt("storage.pool-min"),
                    conf.getInt("storage.pool-max"));
}

From source file:com.netflix.config.ConfigurationManagerInitClassTest.java

@Test
public void testConfigurationClass() {
    TestConfiguration config = (TestConfiguration) ConfigurationManager.getConfigInstance();
    assertTrue(ConfigurationManager.isConfigurationInstalled());
    Object configSource = DynamicPropertyFactory.getInstance().getBackingConfigurationSource();
    assertTrue(configSource == config);/*from w w  w  . j a va2 s .  c o m*/
    try {
        ConfigurationManager.install(new BaseConfiguration());
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        assertNotNull(e);
    }

}

From source file:de.berlios.jedi.common.config.ConfigurationFactory.java

/**
 * Returns a Configuration instance.<br>
 * If an exception happens when creating the configuration, an empty
 * Configuration object is returned and the exception is logged. It
 * shouldn't happen, however...//from   ww  w  . j a  v  a2s  . c o  m
 * 
 * @return A Configuration instance.
 */
public static Configuration getConfiguration() {
    try {
        return instance.getConfigurationFactory().getConfiguration();
    } catch (ConfigurationException e) {
        LogFactory.getLog(ConfigurationFactory.class).error("Configuration can not be retrieved", e);
        return new BaseConfiguration();
    }
}

From source file:cz.cas.lib.proarc.common.config.CatalogConfigurationTest.java

@Before
public void setUp() {
    conf = new BaseConfiguration();
    // catalog1//from  ww  w  .j a  v  a2 s  . com
    String prefix = Catalogs.CATALOG_PREFIX + '.' + "catalog1";
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalog1Name");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalog1URL");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalog1Type");
    catalog1ExtraOption = "extraOption";
    conf.addProperty(prefix + '.' + catalog1ExtraOption, "catalog1ExtraOption");
    // Invalid catalog
    prefix = Catalogs.CATALOG_PREFIX + '.' + "catalogInvalid";
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalogInvalidName");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalogInvalidType");
    // Not listed catalog
    prefix = Catalogs.CATALOG_PREFIX + '.' + "catalogNotListed";
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalogNotListedName");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalogNotListedURL");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalogNotListedType");
    // catalog2
    prefix = Catalogs.CATALOG_PREFIX + '.' + "catalog2";
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_NAME, "catalog2Name");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_URL, "catalog2URL");
    conf.addProperty(prefix + '.' + CatalogConfiguration.PROPERTY_TYPE, "catalog2Type");
    // catalogs declaration
    conf.addProperty(Catalogs.PROPERTY_CATALOGS, "catalog1, catalogInvalid, catalogMissing, catalog2");
    conf.addProperty("dummyProperty", "dummy");
}

From source file:com.comcast.viper.flume2storm.location.StaticLocationServiceConfigurationTest.java

/**
 * Test {@link StaticLocationServiceConfiguration#from(Configuration)}
 *
 * @throws F2SConfigurationException/*from  ww w .  j  a v a2  s  .  c om*/
 *           If the configuration is invalid
 */
@Test
public void testFromConfiguration() throws F2SConfigurationException {
    String configurationLoaderClassName = SimpleServiceProviderConfigurationLoader.class.getCanonicalName();
    String serviceProviderBase = "whatever";
    Configuration config = new BaseConfiguration();
    config.addProperty(StaticLocationServiceConfiguration.CONFIGURATION_LOADER_CLASS,
            configurationLoaderClassName);
    config.addProperty(StaticLocationServiceConfiguration.SERVICE_PROVIDER_BASE, serviceProviderBase);

    StaticLocationServiceConfiguration staticLocationServiceConfiguration = StaticLocationServiceConfiguration
            .from(config);
    Assert.assertEquals(configurationLoaderClassName,
            staticLocationServiceConfiguration.getConfigurationLoaderClassName());
    Assert.assertEquals(serviceProviderBase, staticLocationServiceConfiguration.getServiceProviderBase());
}

From source file:com.feedzai.fos.impl.weka.utils.WekaThreadSafeScorerPoolTest.java

@Test
public void testScoring() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".minIdle", 10);
    configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".maxActive", 10);
    configuration.setProperty(FosConfig.HEADER_LOCATION, "target/test-classes/models/threadsafe");
    configuration.setProperty(FosConfig.FACTORY_NAME, WekaManagerFactory.class.getName());

    FileInputStream fis = new FileInputStream("target/test-classes/models/threadsafe/test.header");
    String modelConfigJson = IOUtils.toString(fis);
    ObjectMapper mapper = new ObjectMapper();

    ModelConfig modelConfig = mapper.readValue(modelConfigJson, ModelConfig.class);

    WekaManagerConfig wekaManagerConfig = new WekaManagerConfig(new FosConfig(configuration));
    WekaThreadSafeScorer wekaThreadSafeScorer = new WekaThreadSafeScorerPool(
            new WekaModelConfig(modelConfig, wekaManagerConfig), wekaManagerConfig);

    double[] score = wekaThreadSafeScorer.score(new Object[] { 1.5, 0, "gray", "positive" });
    assertEquals(2, score.length);//from w ww.j  a v  a2s  .  com
    assertEquals(1.0, score[0] + score[1], 0.001);
}

From source file:com.feedzai.fos.server.remote.impl.RemoteClassifierFactoryTest.java

@Test
public void testCreation() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty(FosConfig.FACTORY_NAME, DummyManagerFactory.class.getName());
    configuration.setProperty(FosConfig.EMBEDDED_REGISTRY, true);
    configuration.setProperty(FosConfig.REGISTRY_PORT, 5959);
    final FosConfig fosConfig = new FosConfig(configuration);
    RemoteManagerFactory remoteClassifierFactory = new RemoteManagerFactory();

    Assert.assertTrue(Whitebox.getInternalState(remoteClassifierFactory.createManager(fosConfig),
            "manager") instanceof DummyManager);
    Assert.assertTrue(Whitebox.getInternalState(remoteClassifierFactory.createManager(fosConfig).getScorer(),
            "scorer") instanceof DummyScorer);
}

From source file:com.netflix.config.ConfigurationManagerInitFactoryTest.java

@Test
public void testConfigurationFactory() {
    Object configSource = DynamicPropertyFactory.getInstance().getBackingConfigurationSource();
    AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    assertTrue(ConfigurationManager.isConfigurationInstalled());
    assertTrue(configSource == config);/*from   w w  w .  j a  va  2  s  . c om*/
    assertTrue(config == TestConfigurationFactory.getInstance());
    try {
        DynamicPropertyFactory.initWithConfigurationSource(new BaseConfiguration());
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        assertNotNull(e);
    }
}

From source file:com.comcast.viper.flume2storm.connection.KryoNetConnectionParametersTest.java

/**
 * Test {@link KryoNetConnectionParameters} with empty configuration
 * /*from w w w . jav a2 s  .  co  m*/
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
@Test
public void testEmpty() throws F2SConfigurationException {
    KryoNetConnectionParameters params = KryoNetConnectionParameters.from(new BaseConfiguration());
    String localAddress;
    try {
        localAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        localAddress = KryoNetConnectionParameters.ADDRESS_DEFAULT;
    }
    Assert.assertEquals(localAddress, params.getAddress());
    Assert.assertEquals(KryoNetConnectionParameters.PORT_DEFAULT, params.getPort());
    Assert.assertEquals(KryoNetConnectionParameters.OBJECT_BUFFER_SIZE_DEFAULT, params.getObjectBufferSize());
    Assert.assertEquals(KryoNetConnectionParameters.WRITE_BUFFER_SIZE_DEFAULT, params.getWriteBufferSize());
}