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

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

Introduction

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

Prototype

BaseConfiguration

Source Link

Usage

From source file:org.neo4j.server.configuration.validation.DatabaseLocationMustBeSpecifiedRuleTest.java

@Test(expected = RuleFailedException.class)
public void shouldFailWhenDatabaseLocationIsAbsentFromConfig() throws RuleFailedException {
    DatabaseLocationMustBeSpecifiedRule theRule = new DatabaseLocationMustBeSpecifiedRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty("foo", "bar");
    theRule.validate(config);/* ww  w  .  j  a v a2s  .  co  m*/
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test(expected = RuleFailedException.class)
public void shouldFailIfNoWebadminConfigSpecified() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration emptyConfig = new BaseConfiguration();
    rule.validate(emptyConfig);//from  w  w w  .j  av  a2 s .  c  om
    assertFalse(theValidatorHasPassed);
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test(expected = RuleFailedException.class)
public void shouldFailIfOnlyRestApiKeySpecified() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty(Configurator.REST_API_PATH_PROPERTY_KEY, "http://localhost:7474/db/data");
    rule.validate(config);/*  w  w  w. j av  a2 s  . c o m*/
    assertFalse(theValidatorHasPassed);
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test(expected = RuleFailedException.class)
public void shouldFailIfOnlyAdminApiKeySpecified() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY, "http://localhost:7474/db/manage");
    rule.validate(config);//from  w w w.j  av a  2 s . c om
    assertFalse(theValidatorHasPassed);
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test
public void shouldAllowAbsoluteUris() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty(Configurator.REST_API_PATH_PROPERTY_KEY, "http://localhost:7474/db/data");
    config.addProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY, "http://localhost:7474/db/manage");
    rule.validate(config);/*ww w  . j a va  2 s  .  c  o  m*/
    assertTrue(theValidatorHasPassed);
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test
public void shouldAllowRelativeUris() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty(Configurator.REST_API_PATH_PROPERTY_KEY, "/db/data");
    config.addProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY, "/db/manage");
    rule.validate(config);//from w w w  .  ja v  a 2s.  c o  m
    assertTrue(theValidatorHasPassed);
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRuleTest.java

@Test
public void shouldNormaliseUris() throws RuleFailedException {
    WebadminConfigurationRule rule = new WebadminConfigurationRule();
    BaseConfiguration config = new BaseConfiguration();
    config.addProperty(Configurator.REST_API_PATH_PROPERTY_KEY, "http://localhost:7474///db///data///");
    config.addProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY, "http://localhost:7474////db///manage");
    rule.validate(config);/*from ww  w . j  a  v  a  2s. c om*/

    assertThat((String) config.getProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY),
            not(containsString("///")));
    assertFalse(((String) config.getProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY)).endsWith("//"));
    assertFalse(((String) config.getProperty(Configurator.MANAGEMENT_PATH_PROPERTY_KEY)).endsWith("/"));

    assertThat((String) config.getProperty(Configurator.REST_API_PATH_PROPERTY_KEY),
            not(containsString("///")));
    assertFalse(((String) config.getProperty(Configurator.REST_API_PATH_PROPERTY_KEY)).endsWith("//"));
    assertFalse(((String) config.getProperty(Configurator.REST_API_PATH_PROPERTY_KEY)).endsWith("/"));
}

From source file:org.openecomp.sdc.asdctool.impl.GraphMLConverter.java

