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

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

Introduction

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

Prototype

boolean containsKey(String key);

Source Link

Document

Check if the configuration contains the specified key.

Usage

From source file:org.sonar.plugins.php.phpunit.PhpUnitExecutorTest.java

@Test
public void testNoIgnoreDefaultConfigurationFile() {
    PhpUnitConfiguration config = mock(PhpUnitConfiguration.class);
    Project project = mock(Project.class);
    MavenProject mProject = mock(MavenProject.class);
    when(project.getPom()).thenReturn(mProject);
    when(mProject.getBasedir()).thenReturn(new File("toto"));

    Configuration configuration = mock(Configuration.class);
    when(project.getConfiguration()).thenReturn(configuration);
    when(config.getProject()).thenReturn(project);

    when(configuration.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(false);
    when(configuration.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);

    ProjectFileSystem pfs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(pfs);
    File testDir = new File("c:/php/math-php-test/sources/test");
    when(project.getFileSystem().getTestDirs()).thenReturn(Arrays.asList(testDir));

    PhpUnitExecutor executor = new PhpUnitExecutor(config, project);
    when(config.shouldRunCoverage()).thenReturn(false);
    when(config.getCoverageReportFile()).thenReturn(new File("phpUnit.coverage.xml"));
    List<String> commandLine = executor.getCommandLine();
    assertThat(commandLine).isNotEmpty();
    assertThat(commandLine).excludes(PHPUNIT_IGNORE_CONFIGURATION_OPTION);
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitExecutorTest.java

@Test
public void testAnalyseTestDirectory() {
    PhpUnitConfiguration config = mock(PhpUnitConfiguration.class);
    Project project = mock(Project.class);
    MavenProject mProject = mock(MavenProject.class);
    when(project.getPom()).thenReturn(mProject);
    when(mProject.getBasedir()).thenReturn(new File("toto"));

    ProjectFileSystem pfs = mock(ProjectFileSystem.class);
    when(project.getFileSystem()).thenReturn(pfs);

    Configuration configuration = mock(Configuration.class);
    when(project.getConfiguration()).thenReturn(configuration);
    when(config.getProject()).thenReturn(project);

    when(configuration.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(false);
    when(configuration.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);

    File testDir = new File("c:/php/math-php-test/sources/test");
    when(project.getFileSystem().getTestDirs()).thenReturn(Arrays.asList(testDir));

    when(configuration.containsKey(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)).thenReturn(true);
    when(configuration.getBoolean(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)).thenReturn(true);

    PhpUnitExecutor executor = new PhpUnitExecutor(config, project);
    when(config.shouldRunCoverage()).thenReturn(false);
    when(config.getCoverageReportFile()).thenReturn(new File("phpUnit.coverage.xml"));
    List<String> commandLine = executor.getCommandLine();
    assertThat(commandLine).isNotEmpty();
    assertThat(commandLine).excludes(PHPUNIT_IGNORE_CONFIGURATION_OPTION);
    assertThat(commandLine).contains(testDir.toString());
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitExecutorTest.java

@Test
public void testDoNotAnalyseTestDirectory() {
    PhpUnitConfiguration config = mock(PhpUnitConfiguration.class);
    Project project = mock(Project.class);
    MavenProject mProject = mock(MavenProject.class);
    when(project.getPom()).thenReturn(mProject);
    when(mProject.getBasedir()).thenReturn(new File("toto"));
    ProjectFileSystem pfs = mock(ProjectFileSystem.class);

    when(project.getFileSystem()).thenReturn(pfs);
    Configuration configuration = mock(Configuration.class);
    when(project.getConfiguration()).thenReturn(configuration);
    when(config.getProject()).thenReturn(project);

    when(configuration.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(false);
    when(configuration.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);

    when(configuration.containsKey(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)).thenReturn(true);
    when(configuration.getBoolean(PHPUNIT_ANALYZE_TEST_DIRECTORY_KEY)).thenReturn(false);

    File testDir = new File("c:/php/math-php-test/sources/test");
    when(project.getFileSystem().getTestDirs()).thenReturn(Arrays.asList(testDir));

    PhpUnitExecutor executor = new PhpUnitExecutor(config, project);
    when(config.shouldRunCoverage()).thenReturn(false);
    when(config.getCoverageReportFile()).thenReturn(new File("phpUnit.coverage.xml"));
    List<String> commandLine = executor.getCommandLine();
    assertThat(commandLine).isNotEmpty();
    assertThat(commandLine).excludes(PHPUNIT_IGNORE_CONFIGURATION_OPTION);
    assertThat(commandLine).excludes(testDir.toString());
}

From source file:org.sonar.plugins.php.phpunit.PhpUnitExecutorTest.java

@Test
public void testAnalyseMultipleTestDirectories() {
    PhpUnitConfiguration config = mock(PhpUnitConfiguration.class);
    Project project = mock(Project.class);
    MavenProject mProject = mock(MavenProject.class);
    when(project.getPom()).thenReturn(mProject);
    when(mProject.getBasedir()).thenReturn(new File("toto"));
    ProjectFileSystem pfs = mock(ProjectFileSystem.class);

    when(project.getFileSystem()).thenReturn(pfs);
    Configuration configuration = mock(Configuration.class);
    when(project.getConfiguration()).thenReturn(configuration);
    when(config.getProject()).thenReturn(project);

    when(configuration.containsKey(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(false);
    when(configuration.getBoolean(PHPUNIT_IGNORE_CONFIGURATION_PROPERTY_KEY)).thenReturn(true);

    File testDir = new File("c:/php/math-php-test/sources/test");
    File testDir2 = new File("c:/php/math-php-test/sources/test2");
    when(project.getFileSystem().getTestDirs()).thenReturn(Arrays.asList(testDir, testDir2));

    PhpUnitExecutor executor = new PhpUnitExecutor(config, project);
    when(config.shouldRunCoverage()).thenReturn(false);
    when(config.getCoverageReportFile()).thenReturn(new File("phpUnit.coverage.xml"));
    List<String> commandLine = executor.getCommandLine();
    assertThat(commandLine).isNotEmpty();

    boolean found = false;
    for (String command : commandLine) {
        if (command != null && command.startsWith(PHPUNIT_CONFIGURATION_OPTION)) {
            found = true;//from   www  .  j  a  v a  2 s .  co m
            break;
        }
    }
    assertThat(found).isTrue();
    assertThat(commandLine).excludes(PHPUNIT_IGNORE_CONFIGURATION_OPTION);
    assertThat(commandLine).excludes(testDir.toString());
}

From source file:org.ublog.benchmark.social.SocialBenchmark.java

@Override
public void initialize(Configuration conf) throws ConfigurationException {
    this.initialTweetsFactor = conf.getDouble("benchmark.social.initialTweetsFactor");

    Utils.MAX_MESSAGES_IN_TIMELINE = conf.getInt("benchmark.social.maximumMessagesTimeline");
    Utils.MaxNTweets = conf.getInt("benchmark.social.maximumTweetsPerUser");
    long seedNextOperation = conf.containsKey("benchmark.social.seedNextOperation")
            ? conf.getLong("benchmark.social.seedNextOperation")
            : System.nanoTime();/*from   w  w  w  .j  a  v  a  2s .  co  m*/
    long seedOwner = conf.containsKey("benchmark.social.seedOwner") ? conf.getLong("benchmark.social.seedOwner")
            : System.nanoTime();
    long seedTopic = conf.containsKey("benchmark.social.seedTopic") ? conf.getLong("benchmark.social.seedTopic")
            : System.nanoTime();
    long seedStartFollow = conf.containsKey("benchmark.social.seedStartFollow")
            ? conf.getLong("benchmark.social.seedStartFollow")
            : System.nanoTime();

    this.rndOp = new Random(seedNextOperation);
    this.rndOwner = new Random(seedOwner);
    this.rndTopic = new Random(seedTopic);
    this.rndStartFollow = new Random(seedStartFollow);

    this.probabilitySearchPerTopic = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerTopic");
    this.probabilitySearchPerOwner = conf.getDouble("benchmark.social.probabilities.probabilitySearchPerOwner");
    this.probabilityGetRecentTweets = conf
            .getDouble("benchmark.social.probabilities.probabilityGetRecentTweets");
    this.probabilityGetFriendsTimeline = conf
            .getDouble("benchmark.social.probabilities.probabilityGetFriendsTimeline");
    this.probabilityStartFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStartFollowing");
    this.probabilityStopFollowing = conf.getDouble("benchmark.social.probabilities.probabilityStopFollowing");
    if (this.probabilityGetFriendsTimeline + this.probabilityGetRecentTweets + this.probabilitySearchPerOwner
            + this.probabilitySearchPerTopic + this.probabilityStartFollowing
            + this.probabilityStopFollowing > 1) {
        logger.warn("The sum of all probabilities must be less or equal than 1.");
        throw new ConfigurationException("The sum of all probabilities must be less or equal than 1.");
    }

    String serverName = conf.getString("benchmark.server.name");
    int serverPort = conf.getInt("benchmark.server.port");
    this.remoteGraphServer = this.getRemoteGraphServer(serverName, serverPort);
    try {
        this.hasInitiated = this.remoteGraphServer.init(this.totalSize);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:org.w3.i18n.AssertionProvider.java

private static void interpretAssertionDefinition(String prefix, Configuration configuration) {
    // Retieve the required properties for the prefix.
    String titleProperty = configuration.containsKey(prefix + ".title")
            ? configuration.getString(prefix + ".title")
            : null;//from w ww.  ja v a 2  s  .  co  m
    String descriptionProperty = configuration.containsKey(prefix + ".description")
            ? configuration.getString(prefix + ".description")
            : null;
    if (titleProperty == null || descriptionProperty == null) {
        throw new RuntimeException("Invalid assertion definition in"
                + " configuration. Each definition should have a 'title'"
                + " and 'description' property. Prefix: " + prefix + ", title property: \"" + titleProperty
                + "\", description property: \"" + descriptionProperty + "\", configuration: " + configuration);
    }

    // Prepare definition details.
    String[] prefixSplit = prefix.split("\\.");
    String id = prefixSplit[0].trim();
    Level level = Level.valueOf(prefixSplit[1].trim());
    String title = titleProperty.trim();
    String description = descriptionProperty.trim();

    // Check for duplicate definition key.
    Key key = new Key(id, level);
    if (definitions.containsKey(key)) {
        throw new RuntimeException("Duplicate assertion definition in" + " configuration. Prefix: " + prefix
                + ", existsing title property: \"" + definitions.get(key).htmlTitle
                + ", current title property: \"" + title + "\", configuration: " + configuration);
    }

    definitions.put(key, new Value(title, description));
}

From source file:org.wso2.andes.server.store.SlowMessageStore.java

public void configureConfigStore(String name, ConfigurationRecoveryHandler recoveryHandler,
        Configuration config, LogSubject logSubject) throws Exception {
    //To change body of implemented methods use File | Settings | File Templates.

    _logger.info("Starting SlowMessageStore on Virtualhost:" + name);
    Configuration delays = config.subset(DELAYS);

    configureDelays(delays);/*from w w w  .j a v  a  2  s .  c o m*/

    String messageStoreClass = config.getString("realStore");

    if (delays.containsKey(DEFAULT_DELAY)) {
        _defaultDelay = delays.getLong(DEFAULT_DELAY);
    }

    if (messageStoreClass != null) {
        Class clazz = Class.forName(messageStoreClass);

        Object o = clazz.newInstance();

        if (!(o instanceof MessageStore)) {
            throw new ClassCastException("Message store class must implement " + MessageStore.class + ". Class "
                    + clazz + " does not.");
        }
        _realStore = (MessageStore) o;
        _realStore.configureConfigStore(name, recoveryHandler, config, logSubject);
    } else {
        _realStore.configureConfigStore(name, recoveryHandler, config, logSubject);
    }
}

From source file:pl.psnc.synat.wrdz.mdz.config.MdzConfiguration.java

/**
 * Reads the schedule definition from the given configuration subset. Handles the hour, minute, day of week, day of
 * month, and month values./*from   w w  w. j  av a2  s  .  c o  m*/
 * 
 * @param config
 *            configuration subset
 * @return configured schedule object to be used with a timer
 */
private ScheduleExpression readSchedule(Configuration config) {
    ScheduleExpression expression = new ScheduleExpression();
    if (config.containsKey(SCHEDULE_HOUR)) {
        expression.hour(config.getString(SCHEDULE_HOUR));
    }
    if (config.containsKey(SCHEDULE_MINUTE)) {
        expression.minute(config.getString(SCHEDULE_MINUTE));
    }
    if (config.containsKey(SCHEDULE_DAY_OF_WEEK)) {
        expression.dayOfWeek(config.getString(SCHEDULE_DAY_OF_WEEK));
    }
    if (config.containsKey(SCHEDULE_DAY_OF_MONTH)) {
        expression.dayOfMonth(config.getString(SCHEDULE_DAY_OF_MONTH));
    }
    if (config.containsKey(SCHEDULE_MONTH)) {
        expression.month(config.getString(SCHEDULE_MONTH));
    }
    return expression;
}

From source file:spectacular.Spectacular.java

public static SpectacularConfiguration parseConfiguration(String config) {

    File file = new File(config);
    if (!file.exists()) {
        LOGGER.fatal("Unable to find configuration file:  " + config);
        System.exit(1);/*  w  w  w . j ava2s  .  c o m*/
    }

    Configuration conf = null;
    try {
        conf = new XMLConfiguration(file);
    } catch (Exception e) {
        LOGGER.fatal("Unable to parse configuration.", e);
        System.exit(1);
    }

    SpectacularConfiguration specConfig = new SpectacularConfiguration();

    if (conf.containsKey("use-cases.base-location.path")) {
        specConfig.setUseCasesBaseLocation(conf.getString("use-cases.base-location.path", "./"));
    }

    if (conf.containsKey("use-cases.base-location.include")) {
        specConfig.setUseCasesBaseLocationIncludeFilter(
                conf.getString("use-cases.base-location.include", "*.usecase"));
    }

    if (conf.containsKey("step-actions.base-location.path")) {
        specConfig.setStepActionBaseLocation(conf.getString("step-actions.base-location.path"));
    }

    if (conf.containsKey("step-actions.base-location.include")) {
        specConfig.setStepActionBaseLocationIncludeFilter(conf.getString("step-actions.base-location.include"));
    }

    if (conf.containsKey("fixtures.base-location.path")) {
        specConfig.setFixtureCodeBaseLocation(conf.getString("fixtures.base-location.path"));
    }

    if (conf.containsKey("fixtures.base-location.include")) {
        specConfig.setFixtureCodeBaseLocationIncludeFilter(conf.getString("fixtures.base-location.include"));
    }

    if (conf.containsKey("webdriver-aware.driver")) {
        specConfig.setSeleniumAwareDriver(conf.getString("webdriver-aware.driver", "HTMLUNIT"));
    }

    return (specConfig);

}

From source file:uk.q3c.krail.core.config.InheritingConfiguration.java

/**
 * Returns the source (the configuration object) actually used to fulfil the value of {@code key}, or null if there
 * is no matching key. This is different to the {@link CompositeConfiguration#getSource(String)} behaviour.
 *
 * @param key//from   www .  j a v a 2 s  .  c om
 *
 * @return
 */
public Configuration getSourceUsed(String key) {
    Configuration firstMatchingConfiguration = null;
    int c = getNumberOfConfigurations();
    for (int i = c - 1; i >= 0; i--) {
        Configuration config = getConfiguration(i);
        if (config.containsKey(key)) {
            firstMatchingConfiguration = config;
            break;
        }
    }
    return firstMatchingConfiguration;
}