use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class CbSailTest method testSimpleQuery.
public void testSimpleQuery() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI cpu = vf.createURI(litdupsNS, "cpu");
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.commit();
conn.close();
resultEndpoint.expectedMessageCount(1);
// query through camel
String query = "select * where {" + "<" + cpu.toString() + "> ?p ?o1." + "}";
template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query);
assertMockEndpointsSatisfied();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class ConformanceTest method run.
@Override
public int run(final String[] args) throws Exception {
// Validate command
if (args.length < 1 || args.length > 2) {
System.out.println("Usage:\n");
System.out.println("\tConformanceTest [configuration options] " + "<test-file> <temp-dir>\n");
System.out.println("to load test data from an RDF file " + "(configuration property " + MRUtils.FORMAT_PROP + " specifies the format, default RDF/XML); or\n");
System.out.println("\tConformanceTest [configuration options] <temp-dir>\n");
System.out.println("to load test data from a Rya instance (specified " + "using standard configuration properties).\n");
System.out.println("For each test given, run the reasoner over the " + "premise ontology using a temporary Mini Accumulo instance " + "at <temp-dir>, then report conformance results.");
System.exit(1);
}
final Set<Value> conformanceTestURIs = new HashSet<>();
Collection<OwlTest> conformanceTests = new LinkedList<>();
final List<OwlTest> successes = new LinkedList<>();
final List<OwlTest> failures = new LinkedList<>();
final Configuration conf = getConf();
Repository repo;
File workingDir;
// If tests are in a file, stick them in a repository for querying
if (args.length == 2) {
workingDir = new File(PathUtils.clean(args[1]));
RDFFormat inputFormat = RDFFormat.RDFXML;
final String formatString = conf.get(MRUtils.FORMAT_PROP);
if (formatString != null) {
inputFormat = RDFFormat.valueOf(formatString);
}
repo = new SailRepository(new MemoryStore());
repo.initialize();
final RepositoryConnection conn = repo.getConnection();
FileInputStream fileInput = new FileInputStream(PathUtils.clean(args[0]));
conn.add(fileInput, "", inputFormat);
fileInput.close();
conn.close();
} else // Otherwise, get a Rya repository
{
workingDir = new File(PathUtils.clean(args[0]));
repo = MRReasoningUtils.getRepository(conf);
repo.initialize();
}
// Query for the tests we're interested in
final RepositoryConnection conn = repo.getConnection();
conformanceTestURIs.addAll(getTestURIs(conn, TEST_INCONSISTENCY));
conformanceTestURIs.addAll(getTestURIs(conn, TEST_CONSISTENCY));
conformanceTestURIs.addAll(getTestURIs(conn, TEST_ENTAILMENT));
conformanceTestURIs.addAll(getTestURIs(conn, TEST_NONENTAILMENT));
conformanceTests = getTests(conn, conformanceTestURIs);
conn.close();
repo.shutDown();
// Set up a MiniAccumulo cluster and set up conf to connect to it
final String username = "root";
final String password = "root";
final MiniAccumuloCluster mini = new MiniAccumuloCluster(workingDir, password);
mini.start();
conf.set(MRUtils.AC_INSTANCE_PROP, mini.getInstanceName());
conf.set(MRUtils.AC_ZK_PROP, mini.getZooKeepers());
conf.set(MRUtils.AC_USERNAME_PROP, username);
conf.set(MRUtils.AC_PWD_PROP, password);
conf.setBoolean(MRUtils.AC_MOCK_PROP, false);
conf.set(MRUtils.TABLE_PREFIX_PROPERTY, "temp_");
// Run the conformance tests
int result;
for (final OwlTest test : conformanceTests) {
System.out.println(test.uri);
result = runTest(conf, args, test);
if (result != 0) {
return result;
}
if (test.success) {
successes.add(test);
System.out.println("(SUCCESS)");
} else {
failures.add(test);
System.out.println("(FAIL)");
}
}
mini.stop();
System.out.println("\n" + successes.size() + " successful tests:");
for (final OwlTest test : successes) {
System.out.println("\t[SUCCESS] " + test.type() + " " + test.name);
}
System.out.println("\n" + failures.size() + " failed tests:");
for (final OwlTest test : failures) {
System.out.println("\t[FAIL] " + test.type() + " " + test.name);
System.out.println("\t\t(" + test.description + ")");
for (final Statement triple : test.error) {
if (test.types.contains(TEST_ENTAILMENT)) {
System.out.println("\t\tExpected: " + triple);
} else if (test.types.contains(TEST_NONENTAILMENT)) {
System.out.println("\t\tUnexpected: " + triple);
}
}
}
return 0;
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfControllerTest method setup.
@Before
public void setup() {
this.mockMvc = standaloneSetup(controller).build();
try {
RepositoryConnection con = repository.getConnection();
con.add(getClass().getResourceAsStream("/test.nt"), "", RDFFormat.NTRIPLES);
con.close();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class ArbitraryLengthQueryTest method testWithoutSubquery.
/**
* This test works. The expected result is 6 rows ranging from "Model1Class 1" through "Model1Class 6".
*
* @throws RepositoryException
* @throws QueryEvaluationException
* @throws TupleQueryResultHandlerException
*
* @throws MalformedQueryException
*/
public void testWithoutSubquery() throws RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, MalformedQueryException {
final String query = "SELECT ?i ?i_label ?i_class ?i_v1" + "WHERE {" + "?i <http://www.w3.org/2000/01/rdf-schema#label> ?i_label ." + "?i a ?i_class ." + "?i_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#Model1Class> ." + "OPTIONAL { ?i <http://dragon-research.com/cham/model/model1#name> ?i_v1 } ." + "}" + "ORDER BY ?i_label";
final RepositoryConnection conn = repository.getConnection();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
RdfCloudTripleStoreConnectionTest.CountTupleHandler countTupleHandler = new RdfCloudTripleStoreConnectionTest.CountTupleHandler();
tupleQuery.evaluate(countTupleHandler);
assertEquals(6, countTupleHandler.getCount());
conn.close();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class ArbitraryLengthQueryTest method testWithSubquery.
/**
* This test fails. The expected result is 6 rows ranging from "Model1Class 1 Event" to "Model1Class 6 Event". The
* current result is a RejectedExecutionException.
*
* @throws RepositoryException
* @throws QueryEvaluationException
* @throws TupleQueryResultHandlerException
*
* @throws MalformedQueryException
*/
public void testWithSubquery() throws RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, MalformedQueryException {
final String query = "SELECT ?i ?i_label ?i_class ?i_v1 ?i_v2 ?i_v2_label ?i_v2_class ?i_v2_v1" + "WHERE {" + "?i <http://www.w3.org/2000/01/rdf-schema#label> ?i_label ." + "?i a ?i_class ." + "?i_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#Event> ." + "OPTIONAL { ?i <http://dragon-research.com/cham/model/model1#name> ?i_v1 } ." + "?i <http://dragon-research.com/cham/model/model1#hasTemporalEntity> ?i_v2 ." + "{" + "SELECT ?i_v2 ?i_v2_label ?i_v2_class ?i_v2_v1" + "WHERE {" + "?i_v2 <http://www.w3.org/2000/01/rdf-schema#label> ?i_v2_label ." + "?i_v2 a ?i_v2_class ." + "?i_v2_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#TemporalInstant> ." + "OPTIONAL { ?i_v2 <http://dragon-research.com/cham/model/model1#dateTime> ?i_v2_v1 } ." + "}" + "ORDER BY ?i_v2_label" + "}" + "}" + "ORDER BY ?i_label";
final RepositoryConnection conn = repository.getConnection();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
RdfCloudTripleStoreConnectionTest.CountTupleHandler countTupleHandler = new RdfCloudTripleStoreConnectionTest.CountTupleHandler();
tupleQuery.evaluate(countTupleHandler);
assertEquals(6, countTupleHandler.getCount());
conn.close();
}
Aggregations