use of org.apache.jena.shared.JenaException in project jena by apache.
the class ExceptionTests method testDefaultPromotedError.
public void testDefaultPromotedError() {
RDFDefaultErrorHandler.silent = true;
try {
Model m = ModelFactory.createDefaultModel();
RDFReader rdr = m.getReader();
rdr.setProperty("ERR_BAD_RDF_ATTRIBUTE", "EM_FATAL");
rdr.read(m, "file:testing/wg/rdfms-abouteach/error002.rdf");
fail("Promoted error did not throw exception");
} catch (JenaException e) {
// System.err.println(e.getMessage());
} finally {
RDFDefaultErrorHandler.silent = false;
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ReasonerTester method runTest.
/**
* Run a single designated test.
* @param uri the uri of the test, as defined in the manifest file
* @param reasoner the reasoner to be tested
* @param testcase the JUnit test case which is requesting this test
* @return true if the test passes
* @throws IOException if one of the test files can't be found
* @throws JenaException if the test can't be found or fails internally
*/
public boolean runTest(String uri, Reasoner reasoner, TestCase testcase) throws IOException {
// Find the specification for the named test
Resource test = testManifest.getResource(uri);
if (!test.hasProperty(RDF.type, testClass)) {
throw new JenaException("Can't find test: " + uri);
}
String description = test.getRequiredProperty(descriptionP).getObject().toString();
logger.debug("Reasoner test " + test.getURI() + " - " + description);
// Construct the inferred graph
Graph tbox = loadTestFile(test, tboxP);
Graph data = loadTestFile(test, dataP);
InfGraph graph = reasoner.bindSchema(tbox).bind(data);
// Run each query triple and accumulate the results
Graph queryG = loadTestFile(test, queryP);
Graph resultG = Factory.createGraphMem();
Iterator<Triple> queries = queryG.find(null, null, null);
while (queries.hasNext()) {
TriplePattern query = tripleToPattern(queries.next());
logger.debug("Query: " + query);
Iterator<Triple> answers = graph.find(query.asTripleMatch());
while (answers.hasNext()) {
Triple ans = answers.next();
logger.debug("ans: " + TriplePattern.simplePrintString(ans));
resultG.add(ans);
}
}
// Check the total result set against the correct answer
Graph correctG = loadTestFile(test, resultP);
boolean correct = correctG.isIsomorphicWith(resultG);
// ... end of debugging hack
if (testcase != null) {
Assert.assertTrue(description, correct);
}
return correct;
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class TestJenaException method testRethrownMessage.
public void testRethrownMessage() {
Exception e = new Exception("kings and queens");
JenaException j = new JenaException(e);
assertTrue(j.getMessage().endsWith(e.getMessage()));
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt) {
try {
Query query = modQuery.getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(System.out, true);
query.serialize(out);
out.flush();
System.out.println();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactionAbort()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt);
} catch (QueryCancelledException ex) {
System.out.flush();
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} catch (ResultSetException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
} catch (QueryException qEx) {
// System.err.println(qEx.getMessage()) ;
throw new CmdException("Query Exeception", qEx);
}
});
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
} catch (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class GraphTestBase method getGraph.
/**
Answer an instance of <code>graphClass</code>. If <code>graphClass</code> has
a constructor that takes a <code>ReificationStyle</code> argument, then that
constructor is run on <code>style</code> to get the instance. Otherwise, if it has a #
constructor that takes an argument of <code>wrap</code>'s class before the
<code>ReificationStyle</code>, that constructor is used; this allows non-static inner
classes to be used for <code>graphClass</code>, with <code>wrap</code> being
the outer class instance. If no suitable constructor exists, a JenaException is thrown.
@param wrap the outer class instance if graphClass is an inner class
@param graphClass a class implementing Graph
@return an instance of graphClass with the given style
@throws RuntimeException or JenaException if construction fails
*/
public static Graph getGraph(Object wrap, Class<? extends Graph> graphClass) {
try {
Constructor<?> cons = getConstructor(graphClass, new Class[] {});
if (cons != null)
return (Graph) cons.newInstance(new Object[] {});
Constructor<?> cons2 = getConstructor(graphClass, new Class[] { wrap.getClass() });
if (cons2 != null)
return (Graph) cons2.newInstance(new Object[] { wrap });
throw new JenaException("no suitable graph constructor found for " + graphClass);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new JenaException(e);
}
}
Aggregations