@Test
public void testExceptionOnQuery() {
DummyQueryResponder queryResponder = new DummyQueryResponder(20) {
private ErrorResponse err() {
ErrorResponse resp = new ErrorResponse();
resp.code = ReasonCode.Error;
resp.serverException = new ServerException();
resp.serverException.message = "foo";
return resp;
}
@Override
public QueryResponse query(QueryRequest query)
throws AvroRemoteException, ErrorResponse {
throw err();
}
};
try {
QueryExecution mgr = new QueryExecution(queryResponder);
Map<String,String> empty = Collections.emptyMap();
mgr.query("SELECT foo", empty, empty);
Assert.fail("Should have thrown an error response!");
} catch(SparqlException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof ErrorResponse);
ErrorResponse er = (ErrorResponse) cause;
Assert.assertEquals(ReasonCode.Error, er.code);
Assert.assertEquals("foo", er.serverException.message);
}
}