Neo4jGraphConfiguration implements GraphConfiguration { public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException { final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION); if (graphFile == null || graphFile.length() == 0) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); } final boolean highAvailabilityMode = context.getProperties().getBoolean(Tokens.REXSTER_GRAPH_HA, false); final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties(); SubnodeConfiguration neo4jSpecificConfiguration; try { neo4jSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES); } catch (IllegalArgumentException iae) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES); } try { final HashMap<String, String> neo4jProperties = new HashMap<String, String>(); final Iterator<String> neo4jSpecificConfigurationKeys = neo4jSpecificConfiguration.getKeys(); while (neo4jSpecificConfigurationKeys.hasNext()) { String key = neo4jSpecificConfigurationKeys.next(); neo4jProperties.put(key.replace("..", "."), neo4jSpecificConfiguration.getString(key)); } if (highAvailabilityMode) { if (!neo4jProperties.containsKey("ha.machine_id")) { throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.machine_id] in the <properties> of the configuration"); } if (!neo4jProperties.containsKey("ha.server")) { throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.server] <properties> of the configuration"); } if (!neo4jProperties.containsKey("ha.initial_hosts")) { throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration"); } return new Neo4jHaGraph(graphFile, neo4jProperties); } else { return new Neo4jGraph(graphFile, neo4jProperties); } } catch (GraphConfigurationException gce) { throw gce; } catch (Exception ex) { throw new GraphConfigurationException(ex); } }  Graph configureGraphInstance(final GraphConfigurationContext context);  }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceNoGraphFile() throws GraphConfigurationException { Configuration graphConfig = new HierarchicalConfiguration(); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceNoNeo4jConfig() throws GraphConfigurationException { Configuration graphConfig = new HierarchicalConfiguration(); graphConfig.addProperty(Tokens.REXSTER_GRAPH_LOCATION, this.neo4jFile); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceHaOnNoProperties() throws GraphConfigurationException { Configuration graphConfig = new HierarchicalConfiguration(); graphConfig.addProperty(Tokens.REXSTER_GRAPH_LOCATION, this.neo4jFile); graphConfig.addProperty(Tokens.REXSTER_GRAPH_HA, "true"); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceHaOnNoMachineId() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.addProperty(Tokens.REXSTER_GRAPH_LOCATION, this.neo4jFile); graphConfig.addProperty(Tokens.REXSTER_GRAPH_HA, "true"); ArrayList<HierarchicalConfiguration.Node> listOfNodes = new ArrayList<HierarchicalConfiguration.Node>(); listOfNodes.add(new HierarchicalConfiguration.Node("anything", "nothing")); graphConfig.addNodes(Tokens.REXSTER_GRAPH_PROPERTIES, listOfNodes); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceHaOnNoServer() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.addProperty(Tokens.REXSTER_GRAPH_LOCATION, this.neo4jFile); graphConfig.addProperty(Tokens.REXSTER_GRAPH_HA, "true"); ArrayList<HierarchicalConfiguration.Node> listOfNodes = new ArrayList<HierarchicalConfiguration.Node>(); listOfNodes.add(new HierarchicalConfiguration.Node("ha.machine_id", "1")); graphConfig.addNodes(Tokens.REXSTER_GRAPH_PROPERTIES, listOfNodes); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceHaOnNoZkServers() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.addProperty(Tokens.REXSTER_GRAPH_LOCATION, this.neo4jFile); graphConfig.addProperty(Tokens.REXSTER_GRAPH_HA, "true"); ArrayList<HierarchicalConfiguration.Node> listOfNodes = new ArrayList<HierarchicalConfiguration.Node>(); listOfNodes.add(new HierarchicalConfiguration.Node("ha.machine_id", "1")); listOfNodes.add(new HierarchicalConfiguration.Node("ha.server", "localhost:9939")); graphConfig.addNodes(Tokens.REXSTER_GRAPH_PROPERTIES, listOfNodes); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); configuration.configureGraphInstance(context); }