public String findErrorInJsonGraph(TitanGraph graph, String outputDirectory) {

    boolean runVertexScan = false;
    boolean runEdgeScan = false;

    String result = null;//  w  w w . j  a  va2 s.c om

    // GraphMLWriter graphMLWriter = new GraphMLWriter(graph);

    String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis()
            + ".json";

    OutputStream out = null;
    try {
        out = new BufferedOutputStream(new FileOutputStream(outputFile));

        if (runEdgeScan) {

            Vertex vertexFrom = null;
            Vertex vertexTo = null;
            Edge edge = null;

            // Iterable<Edge> edges = graph.getEdges();
            // Iterable<Edge> edges = graph.query().edges();
            Iterable<TitanEdge> edges = graph.query().edges();
            // Iterator<Edge> iterator = edges.iterator();
            Iterator<TitanEdge> iterator = edges.iterator();
            while (iterator.hasNext()) {

                try {

                    edge = iterator.next();

                    // vertexFrom = edge.getVertex(Direction.OUT);
                    // vertexTo = edge.getVertex(Direction.IN);
                    vertexFrom = edge.outVertex();
                    vertexTo = edge.inVertex();

                    BaseConfiguration conf = new BaseConfiguration();
                    conf.setProperty("storage.backend", "inmemory");
                    TitanGraph openGraph = Utils.openGraph(conf);

                    TitanVertex addVertexFrom = openGraph.addVertex();
                    // ElementHelper.setProperties(addVertexFrom,
                    // ElementHelper.getProperties(vertexFrom));
                    Utils.setProperties(addVertexFrom, Utils.getProperties(vertexFrom));

                    TitanVertex addVertexTo = openGraph.addVertex();
                    // ElementHelper.setProperties(addVertexTo,
                    // ElementHelper.getProperties(vertexTo));
                    Utils.setProperties(addVertexTo, Utils.getProperties(vertexTo));

                    // Edge addEdge = openGraph.addEdge(null, addVertexFrom,
                    // addVertexTo, edge.getLabel());

                    // Edge edge = tGraph.addEdge(null,
                    // fromV.left().value(), toV.left().value(), type);

                    Edge addEdge = addVertexFrom.addEdge(edge.label(), addVertexTo);
                    // ElementHelper.setProperties(addEdge,
                    // ElementHelper.getProperties(edge));
                    Utils.setProperties(addEdge, Utils.getProperties(edge));

                    // log.info("fromVertex=" +
                    // ElementHelper.getProperties(vertexFrom));
                    log.info("fromVertex=" + Utils.getProperties(vertexFrom));
                    // log.info("toVertex=" +
                    // ElementHelper.getProperties(vertexTo));
                    log.info("toVertex=" + Utils.getProperties(vertexTo));
                    // log.info("edge=" + edge.getLabel() + " " +
                    // ElementHelper.getProperties(edge));
                    log.info("edge=" + edge.label() + " " + Utils.getProperties(edge));

                    // GraphSONWriter.outputGraph(openGraph, outputFile);
                    GraphSONWriter create = GraphSONWriter.build().create();
                    create.writeGraph(out, openGraph);

                    // openGraph.rollback();
                    openGraph.tx().rollback();

                } catch (Exception e) {
                    e.printStackTrace();

                    // log.error("fromVertex=" +
                    // ElementHelper.getProperties(vertexFrom));
                    log.error("fromVertex=" + Utils.getProperties(vertexFrom));
                    // log.error("toVertex=" +
                    // ElementHelper.getProperties(vertexTo));
                    log.error("toVertex=" + Utils.getProperties(vertexTo));
                    // log.error("edge=" + edge.getLabel() + " " +
                    // ElementHelper.getProperties(edge));
                    log.error("edge=" + edge.label() + " " + Utils.getProperties(edge));

                    break;

                }
            }

            // graph.rollback();
            graph.tx().rollback();

        }

        if (runVertexScan) {

            Vertex vertex = null;
            // Iterable<Vertex> vertices = graph.getVertices();

            // Iterator<Vertex> iteratorVertex = vertices.iterator();
            Iterator<Vertex> iteratorVertex = graph.vertices();
            while (iteratorVertex.hasNext()) {

                try {

                    vertex = iteratorVertex.next();

                    // Iterable<Edge> edges2 =
                    // vertex.getEdges(Direction.BOTH);

                    // Iterator<Edge> iterator2 = edges2.iterator();
                    Iterator<Edge> iterator2 = vertex.edges(Direction.BOTH);
                    if (false == iterator2.hasNext()) {

                        BaseConfiguration conf = new BaseConfiguration();
                        conf.setProperty("storage.backend", "inmemory");
                        TitanGraph openGraph = Utils.openGraph(conf);

                        TitanVertex addVertexFrom = openGraph.addVertex();
                        // ElementHelper.setProperties(addVertexFrom,
                        // ElementHelper.getProperties(vertex));
                        Utils.setProperties(addVertexFrom, Utils.getProperties(vertex));

                        // log.info("fromVertex=" +
                        // ElementHelper.getProperties(addVertexFrom));
                        log.info("fromVertex=" + Utils.getProperties(addVertexFrom));

                        // GraphSONWriter.outputGraph(openGraph,
                        // outputFile);
                        GraphSONWriter create = GraphSONWriter.build().create();
                        create.writeGraph(out, openGraph);

                        // openGraph.rollback();
                        openGraph.tx().rollback();

                    }

                } catch (Exception e) {
                    e.printStackTrace();

                    // log.error("vertex=" +
                    // ElementHelper.getProperties(vertex));

                    GraphPropertiesDictionary[] values = GraphPropertiesDictionary.values();

                    // Object property1 =
                    // vertex.getProperty(GraphPropertiesDictionary.HEALTH_CHECK.getProperty());
                    Object property1 = vertex.value(GraphPropertiesDictionary.HEALTH_CHECK.getProperty());
                    System.out.println(property1);

                    // Object property2 = vertex.getProperty("healthcheck");
                    Object property2 = vertex.value("healthcheck");
                    System.out.println(property2);

                    // for (GraphPropertiesDictionary value : values) {
                    //
                    // System.out.println(property);
                    // }

                    break;

                }
            }

            // graph.rollback();
            graph.tx().rollback();

        }

        // Iterable<Vertex> vertices2 =
        // graph.getVertices(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(),
        // "GOOD");
        Iterable<TitanVertex> vertices2 = graph.query()
                .has(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(), "GOOD").vertices();
        ;
        Vertex next = vertices2.iterator().next();

        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "inmemory");
        TitanGraph openGraph = Utils.openGraph(conf);

        // TitanVertex addVertexFrom = openGraph.addVertex();
        //
        // addVertexFrom.setProperty(GraphPropertiesDictionary.HEALTH_CHECK.getProperty(),
        // "GOOD");
        // addVertexFrom.setProperty("healthcheck",
        // next.getProperty("healthcheck"));
        //
        // //next.remove();
        //
        // next.removeProperty("healthcheck");
        // next.removeProperty("healthcheckis");
        //
        // next.remove();

        // GraphSONWriter.outputGraph(openGraph, outputFile);

        for (NodeTypeEnum nodeTypeEnum : NodeTypeEnum.values()) {
            removeNodesByLabel(graph, nodeTypeEnum.getName());
        }

        // GraphSONWriter.outputGraph(graph, outputFile);

        GraphSONWriter create = GraphSONWriter.build().create();
        create.writeGraph(out, graph);

        // graph.rollback();
        graph.tx().rollback();

    } catch (Exception e) {
        e.printStackTrace();
        // graph.rollback();
        graph.tx().rollback();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return result;

}

