Skip to content

Commit c0cb34e

Browse files
committed
make graph uris unique to this class to avoid interactions with data already in the db
(cherry picked from commit c384e65)
1 parent 4dcbd48 commit c0cb34e

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

src/test/java/com/marklogic/client/test/SPARQLQueryDefinitionTest.java

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SPARQLQueryDefinitionTest {
3030

3131
private static String TEST_TRIG = "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . "
3232
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . "
33-
+ "@prefix : <http://example.org/> . "
33+
+ "@prefix : <http://marklogic.com/SPARQLQDefTest/> . "
3434
+ "{ :r1 a :c1 ; "
3535
+ " :p1 \"string value 0\" ; "
3636
+ " :p2 \"string value 1\" . "
@@ -87,7 +87,7 @@ public static void beforeClass() {
8787
Common.connect();
8888
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
8989
gmgr = Common.client.newGraphManager();
90-
gmgr.replaceGraphs(new StringHandle(TEST_TRIG)
90+
gmgr.mergeGraphs(new StringHandle(TEST_TRIG)
9191
.withMimetype("text/trig"));
9292
smgr = Common.client.newSPARQLQueryManager();
9393
}
@@ -96,7 +96,15 @@ public static void beforeClass() {
9696
public static void afterClass() {
9797
Common.connect();
9898
gmgr = Common.client.newGraphManager();
99-
gmgr.deleteGraphs();
99+
gmgr.delete(GraphManager.DEFAULT_GRAPH);
100+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/g1");
101+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/g2");
102+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/g4");
103+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/g65");
104+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/o1");
105+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/o2");
106+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/o3");
107+
gmgr.delete("http://marklogic.com/SPARQLQDefTest/o4");
100108
}
101109

102110
private ArrayNode executeAndExtractBindings(SPARQLQueryDefinition qdef) {
@@ -110,8 +118,8 @@ private ArrayNode executeAndExtractBindings(SPARQLQueryDefinition qdef) {
110118

111119
@Test
112120
public void testBindings() {
113-
String ask = "ASK FROM <http://example.org/g1> " +
114-
"WHERE { <http://example.org/r1> <http://example.org/p3> ?o }";
121+
String ask = "ASK FROM <http://marklogic.com/SPARQLQDefTest/g1> " +
122+
"WHERE { <http://marklogic.com/SPARQLQDefTest/r1> <http://marklogic.com/SPARQLQDefTest/p3> ?o }";
115123
SPARQLQueryDefinition askQuery = smgr.newQueryDefinition(ask);
116124

117125
SPARQLBindings bindings = askQuery.getBindings();
@@ -387,21 +395,21 @@ public void testBaseUri() {
387395
String relativeConstruct = "CONSTRUCT { <relative1> <relative2> <relative3> } \n" +
388396
"WHERE { ?s ?p ?o . } LIMIT 1";
389397
SPARQLQueryDefinition qdef = smgr.newQueryDefinition(relativeConstruct);
390-
qdef.setBaseUri("http://example.org/test/");
398+
qdef.setBaseUri("http://marklogic.com/SPARQLQDefTest/");
391399
JsonNode rdf = smgr.executeConstruct(qdef, new JacksonHandle()).get();
392400

393401
String subject = rdf.fieldNames().next();
394402
assertEquals("base uri plus relative subject uri",
395-
"http://example.org/test/relative1", subject);
403+
"http://marklogic.com/SPARQLQDefTest/relative1", subject);
396404

397405
String predicate = rdf.get(subject).fieldNames().next();
398406
assertEquals("base uri plus relative predicate uri",
399-
"http://example.org/test/relative2", predicate);
407+
"http://marklogic.com/SPARQLQDefTest/relative2", predicate);
400408

401409
JsonNode objects = rdf.get(subject).get(predicate);
402410
assertEquals(1, objects.size());
403411
assertEquals("base uri plus relative uri",
404-
"http://example.org/test/relative3", objects.path(0).path("value").asText());
412+
"http://marklogic.com/SPARQLQDefTest/relative3", objects.path(0).path("value").asText());
405413
}
406414

407415
@Test
@@ -418,12 +426,12 @@ public void testDefaultURI() {
418426
assertEquals("Union of all graphs has three class assertions", 3,
419427
bindings.size());
420428

421-
qdef.setDefaultGraphUris("http://example.org/g4");
429+
qdef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g4");
422430
bindings = executeAndExtractBindings(qdef);
423431
assertEquals("Single graphs has one assertion", 1, bindings.size());
424432

425-
qdef.setDefaultGraphUris("http://example.org/g4",
426-
"http://example.org/g2");
433+
qdef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g4",
434+
"http://marklogic.com/SPARQLQDefTest/g2");
427435
bindings = executeAndExtractBindings(qdef);
428436
assertEquals("Union two default graphs has two assertions", 2,
429437
bindings.size());
@@ -434,56 +442,66 @@ public void testNamedGraphUris() {
434442
SPARQLQueryDefinition qdef = smgr
435443
.newQueryDefinition("SELECT ?s where { GRAPH ?g { ?s a ?o } }");
436444
qdef.setIncludeDefaultRulesets(false);
437-
qdef.setNamedGraphUris("http://example.org/g3");
445+
qdef.setNamedGraphUris("http://marklogic.com/SPARQLQDefTest/g3");
438446
ArrayNode bindings = executeAndExtractBindings(qdef);
439447
assertEquals("From named 0 result assertions", 0, bindings.size());
440448

441-
qdef.setNamedGraphUris("http://example.org/g4");
449+
qdef.setNamedGraphUris("http://marklogic.com/SPARQLQDefTest/g4");
442450
bindings = executeAndExtractBindings(qdef);
443451
assertEquals("From named 1 result assertions", 1, bindings.size());
444452

445-
qdef.setNamedGraphUris("http://example.org/g4", "http://example.org/g2");
453+
qdef.setNamedGraphUris("http://marklogic.com/SPARQLQDefTest/g4", "http://marklogic.com/SPARQLQDefTest/g2");
446454
bindings = executeAndExtractBindings(qdef);
447455
assertEquals("From named 1 result assertions", 2, bindings.size());
448456
}
449457

450458
@Test
451459
public void testUsingURI() {
452460
// verify default graph
453-
String defGraphQuery = "INSERT { GRAPH <http://example.org/g3> { <http://example.org/r3> <http://example.org/p3> <http://example.org/o3> } } WHERE { <http://example.org/r1> <http://example.org/p3> ?o }";
454-
String defCheckQuery = "ASK WHERE { <http://example.org/r3> <http://example.org/p3> <http://example.org/o3> }";
461+
String defGraphQuery = "INSERT { GRAPH <http://marklogic.com/SPARQLQDefTest/g3> " +
462+
"{ <http://marklogic.com/SPARQLQDefTest/r3> " +
463+
"<http://marklogic.com/SPARQLQDefTest/p3> " +
464+
"<http://marklogic.com/SPARQLQDefTest/o3> } } " +
465+
"WHERE { <http://marklogic.com/SPARQLQDefTest/r1> <http://marklogic.com/SPARQLQDefTest/p3> ?o }";
466+
String defCheckQuery =
467+
"ASK WHERE { <http://marklogic.com/SPARQLQDefTest/r3> <http://marklogic.com/SPARQLQDefTest/p3> <http://marklogic.com/SPARQLQDefTest/o3> }";
455468
SPARQLQueryDefinition qdef = smgr.newQueryDefinition(defGraphQuery);
456-
qdef.setUsingGraphUris("http://example.org/g1");
469+
qdef.setUsingGraphUris("http://marklogic.com/SPARQLQDefTest/g1");
457470
smgr.executeUpdate(qdef);
458471
SPARQLQueryDefinition checkDef = smgr.newQueryDefinition(defCheckQuery);
459-
checkDef.setDefaultGraphUris("http://example.org/g3");
472+
checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g3");
460473
assertTrue(smgr.executeAsk(checkDef));
461474

462475
// clean up
463-
smgr.executeUpdate(smgr.newQueryDefinition("DROP GRAPH <http://example.org/g3>"));
476+
smgr.executeUpdate(smgr.newQueryDefinition("DROP GRAPH <http://marklogic.com/SPARQLQDefTest/g3>"));
464477
assertFalse(smgr.executeAsk(checkDef));
465478
}
466479

467480
@Test
468481
public void testUsingNamedURI() {
469482
// verify default graph
470-
String defGraphQuery = "INSERT { GRAPH <http://example.org/g65> { <http://example.org/r3> <http://example.org/p3> <http://example.org/o3> } } WHERE { GRAPH ?g { <http://example.org/r1> <http://example.org/p3> ?o } }";
471-
String checkQuery = "ASK WHERE { <http://example.org/r3> <http://example.org/p3> <http://example.org/o3> }";
483+
String defGraphQuery = "INSERT { GRAPH <http://marklogic.com/SPARQLQDefTest/g65> " +
484+
"{ <http://marklogic.com/SPARQLQDefTest/r3> " +
485+
"<http://marklogic.com/SPARQLQDefTest/p3> " +
486+
"<http://marklogic.com/SPARQLQDefTest/o3> } } " +
487+
"WHERE { GRAPH ?g { <http://marklogic.com/SPARQLQDefTest/r1> <http://marklogic.com/SPARQLQDefTest/p3> ?o } }";
488+
String checkQuery =
489+
"ASK WHERE { <http://marklogic.com/SPARQLQDefTest/r3> <http://marklogic.com/SPARQLQDefTest/p3> <http://marklogic.com/SPARQLQDefTest/o3> }";
472490
SPARQLQueryDefinition qdef = smgr.newQueryDefinition(defGraphQuery);
473491

474492
// negative, no insert
475-
qdef.setUsingNamedGraphUris("http://example.org/baloney");
493+
qdef.setUsingNamedGraphUris("http://marklogic.com/SPARQLQDefTest/baloney");
476494
smgr.executeUpdate(qdef);
477495

478496
SPARQLQueryDefinition checkDef = smgr.newQueryDefinition(checkQuery);
479-
checkDef.setDefaultGraphUris("http://example.org/g65");
497+
checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g65");
480498
assertFalse(smgr.executeAsk(checkDef));
481499

482500
// positive
483-
qdef.setUsingNamedGraphUris("http://example.org/g1");
501+
qdef.setUsingNamedGraphUris("http://marklogic.com/SPARQLQDefTest/g1");
484502
smgr.executeUpdate(qdef);
485503

486-
checkDef.setDefaultGraphUris("http://example.org/g65");
504+
checkDef.setDefaultGraphUris("http://marklogic.com/SPARQLQDefTest/g65");
487505
assertTrue(smgr.executeAsk(checkDef));
488506
}
489507

@@ -494,7 +512,7 @@ public void testIncludeDefaultInference() {
494512
// check query with and without
495513
// uninstall default inference.
496514
SPARQLQueryDefinition qdef = smgr
497-
.newQueryDefinition("select ?o where {?s a ?o . filter (?s = <http://example.org/r4> )}");
515+
.newQueryDefinition("select ?o where {?s a ?o . filter (?s = <http://marklogic.com/SPARQLQDefTest/r4> )}");
498516
qdef.setIncludeDefaultRulesets(false);
499517

500518
assertFalse(qdef.getIncludeDefaultRulesets());
@@ -511,7 +529,7 @@ public void testIncludeDefaultInference() {
511529

512530
qdef = smgr
513531
.newQueryDefinition(
514-
"select ?o where {?s a ?o . filter (?s = <http://example.org/r4> )}")
532+
"select ?o where {?s a ?o . filter (?s = <http://marklogic.com/SPARQLQDefTest/r4> )}")
515533
.withIncludeDefaultRulesets(false);
516534

517535
// TODO removeDefaultInference();

0 commit comments

Comments
 (0)