IdGraphConfiguration implements GraphConfiguration { public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException { final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION, null); if (graphFile == null || graphFile.trim().length() == 0) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); } RexsterApplicationGraph baseGraph = context.getGraphs().get(graphFile); if (null == baseGraph) { throw new GraphConfigurationException("no such base graph for IdGraph: " + graphFile); } if (!(baseGraph.getGraph() instanceof KeyIndexableGraph)) { throw new GraphConfigurationException("base graph for IdGraph must be an instance of KeyIndexableGraph"); } final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties(); SubnodeConfiguration specificConfiguration; try { specificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES); } catch (IllegalArgumentException iae) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES); } boolean supportVertexIds = specificConfiguration.getBoolean("supportVertexIds", true); boolean supportEdgeIds = specificConfiguration.getBoolean("supportEdgeIds", true); return new IdGraph((KeyIndexableGraph) baseGraph.getGraph(), supportVertexIds, supportEdgeIds); }  Graph configureGraphInstance(final GraphConfigurationContext context);  }
@Test public void configureIdGraphOnTinkerGraph() throws Exception { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); TinkerGraphGraphConfiguration conf = new TinkerGraphGraphConfiguration(); Graph baseGraph = conf.configureGraphInstance(context); graphs.put("idbase", new RexsterApplicationGraph("idbase", baseGraph)); graphConfig = new HierarchicalConfiguration(); context = new GraphConfigurationContext(graphConfig, graphs); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, "idbase"); ArrayList<HierarchicalConfiguration.Node> listOfNodes = new ArrayList<HierarchicalConfiguration.Node>(); listOfNodes.add(new HierarchicalConfiguration.Node("supportEdgeIds", "false")); graphConfig.addNodes(Tokens.REXSTER_GRAPH_PROPERTIES, listOfNodes); this.configuration.configureGraphInstance(context); Graph graph = this.configuration.configureGraphInstance(context); assertTrue(graph instanceof IdGraph); assertTrue(((IdGraph) graph).getSupportVertexIds()); assertFalse(((IdGraph) graph).getSupportEdgeIds()); }
@Test(expected = GraphConfigurationException.class) public void configureIdGraphNoBaseGraph() throws Exception { Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureIdGraphBaseGraphNotFound() throws Exception { Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, "idbase"); this.configuration.configureGraphInstance(context); }