From source file:org.openecomp.sdc.be.dao.titan.TitanGraphClient.java

@PostConstruct
public TitanOperationStatus createGraph() {

    logger.info("** createGraph started **");

    if (ConfigurationManager.getConfigurationManager().getConfiguration().getTitanInMemoryGraph()) {
        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "inmemory");
        graph = TitanFactory.open(conf);

        createIndexesAndDefaults();/*from www .  j  av a 2  s  .c  o m*/

        logger.info("** in memory graph created");
        return TitanOperationStatus.OK;
    } else {
        this.titanCfgFile = ConfigurationManager.getConfigurationManager().getConfiguration().getTitanCfgFile();
        if (titanCfgFile == null || titanCfgFile.isEmpty()) {
            titanCfgFile = "config/titan.properties";
        }

        // yavivi
        // In case connection failed on init time, schedule a reconnect task
        // in the BG
        TitanOperationStatus status = createGraph(titanCfgFile);
        logger.debug("Create Titan graph status {}", status);
        if (status != TitanOperationStatus.OK) {
            this.startReconnectTask();
        }

        return status;
    }
}

From source file:org.openecomp.sdc.be.resources.TitanGenericDaoTest.java

public void testStringSearch() {
    TitanGraph graph;//from ww  w . jav  a 2s. co  m

    BaseConfiguration conf = new BaseConfiguration();
    conf.setProperty("storage.backend", "inmemory");
    graph = TitanFactory.open(conf);

    // TitanManagement graphMgt = graph.getManagementSystem();
    TitanManagement graphMgt = graph.openManagement();
    PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make();
    graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex();

    propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make();

    // graphMgt.buildIndex("string2", Vertex.class).addKey(propKey,
    // Mapping.TEXT.getParameter()).buildMixedIndex("search");
    graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
    graphMgt.commit();

    // TitanVertex v = graph.addVertex();
    // v.addProperty("string1", "My new String 1");
    // v.addProperty("string2", "String11");
    // graph.commit();
    //
    // v = graph.addVertex();
    // v.addProperty("string1", "my new string 1");
    // v.addProperty("string2", "string11");
    // graph.commit();
    //
    // System.out.println("First index search - case");
    //
    // Iterable<Vertex> vertices = graph.getVertices("string1", "My new
    // String 1");
    // Iterator<Vertex> iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("First index search non case");
    //
    // vertices = graph.getVertices("string1", "my new string 1");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Second index search case");
    //
    // vertices = graph.getVertices("string2", "String11");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("second index search non case");
    //
    // vertices = graph.getVertices("string2", "string11");
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Query index search case");
    // vertices = graph.query().has("string1", "My new String
    // 1").vertices();
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }
    // System.out.println("Query index search non case");
    // vertices = graph.query().has("string1", "my new string
    // 1").vertices();
    // iter = vertices.iterator();
    // while ( iter.hasNext() ){
    // Vertex ver = iter.next();
    // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
    // }

    log.debug("**** predicat index search non case");
    Iterable<TitanVertex> vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices();
    Iterator<TitanVertex> iter = vertices.iterator();
    while (iter.hasNext()) {
        Vertex ver = iter.next();
        // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
        log.debug("{}", titanDao.getProperties(ver));
    }

}