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

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

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Usage

From source file:fr.inria.atlanmod.neoemf.data.blueprints.neo4j.option.BlueprintsNeo4jResourceSaveTest.java

private void assertConfigurationHasEntry(PropertiesConfiguration configuration, String key, String value) {
    assertThat(configuration.containsKey(key)).isTrue();
    assertThat(configuration.getString(key)).isEqualTo(value);
}

From source file:fr.inria.atlanmod.neoemf.data.blueprints.BlueprintsPersistenceBackendFactory.java

private PropertiesConfiguration getOrCreateBlueprintsConfiguration(File directory, Map<?, ?> options)
        throws InvalidDataStoreException {
    PropertiesConfiguration configuration;

    // Try to load previous configurations
    Path path = Paths.get(directory.getAbsolutePath()).resolve(BLUEPRINTS_CONFIG_FILE);
    try {//from w ww . ja v a  2  s  .  c  om
        configuration = new PropertiesConfiguration(path.toFile());
    } catch (ConfigurationException e) {
        throw new InvalidDataStoreException(e);
    }

    // Initialize value if the config file has just been created
    if (!configuration.containsKey(BlueprintsResourceOptions.GRAPH_TYPE)) {
        configuration.setProperty(BlueprintsResourceOptions.GRAPH_TYPE,
                BlueprintsResourceOptions.GRAPH_TYPE_DEFAULT);
    } else if (options.containsKey(BlueprintsResourceOptions.GRAPH_TYPE)) {
        // The file already existed, check that the issued options are not conflictive
        String savedGraphType = configuration.getString(BlueprintsResourceOptions.GRAPH_TYPE);
        String issuedGraphType = options.get(BlueprintsResourceOptions.GRAPH_TYPE).toString();
        if (!Objects.equals(savedGraphType, issuedGraphType)) {
            NeoLogger.error("Unable to create graph as type {0}, expected graph type was {1})", issuedGraphType,
                    savedGraphType);
            throw new InvalidDataStoreException("Unable to create graph as type " + issuedGraphType
                    + ", expected graph type was " + savedGraphType + ')');
        }
    }

    // Copy the options to the configuration
    for (Entry<?, ?> e : options.entrySet()) {
        configuration.setProperty(e.getKey().toString(), e.getValue().toString());
    }

    // Check we have a valid graph type, it is needed to get the graph name
    String graphType = configuration.getString(BlueprintsResourceOptions.GRAPH_TYPE);
    if (isNull(graphType)) {
        throw new InvalidDataStoreException("Graph type is undefined for " + directory.getAbsolutePath());
    }

    // Define the configuration
    String[] segments = graphType.split("\\.");
    if (segments.length >= 2) {
        String graphName = segments[segments.length - 2];
        String upperCaseGraphName = Character.toUpperCase(graphName.charAt(0)) + graphName.substring(1);
        String configClassName = MessageFormat.format("InternalBlueprints{0}Configuration", upperCaseGraphName);
        String configClassQualifiedName = MessageFormat
                .format("fr.inria.atlanmod.neoemf.data.blueprints.{0}.config.{1}", graphName, configClassName);

        try {
            ClassLoader classLoader = BlueprintsPersistenceBackendFactory.class.getClassLoader();
            Class<?> configClass = classLoader.loadClass(configClassQualifiedName);
            Method configClassInstanceMethod = configClass.getMethod("getInstance");
            InternalBlueprintsConfiguration blueprintsConfig = (InternalBlueprintsConfiguration) configClassInstanceMethod
                    .invoke(configClass);
            blueprintsConfig.putDefaultConfiguration(configuration, directory);
        } catch (ClassNotFoundException e) {
            NeoLogger.warn(e, "Unable to find the configuration class {0}", configClassQualifiedName);
        } catch (NoSuchMethodException e) {
            NeoLogger.warn(e, "Unable to find configuration methods in class {0}", configClassName);
        } catch (InvocationTargetException | IllegalAccessException e) {
            NeoLogger.warn(e, "An error occurs during the execution of a configuration method");
        }
    } else {
        NeoLogger.warn("Unable to compute graph type name from {0}", graphType);
    }

    return configuration;
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

@SuppressWarnings("unchecked")
@Test//w  w  w. j  ava  2s  .  c o  m
public void testSaveGraphNeo4jResourceNoneCacheTypeOption() throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE,
            BlueprintsNeo4jResourceOptions.CACHE_TYPE.NONE);
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE)
            .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.NONE.toString());
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the cache_type properties in the configuration file.
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 *//*from ww w  . j  a  v  a2  s  .c  o  m*/
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourceWeakCacheTypeOption() throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE,
            BlueprintsNeo4jResourceOptions.CACHE_TYPE.WEAK);
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE)
            .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.WEAK.toString());
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the cache_type properties in the configuration file.
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 *//*from   ww w  .  j a  v a 2  s  . c o  m*/
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourceSoftCacheTypeOption() throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE,
            BlueprintsNeo4jResourceOptions.CACHE_TYPE.SOFT);
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE)
            .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.SOFT.toString());
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the cache_type properties in the configuration file.
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 *///from  w  w  w. j a  v a 2s.  c o m
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourceStrongCacheTypeOption() throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE,
            BlueprintsNeo4jResourceOptions.CACHE_TYPE.STRONG);
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE)
            .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.STRONG.toString());
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the nodes_mapped_memory properties in the configuration file (with
 * a value set to 0M).//from  www.j ava 2  s  . c om
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 */
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourceNullNodesMappedMemoryOption() throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY, "0M");
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration
            .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY)
            .equals("0M");
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the arrays_mapped_memory properties in the configuration file (with
 * a positive value).//from  w w w  .j av  a  2 s.  c o m
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 */
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourcePositiveArraysMappedMemoryOption()
        throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY, "64M");
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration
            .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY)
            .equals("64M");
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the arrays_mapped_memory properties in the configuration file (with
 * a value set to 0M)./* ww  w .j  a  va2 s.  com*/
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 */
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourceNullArraysMappedMemoryOption()
        throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY, "0M");
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration
            .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_ARRAYS_MAPPED_MEMORY)
            .equals("0M");
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

/**
 * Test the existence of the nodes_mapped_memory properties in the configuration file (with
 * a positive value).//from  w w  w  .  j a v  a  2s.  c  o m
 * This test use the option @see{BlueprintsNeo4jResourceOptions.OPTIONS_GRAPH_TYPE_NEO4J}
 * but does not test it (it is done in @see{testSaveGraphNeo4jResourceNeo4jTypeOption()})
 * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in
 * @see{testSaveGraphNeo4jResourceNeo4jTypeOption()}
 */
@SuppressWarnings("unchecked")
@Test
public void testSaveGraphNeo4jResourcePositiveNodesMappedMemoryOption()
        throws IOException, ConfigurationException {
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY, "64M");
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration
            .containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_NODES_MAPPED_MEMORY)
            .equals("64M");
    assert getKeyCount(configuration) == defaultPropertyCount
            + 1 : "The number of properties in the configuration file is not consistent with the given options";
}