Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.nesscomputing.config.TestPrefix.java

@Test
public void testSubConfig() {
    Assert.assertThat(cfg, is(notNullValue()));

    final Configuration config = cfg.getConfiguration("prefix.of.three");

    Assert.assertThat(config, is(notNullValue()));

    final String s_cfg1 = config.getString("string-null-value");
    Assert.assertThat(s_cfg1, is(nullValue()));

    final String s_cfg2 = config.getString("string-value");
    Assert.assertThat(s_cfg2, is("the-test-value"));
}

From source file:es.udc.gii.common.eaf.log.LogTool.java

@Override
public void configure(Configuration conf) {
    if (conf.containsKey("Folder")) {
        this.folder = conf.getString("Folder");
    } else {//  w  w  w .j  av a 2 s.  co m
        ConfWarning w = new ConfWarning("Folder", this.folder);
        w.warn();
    }
    if (conf.containsKey("Name")) {
        this.name = conf.getString("Name");
    } else {
        ConfWarning w = new ConfWarning("Name", this.name);
        w.warn();
    }
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecoratorTest.java

@Test(expected = SonarException.class)
public void testLoadPatternsInvalidFile() throws IOException {
    final File tempFile = temporaryFolder.newFile("coverage.txt");
    final PrintWriter writer = new PrintWriter(tempFile);
    writer.println("invalid");
    writer.close();//  w  ww.j a v  a2s  . com

    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE))
            .thenReturn(tempFile.getAbsolutePath());
    IgnoreCoverageDecorator.loadPatterns(configuration);
    Assert.fail("must not load invalid file");
}

From source file:com.virtualparadigm.packman.processor.JPackageManager.java

private static Map<String, String> createSubstitutionContext(Configuration configuration) {
    Map<String, String> substitutionContextMap = null;
    if (configuration != null) {
        substitutionContextMap = new HashMap<String, String>();
        String key = null;/*w w  w  .jav  a  2s  . c om*/
        for (Iterator<String> it = configuration.getKeys(); it.hasNext();) {
            key = it.next();
            substitutionContextMap.put(key, configuration.getString(key));
        }
    }
    return substitutionContextMap;
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecoratorTest.java

@Test
public void testLoadPatternsFile() throws IOException {
    final File tempFile = temporaryFolder.newFile("coverage.txt");
    final PrintWriter writer = new PrintWriter(tempFile);
    writer.println("**/*;*");
    writer.close();/*from ww w.  j a v  a  2s  . c  o m*/

    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE))
            .thenReturn(tempFile.getAbsolutePath());
    final List<CoveragePattern> patterns = IgnoreCoverageDecorator.loadPatterns(configuration);
    Assert.assertNotNull("List must not be null", patterns);
    Assert.assertEquals("List must contain the exact number of entries", 1, patterns.size());
}

From source file:com.nesscomputing.config.TestPrefix.java

@Test
public void testOverride() {
    Assert.assertThat(cfg, is(notNullValue()));

    PropertiesConfiguration pc = new PropertiesConfiguration();
    pc.setProperty("prefix.of.three.string-null-value", "NULL");
    pc.setProperty("prefix.of.three.string-value", "another test value");

    Config c2 = Config.getOverriddenConfig(cfg, pc);

    final Configuration config = c2.getConfiguration("prefix.of.three");

    Assert.assertThat(config, is(notNullValue()));

    final String s_cfg1 = config.getString("string-null-value");
    Assert.assertThat(s_cfg1, is("NULL"));

    final String s_cfg2 = config.getString("string-value");
    Assert.assertThat(s_cfg2, is("another test value"));
}

From source file:edu.kit.dama.dataorganization.impl.neo4j.DataOrganizerImpl.java

@Override
public final boolean configure(Configuration pConfig) throws ConfigurationException {
    String neo4jUrl = pConfig.getString("neo4jUrl"); //http://localhost:7474
    String neo4jUser = pConfig.getString("neo4jUser");//neo4j
    String neo4jPassword = pConfig.getString("neo4jPassword");//neo4j

    return configure(neo4jUrl, neo4jUser, neo4jPassword);

}

From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactory.java

private Map<Integer, ChannelConfig> loadChannelConfigs(HierarchicalConfiguration config) {
    Map<Integer, ChannelConfig> channelConfigById = new LinkedHashMap<>();
    for (Configuration channelConfig : getConfigurationList(config.configurationsAt("channels.channel"))) {
        int id = channelConfig.getInt("[@id]");
        String name = channelConfig.getString("");
        channelConfigById.put(id, new ChannelConfig(id, name));
    }/*from  w w w  .  ja  v a2  s .  c o  m*/
    return channelConfigById;
}

From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBoltTest.java

@Test
public void testConfigure(@Injectable Configuration conf) throws ConfigurationException {
    new Expectations(bolt) {
        {/*from  w  ww. ja v  a  2 s  .  c  o m*/
            conf.getString(LogRecordDateBolt.LEVEL);
            result = "info";
            conf.getString(LogRecordDateBolt.DATE_FORMAT, anyString);
            result = "format0";
            bolt.validateDateFormat();
        }
    };
    bolt.configure(conf);
    assertThat(bolt.dateFormat, is("format0"));
    assertThat(bolt.level, is(Level.INFO));
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecoratorTest.java

@Test
public void testDecorateAllLines() throws Exception {
    final java.io.File configFile = temporaryFolder.newFile("coverage.txt");
    final PrintWriter writer = new PrintWriter(configFile);
    writer.println("src/java/net/example/Foo.java;*");
    writer.close();//w w  w  .j  a v a  2  s  .  co m

    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE))
            .thenReturn(configFile.getAbsolutePath());

    final IgnoreCoverageDecorator decorator = new IgnoreCoverageDecorator(configuration);

    final org.sonar.api.resources.File file = org.sonar.api.resources.File
            .create("src/java/net/example/Foo.java");
    final DecoratorContext context = Mockito.mock(DecoratorContext.class);
    decorator.decorate(file, context);
}