qdef.setDefaultGraphUris(graphName); InputStreamHandle results = client.executeSelect(qdef, new InputStreamHandle());
@Test public void testDefaultURI() { // verify default graph String defGraphQuery = "SELECT ?s WHERE { ?s a ?o }"; SPARQLQueryDefinition qdef = smgr.newQueryDefinition(defGraphQuery); qdef.setIncludeDefaultRulesets(false); qdef.setOptimizeLevel(1); // this only tests whether optimize level is set, not sent to server // I'm not sure how to test that assertEquals(1, qdef.getOptimizeLevel()); ArrayNode bindings = executeAndExtractBindings(qdef); qdef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g4"); bindings = executeAndExtractBindings(qdef); assertEquals("Single graphs has one assertion", 1, bindings.size()); qdef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g4", "http://marklogic.com/SPARQLQDefTest/g2"); bindings = executeAndExtractBindings(qdef); assertEquals("Union two default graphs has two assertions", 2, bindings.size()); }
@Test public void testUsingNamedURI() { // verify default graph String defGraphQuery = "INSERT { GRAPH <http://marklogic.com/SPARQLQDefTest/g65> " + "{ <http://marklogic.com/SPARQLQDefTest/r3> " + "<http://marklogic.com/SPARQLQDefTest/p3> " + "<http://marklogic.com/SPARQLQDefTest/o3> } } " + "WHERE { GRAPH ?g { <http://marklogic.com/SPARQLQDefTest/r1> <http://marklogic.com/SPARQLQDefTest/p3> ?o } }"; String checkQuery = "ASK WHERE { <http://marklogic.com/SPARQLQDefTest/r3> <http://marklogic.com/SPARQLQDefTest/p3> <http://marklogic.com/SPARQLQDefTest/o3> }"; SPARQLQueryDefinition qdef = smgr.newQueryDefinition(defGraphQuery); // negative, no insert qdef.setUsingNamedGraphUris("http://marklogic.com/SPARQLQDefTest/baloney"); smgr.executeUpdate(qdef); SPARQLQueryDefinition checkDef = smgr.newQueryDefinition(checkQuery); checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g65"); assertFalse(smgr.executeAsk(checkDef)); // positive qdef.setUsingNamedGraphUris("http://marklogic.com/SPARQLQDefTest/g1"); smgr.executeUpdate(qdef); checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g65"); assertTrue(smgr.executeAsk(checkDef)); }
@Test public void testUsingURI() { // verify default graph String defGraphQuery = "INSERT { GRAPH <http://marklogic.com/SPARQLQDefTest/g3> " + "{ <http://marklogic.com/SPARQLQDefTest/r3> " + "<http://marklogic.com/SPARQLQDefTest/p3> " + "<http://marklogic.com/SPARQLQDefTest/o3> } } " + "WHERE { <http://marklogic.com/SPARQLQDefTest/r1> <http://marklogic.com/SPARQLQDefTest/p3> ?o }"; String defCheckQuery = "ASK WHERE { <http://marklogic.com/SPARQLQDefTest/r3> <http://marklogic.com/SPARQLQDefTest/p3> <http://marklogic.com/SPARQLQDefTest/o3> }"; SPARQLQueryDefinition qdef = smgr.newQueryDefinition(defGraphQuery); qdef.setUsingGraphUris("http://marklogic.com/SPARQLQDefTest/g1"); smgr.executeUpdate(qdef); SPARQLQueryDefinition checkDef = smgr.newQueryDefinition(defCheckQuery); checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g3"); assertTrue(smgr.executeAsk(checkDef)); // clean up smgr.executeUpdate(smgr.newQueryDefinition("DROP GRAPH <http://marklogic.com/SPARQLQDefTest/g3>")); assertFalse(smgr.executeAsk(checkDef)); }