SindicePreProcessing implements PreProcessing { @Override public String process(String query) throws Exception { final ASTQueryContainer ast = SyntaxTreeBuilder.parseQuery(query); if (ast.getQuery().getDatasetClauseList().size() != 0) { throw new IllegalArgumentException("FROM and FROM NAMED clauses are not allowed. Use GRAPH instead."); } ASTVarGenerator.reset(); final AddDatasetStatement addDSst = new AddDatasetStatement(); addDSst.visit(ast, null); return AST2TextTranslator.translate(ast); }  @Override void init(String... args); @Override String getVarPrefix(); @Override String getVarSuffix(); @Override String process(String query); final static ASTIRI isPartOf; }
@Test(expected = Exception.class) public void testQueryWithFROM() throws Exception { String query = "SELECT * FROM <http: pre.process(query); }
@Test public void testQueryNoGraphs() throws Exception { String query = "SELECT * { ?s ?p ?o }"; String processed = pre.process(query); assertEquals("SELECT *\nWHERE {\n ?s ?p ?o .\n}\n", processed); }
@Test public void testPropertyListPath() throws Exception { String query = "SELECT * { ?s ?p ?o , ?o2, <toto> ;?b ?c;<name> ?e }"; String processed = pre.process(query); assertEquals( "SELECT *\nWHERE {\n ?s ?p ?o ,?o2 ,<toto> ;?b ?c ;<name> ?e .\n}\n", processed); }
@Test public void testBlankNodePropertyList() throws Exception { String query = "SELECT * { ?s ?p [ ?p ?type1 , ?type2 ; <name> \"titi\" ] }"; String processed = pre.process(query); assertEquals( "SELECT *\nWHERE {\n ?s ?p [?p ?type1 ,?type2 ;<name> \"titi\" ].\n}\n", processed); }
@Test public void testQueryWithGraphs() throws Exception { String query1 = "SELECT * { GRAPH <http: String processed = pre.process(query1); final String[] vars = filter(ASTVarGenerator.getCurrentVarNames(), "a", "b", "c", "s", "p", "o"); assertEquals(1, vars.length); assertEquals("SELECT *\nWHERE {\nGRAPH ?" + vars[0] + " {\n ?a ?b ?c .\n}\n ?s ?p ?o .\n ?" + vars[0] + " <" + SindicePreProcessing.isPartOf.getValue() + "> <http: }
@Test public void testQueryWithGraphs2() throws Exception { String query1 = "SELECT * { GRAPH <http: String processed = pre.process(query1); final String[] vars = filter(ASTVarGenerator.getCurrentVarNames(), "a", "b", "c", "s", "p", "o"); assertEquals(2, vars.length); assertEquals("SELECT *\nWHERE {\nGRAPH ?" + vars[0] + " {\n ?a ?b ?c .\n}\n" + "GRAPH ?" + vars[1] + " {\n ?s ?p ?o .\n}\n" + " ?" + vars[0] + " <" + SindicePreProcessing.isPartOf.getValue() + "> <http: + SindicePreProcessing.isPartOf.getValue() + "> ?g .\n}\n", processed); }