Skip to content

Commit

Permalink
Junit for SPARQL generation on objects of complex ranges : make sure …
Browse files Browse the repository at this point in the history
…the type clause is included
  • Loading branch information
Paul Cuddihy committed May 25, 2022
1 parent 335289f commit cbc9335
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static void setup() throws Exception {
// load Batttery
sgJsonBattery = TestGraph.addModelAndData(QueryGenTest_IT.class, "sampleBattery");

// load RangeTest (owl contains model and a little data)
TestGraph.uploadOwlContents(Utility.getResourceAsString(QueryGenTest_IT.class, "RangeTest.owl"));
}

// TODO : all tests should have corresponding CONSTRUCT
Expand Down Expand Up @@ -812,6 +814,16 @@ public void test_createConstructAllConnectedBattery() throws Exception {
assertTrue("Results are missing: " + lookup, res.contains(lookup));
}
}

@Test
public void testComplexRangeQuery() throws Exception {
// WeirdBird has two children, and hasChild has a complex range {Bird, Unusual}
// A query for just the bird should return just the bird
SparqlGraphJson sgjson = TestGraph.getSparqlGraphJsonFromResource(this.getClass(), "rangeTestComplexRangeQuery.json");
Table res = TestGraph.execTableSelect(sgjson);
assertEquals("Complex range query returned the wrong number of rows", 1, res.getNumRows());
}

/**
* Count the number of attributes of items in a Graph where key.contains(keyContains) and value.contains(valContains)
* Not recursive, checks each element in the graph array.
Expand Down
16 changes: 10 additions & 6 deletions sparqlGraphLibrary/src/test/resources/RangeTest.owl
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,21 @@
<rdfs:range rdf:resource="#Egg"/>
</owl:ObjectProperty>
<Bird rdf:ID="bir"/>
<Duck rdf:ID="duc">
<hasChild>
<Animal rdf:ID="ani"/>
</hasChild>
</Duck>
<Separate rdf:ID="sep"/>
<Unusual rdf:ID="unu"/>
<WeirdBird rdf:ID="wei">
<hasAnotherEgg>
<Egg rdf:ID="egg"/>
</hasAnotherEgg>
<hasChild>
<Unusual rdf:ID="unu"/>
</hasChild>
<hasChild>
<Duck rdf:ID="duc">
<hasChild>
<Animal rdf:ID="ani"/>
</hasChild>
</Duck>
</hasChild>
</WeirdBird>
<Rabbit rdf:ID="rab"/>
<Another rdf:ID="ano"/>
Expand Down
2 changes: 2 additions & 0 deletions sparqlGraphLibrary/src/test/resources/RangeTest.sadl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ duc is a Duck.
rab is a Rabbit.
wei is a WeirdBird.

wei hasChild duc.
wei hasChild unu.

// Sadl warns. Semtk says this is fine
wei hasAnotherEgg egg.
Expand Down
100 changes: 100 additions & 0 deletions sparqlGraphLibrary/src/test/resources/rangeTestComplexRangeQuery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"version": 3,
"sparqlConn": {
"name": "Junit fuseki",
"domain": "",
"enableOwlImports": true,
"model": [
{
"type": "fuseki",
"url": "http://localhost:3030/JUNIT",
"graph": "http://junit/GG2NQYY2E/200001934/both"
}
],
"data": [
{
"type": "fuseki",
"url": "http://localhost:3030/JUNIT",
"graph": "http://junit/GG2NQYY2E/200001934/both"
}
]
},
"sNodeGroup": {
"version": 19,
"limit": 0,
"offset": 0,
"sNodeList": [
{
"propList": [],
"nodeList": [],
"fullURIName": "http://rangetest#Duck",
"SparqlID": "?Duck",
"isReturned": true,
"isRuntimeConstrained": false,
"valueConstraint": "",
"instanceValue": null,
"deletionMode": "NO_DELETE"
},
{
"propList": [],
"nodeList": [
{
"SnodeSparqlIDs": [
"?Duck"
],
"OptionalMinus": [
0
],
"Qualifiers": [
""
],
"DeletionMarkers": [
false
],
"range": [
"http://rangetest#Duck",
"http://rangetest#Unusual"
],
"ConnectBy": "hasChild",
"Connected": true,
"UriConnectBy": "http://rangetest#hasChild"
}
],
"fullURIName": "http://rangetest#WeirdBird",
"SparqlID": "?WeirdBird",
"isReturned": true,
"isRuntimeConstrained": false,
"valueConstraint": "",
"instanceValue": null,
"deletionMode": "NO_DELETE"
}
],
"orderBy": [],
"groupBy": [],
"unionHash": {},
"columnOrder": []
},
"importSpec": {
"version": "1",
"baseURI": "",
"columns": [],
"dataValidator": [],
"texts": [],
"transforms": [],
"nodes": [
{
"sparqlID": "?WeirdBird",
"type": "http://rangetest#WeirdBird",
"mapping": [],
"props": []
},
{
"sparqlID": "?Duck",
"type": "http://rangetest#Duck",
"mapping": [],
"props": []
}
]
},
"plotSpecs": null
}

0 comments on commit cbc9335

Please sign in to comment.