@Test public void testInComparison2() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertFalse(result.hasNext()); }
assertFalse(bob.equals(s)); // should not be present in default assertFalse(alice.equals(s)); // should not be present in default
@Test public void testNullContext1() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(" SELECT * "); query.append(" FROM DEFAULT "); query.append(" WHERE { ?s ?p ?o } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); Resource s = (Resource)bs.getValue("s"); assertNotNull(s); assertFalse(bob.equals(s)); // should not be present in default // graph assertFalse(alice.equals(s)); // should not be present in default // graph } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testInComparison2() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertFalse(result.hasNext()); }
assertFalse(result.contains(e, null, null)); Set<Value> objects = result.filter(d, p, null).objects(); assertNotNull(objects);
assertFalse(bob.equals(s)); // should not be present in default assertFalse(alice.equals(s)); // should not be present in default
@Test public void testNullContext1() throws Exception { loadTestData("/testdata-query/dataset-query.trig"); StringBuilder query = new StringBuilder(); query.append(" SELECT * "); query.append(" FROM DEFAULT "); query.append(" WHERE { ?s ?p ?o } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); while (result.hasNext()) { BindingSet bs = result.next(); assertNotNull(bs); Resource s = (Resource)bs.getValue("s"); assertNotNull(s); assertFalse(bob.equals(s)); // should not be present in default // graph assertFalse(alice.equals(s)); // should not be present in default // graph } result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSES2024PropertyPathAnonVarSharing() throws Exception { loadTestData("/testdata-query/dataset-ses2024.trig"); String query = "PREFIX : <http://example.org/> SELECT * WHERE { ?x1 :p/:lit ?l1 . ?x1 :diff ?x2 . ?x2 :p/:lit ?l2 . }" ; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); BindingSet bs = result.next(); Literal l1 = (Literal)bs.getValue("l1"); Literal l2 = (Literal)bs.getValue("l2"); assertNotNull(l1); assertFalse(l1.equals(l2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
assertTrue(result.contains(e, RDFS.LABEL, null)); assertTrue(result.contains(null, p, e)); assertFalse(result.contains(f, null, null)); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects);
@Test public void testSES1991STRUUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(STRUUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal uid1 = (Literal)result.next().getValue("uid"); Literal uid2 = (Literal)result.next().getValue("uid"); assertNotNull(uid1); assertFalse(uid1.equals(uid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSES1991UUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(UUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); URI uuid1 = (URI)result.next().getValue("uid"); URI uuid2 = (URI)result.next().getValue("uid"); assertNotNull(uuid1); assertNotNull(uuid2); assertFalse(uuid1.equals(uuid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSES1991RANDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?r WHERE {?s ?p ?o . BIND(RAND() as ?r) } LIMIT 3"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal r1 = (Literal)result.next().getValue("r"); Literal r2 = (Literal)result.next().getValue("r"); Literal r3 = (Literal)result.next().getValue("r"); assertNotNull(r1); // there is a small chance that two successive calls to the random // number generator will generate the exact same value, so we check for // three successive calls (still theoretically possible to be // identical, but phenomenally unlikely). assertFalse(r1.equals(r2) && r1.equals(r3)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
assertFalse(result.contains(e, null, null)); Set<Value> objects = result.filter(d, p, null).objects(); assertNotNull(objects);
@Test public void testSES2024PropertyPathAnonVarSharing() throws Exception { loadTestData("/testdata-query/dataset-ses2024.trig"); String query = "PREFIX : <http://example.org/> SELECT * WHERE { ?x1 :p/:lit ?l1 . ?x1 :diff ?x2 . ?x2 :p/:lit ?l2 . }" ; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); BindingSet bs = result.next(); Literal l1 = (Literal)bs.getValue("l1"); Literal l2 = (Literal)bs.getValue("l2"); assertNotNull(l1); assertFalse(l1.equals(l2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSES1991STRUUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(STRUUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal uid1 = (Literal)result.next().getValue("uid"); Literal uid2 = (Literal)result.next().getValue("uid"); assertNotNull(uid1); assertFalse(uid1.equals(uid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
assertTrue(result.contains(e, RDFS.LABEL, null)); assertTrue(result.contains(null, p, e)); assertFalse(result.contains(f, null, null)); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects);
@Test public void testSES1991UUIDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?uid WHERE {?s ?p ?o . BIND(UUID() as ?uid) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); URI uuid1 = (URI)result.next().getValue("uid"); URI uuid2 = (URI)result.next().getValue("uid"); assertNotNull(uuid1); assertNotNull(uuid2); assertFalse(uuid1.equals(uuid2)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testSES1991RANDEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?r WHERE {?s ?p ?o . BIND(RAND() as ?r) } LIMIT 3"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal r1 = (Literal)result.next().getValue("r"); Literal r2 = (Literal)result.next().getValue("r"); Literal r3 = (Literal)result.next().getValue("r"); assertNotNull(r1); // there is a small chance that two successive calls to the random // number generator will generate the exact same value, so we check for // three successive calls (still theoretically possible to be // identical, but phenomenally unlikely). assertFalse(r1.equals(r2) && r1.equals(r3)); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }