Skip to content

Commit

Permalink
Fix #200
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Feb 1, 2022
1 parent cd911ca commit aa80371
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public class AbstractExecutionTester {
protected static final Logger logger = LoggerFactory.getLogger(AbstractExecutionTester.class);

protected static final String FILENAME_PLACEHOLDER = "%%fileName%%";
protected Dataset dataset = null;
protected Query query = null;
protected URI expectedFile = null;
Expand Down Expand Up @@ -72,7 +73,22 @@ protected void beforeExecution() {
protected void prepareQuery() throws IOException, URISyntaxException {
String queryFileName = name.getMethodName().substring(4) + ".sparql";
URI queryFile = getClass().getClassLoader().getResource(queryFileName).toURI();
query = QueryFactory.create(IOUtils.toString(queryFile, StandardCharsets.UTF_8));
String queryStr = IOUtils.toString(queryFile, StandardCharsets.UTF_8);
queryStr = prepareQueryString(queryStr);
query = QueryFactory.create(queryStr);
}

protected String prepareQueryString(String queryStr){
// Extension point
if(queryStr.contains(FILENAME_PLACEHOLDER)){
String fileName = name.getMethodName().substring(4) + "Input";
String filePath = getClass().getClassLoader().getResource(".").getPath();
String file = filePath + "/" + fileName;
queryStr = queryStr.replace(FILENAME_PLACEHOLDER, file);
logger.debug("Input file name: {}" , file);
}
logger.debug("queryStr: {}", queryStr);
return queryStr;
}

protected void prepareDataset(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
public class ExecutionsTest extends AbstractExecutionTester {

@Test
public void testSliceSelect1(){
public void testPlainSelect(){
// Testing is working :)
Assert.assertTrue(result.getResultVars().contains("A"));
Assert.assertTrue(result.next().getLiteral("A").getBoolean());
}

@Test
public void testExecutionSelect(){
// Testing is working :)
Assert.assertTrue(result.getResultVars().contains("B"));
Assert.assertTrue(result.next().getLiteral("B").getBoolean());
}
}
2 changes: 2 additions & 0 deletions sparql-anything-it/src/test/resources/ExecutionSelect.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
B
true
14 changes: 14 additions & 0 deletions sparql-anything-it/src/test/resources/ExecutionSelect.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

select ?B
where {
service <x-sparql-anything:> {
fx:properties fx:location "%%fileName%%.csv" ; fx:csv.headers "true".
[] xyz:A ?B
}
}
2 changes: 2 additions & 0 deletions sparql-anything-it/src/test/resources/PlainSelect.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A
true

0 comments on commit aa80371

Please sign in to comment.