Search in sources :

Example 31 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestQueryExecDataset method queryExec_substitution_01.

// Most QueryExec testing gets tested via QueryExecution usage
@Test
public void queryExec_substitution_01() {
    QueryExec queryExec = QueryExec.dataset(DatasetGraphFactory.empty()).query("SELECT * { ?s ?p ?o }").substitution(Var.alloc("s"), SSE.parseNode(":x")).build();
    Query query = queryExec.getQuery();
    String s = query.toString();
    assertTrue(s.contains("http://example/x"));
}
Also used : Query(org.apache.jena.query.Query) Test(org.junit.Test)

Example 32 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestSerialization method testOpToSyntax.

private void testOpToSyntax(String opStr, String queryString) {
    Op op = SSE.parseOp(opStr);
    Query queryConverted = OpAsQuery.asQuery(op);
    Query queryExpected = QueryFactory.create(queryString, queryConverted.getSyntax());
    // if ( ! queryExpected.equals(queryConverted) )
    // {
    // System.err.println("Query Expected: "+queryExpected.getSyntax()) ;
    // System.err.println(queryExpected) ;
    // 
    // System.err.println("Query Converted: "+queryConverted.getSyntax()) ;
    // System.err.println(queryConverted) ;
    // System.err.println() ;
    // }
    assertEquals(queryExpected, queryConverted);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpAsQuery(org.apache.jena.sparql.algebra.OpAsQuery) Query(org.apache.jena.query.Query)

Example 33 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestSyntaxTransform method testQueryModel.

private void testQueryModel(String input, String output, String varStr, String valStr) {
    Query q1 = QueryFactory.create(PREFIX + input);
    Query qExpected = QueryFactory.create(PREFIX + output);
    Map<String, RDFNode> map = Map.of(varStr, fromString(valStr));
    Query qTrans = QueryTransformOps.transformQuery(q1, map);
    assertEquals(qExpected, qTrans);
}
Also used : Query(org.apache.jena.query.Query) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 34 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestSyntaxTransform method testQuery.

private void testQuery(String input, String output, String varStr, String valStr) {
    Query q1 = QueryFactory.create(PREFIX + input);
    Query qExpected = QueryFactory.create(PREFIX + output);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(varStr), SSE.parseNode(valStr));
    Query qTrans = QueryTransformOps.transform(q1, map);
    if (!qExpected.equals(qTrans)) {
        System.out.println(qExpected.getProject());
        System.out.print(qExpected);
        System.out.println(qTrans.getProject());
        System.out.print(qTrans);
    }
    assertEquals(qExpected, qTrans);
}
Also used : Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 35 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestQueryOps method testShallowCopy.

private static void testShallowCopy(String queryString) {
    Query q1 = QueryFactory.create(queryString);
    Query q2 = QueryTransformOps.shallowCopy(q1);
    assertEquals(q1, q2);
}
Also used : Query(org.apache.jena.query.Query)

Aggregations

Query (org.apache.jena.query.Query)265 Test (org.junit.Test)78 ContractTest (org.xenei.junit.contract.ContractTest)65 QueryExecution (org.apache.jena.query.QueryExecution)63 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)49 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)42 Var (org.apache.jena.sparql.core.Var)42 Triple (org.apache.jena.graph.Triple)38 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)32 ResultSet (org.apache.jena.query.ResultSet)29 Node (org.apache.jena.graph.Node)28 TriplePath (org.apache.jena.sparql.core.TriplePath)28 QuerySolution (org.apache.jena.query.QuerySolution)26 ExprVar (org.apache.jena.sparql.expr.ExprVar)24 Binding (org.apache.jena.sparql.engine.binding.Binding)22 Model (org.apache.jena.rdf.model.Model)20 HashMap (java.util.HashMap)19 Dataset (org.apache.jena.query.Dataset)15 Op (org.apache.jena.sparql.algebra.Op)15 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)14