Skip to content

Commit

Permalink
[#184] Add implementation to executeSPINQueryCustomJavaFunction test
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Aug 14, 2024
1 parent 5a4004b commit b06eea1
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions s-pipes-core/src/test/java/cz/cvut/spin/SpinIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cz.cvut.spin;

import cz.cvut.spipes.engine.PipelineFactory;
import org.apache.jena.ontology.OntModelSpec;
import org.apache.jena.query.QuerySolutionMap;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.*;
import org.apache.jena.util.FileUtils;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -61,20 +62,28 @@ public void executeSPINExpressionWithCustomSpinFunction() throws UnsupportedEnco
}

@Test
public void executeQueryWithCustomJavaFunction() {
SPINModuleRegistry.get().init(); //TODO is it needed ?
public void executeSPINQueryWithCustomJavaFunction() {
PipelineFactory pipelineFactory = new PipelineFactory();

// make a query with AddDays function
String query = """
@prefix kbss-timef: <http://onto.fel.cvut.cz/ontologies/lib/function/time/> .
SELECT ?nextDay
WHERE {
BIND(kbss-timef:add-days("2022-01-01"^^xsd:date, 1) as ?nextDay)
}
""";
String queryString = """
PREFIX kbss-timef: <http://onto.fel.cvut.cz/ontologies/lib/function/time/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?nextDay
WHERE {
BIND(kbss-timef:add-days("2022-01-01"^^xsd:date, 1) AS ?nextDay)
}
""";
Model model = ModelFactory.createDefaultModel();

// execute the query
Query query = QueryFactory.create(queryString);

// check the result

QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();

if (results.hasNext()) {
QuerySolution soln = results.nextSolution();
assertEquals(soln.getLiteral("nextDay").getString(), "2022-01-02");
}
}
}

0 comments on commit b06eea1

Please sign in to comment.