use of org.apache.jena.query.Query in project jena by apache.
the class TestClassify method classifyLJ.
/**
* Test left join classification
* @param pattern WHERE clause for the query as a string
* @param expected Whether the join should be classified as linear
*/
private void classifyLJ(String pattern, boolean expected) {
String qs1 = "PREFIX : <http://example/>\n";
String qs = qs1 + "SELECT * " + pattern;
Query query = QueryFactory.create(qs, Syntax.syntaxARQ);
Op op = Algebra.compile(query.getQueryPattern());
if (!(op instanceof OpLeftJoin))
fail("Not a leftjoin: " + pattern);
boolean nonLinear = LeftJoinClassifier.isLinear((OpLeftJoin) op);
assertEquals("LeftJoin: " + pattern, expected, nonLinear);
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestSerialization method test.
private void test(String qs1, String qs2, boolean result) {
Query q1 = null;
Query q2 = null;
try {
q1 = QueryFactory.create(qs1, Syntax.syntaxSPARQL);
} catch (Exception ex) {
fail("Building query 1");
}
try {
q2 = QueryFactory.create(qs2, Syntax.syntaxSPARQL);
} catch (Exception ex) {
fail("Building query 2");
}
boolean b = false;
try {
b = q1.equals(q2);
} catch (Exception ex) {
ex.printStackTrace(System.err);
fail("Evaluating .equals");
}
if (result)
assertTrue(b);
else
assertFalse(b);
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestFlattenSyntax method test.
private static void test(String input, String expected) {
if (expected == null)
expected = input;
String qs = gen(PRE, input);
String qsExpected = gen(PRE, expected);
Query query = QueryFactory.create(qs, Syntax.syntaxARQ);
Query query2 = QueryTransformOps.transform(query, new ElementTransformCleanGroupsOfOne());
Query queryExpected = QueryFactory.create(qsExpected, Syntax.syntaxARQ);
Op op1 = Algebra.compile(query);
Op op2 = Algebra.compile(query2);
assertEquals("Algebra different", op1, op2);
boolean modified = !query.equals(query2);
boolean expectModification = !queryExpected.equals(query);
assertEquals("Expect query modifed?", expectModification, modified);
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestService method query_service_context_application_02.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_02() {
// This test requires us to set some authentication credentials for the
// service
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
HttpClient testClient = HttpClients.custom().build();
serviceContext.put(Service.queryClient, testClient);
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(-1, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertEquals(testClient, engine.getClient());
} finally {
serviceContext.remove(Service.queryClient);
}
}
use of org.apache.jena.query.Query in project jena by apache.
the class TestService method query_service_context_application_05.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_05() {
// This test requires us to set that GZip and Deflate are permitted
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
serviceContext.put(Service.queryCompression, false);
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(-1, engine.getTimeout2());
Assert.assertFalse(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryCompression);
}
}
Aggregations