Search in sources :

Example 16 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project bitflyer4j by after-the-sunrise.

the class KeyTypeTest method test.

@Test
public void test() throws ConfigurationException {
    // Null input.  (= Default value.)
    assertEquals(VERSION.fetch(null), VERSION.getDefaultValue());
    // Not found. (= Default value.)
    Configuration conf = new MapConfiguration(new HashMap<>());
    assertEquals(VERSION.fetch(conf), VERSION.getDefaultValue());
    // Retrieved from properties. (Empty)
    conf.setProperty(VERSION.getKey(), "");
    assertNull(VERSION.fetch(conf));
    // Retrieved from properties. (Configured)
    conf.setProperty(VERSION.getKey(), "test");
    assertEquals(VERSION.fetch(conf), "test");
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Configuration(org.apache.commons.configuration2.Configuration) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) Test(org.testng.annotations.Test)

Example 17 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class AbstractConfiguredGraphFactoryTest method shouldOpenGraphUsingConfiguration.

@Test
public void shouldOpenGraphUsingConfiguration() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
    } finally {
        ConfiguredGraphFactory.removeConfiguration(graphName);
        ConfiguredGraphFactory.close(graphName);
    }
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 18 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class AbstractConfiguredGraphFactoryTest method dropShouldCleanUpTraversalSourceAndBindings.

@Test
public void dropShouldCleanUpTraversalSourceAndBindings() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    final String graphNameTraversal = graphName + "_traversal";
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final JanusGraphManager jgm = JanusGraphManager.getInstance();
        final Bindings bindings = new SimpleBindings();
        jgm.configureGremlinExecutor(mockGremlinExecutor(bindings));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        jgm.putTraversalSource(ConfiguredGraphFactory.toTraversalSourceName(graphName), graph.traversal());
        assertNotNull(jgm.getGraph(graphName));
        assertEquals(ConfiguredGraphFactory.toTraversalSourceName(graphName), jgm.getTraversalSourceNames().iterator().next());
        // Confirm the graph and traversal source were added to the Gremlin Script Engine bindings
        assertTrue(bindings.containsKey(graphName));
        assertTrue(bindings.containsKey(graphNameTraversal));
        // Drop the graph and confirm that the graph and traversal source
        ConfiguredGraphFactory.drop(graphName);
        assertNull(jgm.getGraph(graphName));
        assertTrue(jgm.getTraversalSourceNames().isEmpty());
        // Confirm the graph and traversal source were removed from the Gremlin Script Engine bindings
        assertFalse(bindings.containsKey(graphName));
        assertFalse(bindings.containsKey(graphNameTraversal));
    } finally {
        ConfiguredGraphFactory.removeConfiguration(graphName);
        ConfiguredGraphFactory.close(graphName);
    }
}
Also used : SimpleBindings(javax.script.SimpleBindings) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 19 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class AbstractConfiguredGraphFactoryTest method removeConfigurationShouldRemoveGraphFromCache.

@Test
public void removeConfigurationShouldRemoveGraphFromCache() throws Exception {
    final MapConfiguration graphConfig = getGraphConfig();
    final String graphName = graphConfig.getString(GRAPH_NAME.toStringWithoutRoot());
    try {
        ConfiguredGraphFactory.createConfiguration(graphConfig);
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open(graphName);
        assertNotNull(graph);
        ConfiguredGraphFactory.removeConfiguration(graphName);
        assertNull(gm.getGraph(graphName));
    } finally {
        ConfiguredGraphFactory.removeConfiguration(graphName);
        ConfiguredGraphFactory.close(graphName);
    }
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.jupiter.api.Test)

Example 20 with MapConfiguration

use of org.apache.commons.configuration2.MapConfiguration in project janusgraph by JanusGraph.

the class AbstractConfiguredGraphFactoryTest method setup.

@BeforeEach
public void setup() {
    if (gm != null)
        return;
    gm = new JanusGraphManager(new Settings());
    final MapConfiguration config = getManagementConfig();
    final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(new CommonsConfiguration(config)));
    // Instantiate the ConfigurationManagementGraph Singleton
    new ConfigurationManagementGraph(graph);
}
Also used : GraphDatabaseConfigurationBuilder(org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) JanusGraphManager(org.janusgraph.graphdb.management.JanusGraphManager) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) Settings(org.apache.tinkerpop.gremlin.server.Settings) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) ConfigurationManagementGraph(org.janusgraph.graphdb.management.ConfigurationManagementGraph) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MapConfiguration (org.apache.commons.configuration2.MapConfiguration)34 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)25 Test (org.junit.jupiter.api.Test)25 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)16 GraphDatabaseConfigurationBuilder (org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder)16 HashMap (java.util.HashMap)6 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)3 Test (org.testng.annotations.Test)3 Configuration (org.apache.commons.configuration2.Configuration)2 Settings (org.apache.tinkerpop.gremlin.server.Settings)2 AbstractConfiguredGraphFactoryTest (org.janusgraph.core.AbstractConfiguredGraphFactoryTest)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 Session (com.datastax.driver.core.Session)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Bindings (javax.script.Bindings)1 SimpleBindings (javax.script.SimpleBindings)1 CompositeConfiguration (org.apache.commons.configuration2.CompositeConfiguration)1 JanusGraphException (org.janusgraph.core.JanusGraphException)1 PropertyKey (org.janusgraph.core.PropertyKey)1