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

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

Introduction

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

Prototype

public MapConfiguration(Map map) 

Source Link

Document

Create a Configuration decorator around the specified Map.

Usage

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void graphConfigurationShouldBeWhatWeExpect() throws Exception {
    try {//from  w ww.  j av  a2s  .c om
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldCreateAndGetGraphUsingTemplateConfiguration() throws Exception {
    try {//w w  w.j a va 2s.  c  o m
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");

        assertNotNull(graph);
        assertEquals(graph, graph1);
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void graphConfigurationShouldBeWhatWeExpectWhenUsingTemplateConfiguration() throws Exception {

    try {/*from  w ww  .  j  a v a 2s  .c  o m*/
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");

        assertNotNull(graph);
        assertEquals(graph, graph1);
        assertEquals("graph1", graph.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("inmemory", graph.getConfiguration().getConfiguration().get(STORAGE_BACKEND));

    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldFailToOpenNewGraphAfterRemoveConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
    ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
    ConfiguredGraphFactory.removeConfiguration("graph1");
    thrown.expect(RuntimeException.class);
    thrown.expectMessage(equalTo("Please create configuration for this graph using the "
            + "ConfigurationManagementGraph#createConfiguration API."));
    ConfiguredGraphFactory.open("graph1");
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldFailToCreateGraphAfterRemoveTemplateConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
    ConfiguredGraphFactory.removeTemplateConfiguration();

    thrown.expect(RuntimeException.class);
    thrown.expectMessage(equalTo("Please create a template Configuration using the "
            + "ConfigurationManagementGraph#createTemplateConfiguration API."));
    ConfiguredGraphFactory.create("graph1");
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldFailToOpenGraphAfterRemoveConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
    ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
    ConfiguredGraphFactory.removeConfiguration("graph1");
    thrown.expect(RuntimeException.class);
    thrown.expectMessage(equalTo("Please create a template Configuration using the "
            + "ConfigurationManagementGraph#createTemplateConfiguration API."));
    ConfiguredGraphFactory.create("graph1");
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void updateConfigurationShouldRemoveGraphFromCache() throws Exception {
    try {//www  . j  a va2  s  .c om
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);

        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "bogusBackend");
        ConfiguredGraphFactory.updateConfiguration("graph1", new MapConfiguration(map));
        assertNull(gm.getGraph("graph1"));
        // we should throw an error since the config has been updated and we are attempting
        // to open a bogus backend
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage(equalTo("Could not find implementation class: bogusBackend"));
        final StandardJanusGraph graph2 = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void removeConfigurationShouldRemoveGraphFromCache() throws Exception {
    try {/*from  w w w  .  j  a  v a 2s. co m*/
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph = (StandardJanusGraph) ConfiguredGraphFactory.open("graph1");
        assertNotNull(graph);

        ConfiguredGraphFactory.removeConfiguration("graph1");
        assertNull(gm.getGraph("graph1"));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldBeAbleToRemoveBogusConfiguration() throws Exception {
    try {// w w w  .j  a va2 s.c o m
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "bogusBackend");
        map.put(GRAPH_NAME.toStringWithoutRoot(), "graph1");
        ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
        ConfiguredGraphFactory.removeConfiguration("graph1");
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.close("graph1");
    }
}

From source file:org.janusgraph.core.ConfiguredGraphFactoryTest.java

@Test
public void shouldCreateTwoGraphsUsingSameTemplateConfiguration() throws Exception {
    try {//w ww  .ja  v a  2s.com
        final Map<String, Object> map = new HashMap<>();
        map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
        ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
        final StandardJanusGraph graph1 = (StandardJanusGraph) ConfiguredGraphFactory.create("graph1");
        final StandardJanusGraph graph2 = (StandardJanusGraph) ConfiguredGraphFactory.create("graph2");

        assertNotNull(graph1);
        assertNotNull(graph2);

        assertEquals("graph1", graph1.getConfiguration().getConfiguration().get(GRAPH_NAME));
        assertEquals("graph2", graph2.getConfiguration().getConfiguration().get(GRAPH_NAME));
    } finally {
        ConfiguredGraphFactory.removeConfiguration("graph1");
        ConfiguredGraphFactory.removeConfiguration("graph2");
        ConfiguredGraphFactory.close("graph1");
        ConfiguredGraphFactory.close("graph2");
    }
}