AbstractSailGraphConfiguration implements GraphConfiguration { public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException { final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION, null); final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties(); SubnodeConfiguration sailSpecificConfiguration = null; try { sailSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES); } catch (IllegalArgumentException iae) { } if ((sailType.equals(SAIL_TYPE_NATIVE) || sailType.equals(SAIL_TYPE_SPARQL) || sailType.equals(SAIL_TYPE_LINKED_DATA)) && (graphFile == null || graphFile.trim().length() == 0)) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); } try { SailGraph graph = null; if (this.sailType.equals(SAIL_TYPE_MEMORY)) { if (graphFile != null && !graphFile.isEmpty()) { logger.warn("[" + MemoryStoreSailGraph.class.getSimpleName() + "] doesn't support the graph-file parameter. It will be ignored."); } graph = new MemoryStoreSailGraph(); } else if (this.sailType.equals(SAIL_TYPE_LINKED_DATA)) { RexsterApplicationGraph baseGraph = context.getGraphs().get(graphFile); if (null == baseGraph) { throw new GraphConfigurationException("no such base graph for LinkedDataSail graph: " + graphFile); } if (!(baseGraph.getGraph() instanceof SailGraph)) { throw new GraphConfigurationException("base graph for LinkedDataSail graph must be an instance of SailGraph"); } if (baseGraph.getGraph() instanceof LinkedDataSailGraph) { throw new GraphConfigurationException("LinkedDataSail graph based on another LinkedDataSail graph"); } graph = new LinkedDataSailGraph((SailGraph) baseGraph.getGraph()); } else if (this.sailType.equals(SAIL_TYPE_NATIVE)) { String configTripleIndices = ""; if (sailSpecificConfiguration != null) { configTripleIndices = sailSpecificConfiguration.getString("triple-indices", ""); } if (configTripleIndices != null && configTripleIndices.trim().length() > 0) { graph = new NativeStoreSailGraph(graphFile, configTripleIndices); } else { graph = new NativeStoreSailGraph(graphFile); } } else if (this.sailType.equals(SAIL_TYPE_SPARQL)) { graph = new SparqlRepositorySailGraph(graphFile); } return graph; } catch (Exception ex) { throw new GraphConfigurationException(ex); } }  Graph configureGraphInstance(final GraphConfigurationContext context); static final String SAIL_TYPE_MEMORY; static final String SAIL_TYPE_LINKED_DATA; static final String SAIL_TYPE_NATIVE; static final String SAIL_TYPE_SPARQL; }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceNativeSailTypeNoGraphFile() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_NATIVE); this.configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceNativeSailTypeEmptyGraphFile() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_NATIVE); this.configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceSparqlRepoSailTypeNoGraphFile() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_SPARQL); this.configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceSparqlRepoSailTypeEmptyGraphFile() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_SPARQL); this.configuration.configureGraphInstance(context); }
@Test public void configureGraphInstanceMemorySailTypeEmptyGraphFile() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_MEMORY); Graph graph = this.configuration.configureGraphInstance(context); Assert.assertNotNull(graph); Assert.assertTrue(graph instanceof MemoryStoreSailGraph); }
@Test public void configureGraphInstanceMemorySailTypeNoGraphFileProperty() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_MEMORY); Graph graph = this.configuration.configureGraphInstance(context); Assert.assertNotNull(graph); Assert.assertTrue(graph instanceof MemoryStoreSailGraph); }
@Test public void configureGraphInstanceLinkedDataSailType() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_MEMORY); Graph graph = this.configuration.configureGraphInstance(context); graphs.put("ldbase", new RexsterApplicationGraph("ldbase", graph)); graphConfig = new HierarchicalConfiguration(); context = new GraphConfigurationContext(graphConfig, graphs); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, "ldbase"); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_LINKED_DATA); this.configuration.configureGraphInstance(context); graph = this.configuration.configureGraphInstance(context); assertTrue(graph instanceof LinkedDataSailGraph); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceLinkedDataSailTypeNoBaseGraph() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, ""); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_LINKED_DATA); this.configuration.configureGraphInstance(context); }
@Test(expected = GraphConfigurationException.class) public void configureGraphInstanceLinkedDataSailTypeBaseGraphDoesNotExist() throws GraphConfigurationException { HierarchicalConfiguration graphConfig = new HierarchicalConfiguration(); graphConfig.setProperty(Tokens.REXSTER_GRAPH_LOCATION, "thisbasegraphdoesnotexist"); Map<String, RexsterApplicationGraph> graphs = new HashMap<String, RexsterApplicationGraph>(); GraphConfigurationContext context = new GraphConfigurationContext(graphConfig, graphs); this.configuration.setSailType(AbstractSailGraphConfiguration.SAIL_TYPE_LINKED_DATA); this.configuration.configureGraphInstance(context); }