SailRepositoryConnection extends AbstractRepositoryConnection implements FederatedServiceResolverClient,
		RepositoryResolverClient, HttpClientDependent, SessionManagerDependent { @Override public SailQuery prepareQuery(QueryLanguage ql, String queryString, String baseURI) throws MalformedQueryException { ParsedQuery parsedQuery = QueryParserUtil.parseQuery(ql, queryString, baseURI); if (parsedQuery instanceof ParsedTupleQuery) { Optional<TupleExpr> sailTupleExpr = sailConnection.prepareQuery(ql, Query.QueryType.TUPLE, queryString, baseURI); if (sailTupleExpr.isPresent()) { parsedQuery = new ParsedTupleQuery(queryString, sailTupleExpr.get()); } return new SailTupleQuery((ParsedTupleQuery) parsedQuery, this); } else if (parsedQuery instanceof ParsedGraphQuery) { Optional<TupleExpr> sailTupleExpr = sailConnection.prepareQuery(ql, Query.QueryType.GRAPH, queryString, baseURI); if (sailTupleExpr.isPresent()) { parsedQuery = new ParsedGraphQuery(queryString, sailTupleExpr.get()); } return new SailGraphQuery((ParsedGraphQuery) parsedQuery, this); } else if (parsedQuery instanceof ParsedBooleanQuery) { Optional<TupleExpr> sailTupleExpr = sailConnection.prepareQuery(ql, Query.QueryType.BOOLEAN, queryString, baseURI); if (sailTupleExpr.isPresent()) { parsedQuery = new ParsedBooleanQuery(queryString, sailTupleExpr.get()); } return new SailBooleanQuery((ParsedBooleanQuery) parsedQuery, this); } else { throw new RuntimeException("Unexpected query type: " + parsedQuery.getClass()); } } protected  SailRepositoryConnection(SailRepository repository, SailConnection sailConnection); SailConnection getSailConnection(); @Override void setFederatedServiceResolver(FederatedServiceResolver resolver); @Override void setRepositoryResolver(RepositoryResolver resolver); @Override HttpClientSessionManager getHttpClientSessionManager(); @Override void setHttpClientSessionManager(HttpClientSessionManager client); @Override HttpClient getHttpClient(); @Override void setHttpClient(HttpClient client); @Override void begin(); @Override void begin(IsolationLevel level); @Override void begin(TransactionSetting... settings); @Override void commit(); @Override void rollback(); @Override void close(); @Override boolean isOpen(); @Override SailQuery prepareQuery(QueryLanguage ql, String queryString, String baseURI); @Override SailTupleQuery prepareTupleQuery(QueryLanguage ql, String queryString, String baseURI); @Override SailGraphQuery prepareGraphQuery(QueryLanguage ql, String queryString, String baseURI); @Override SailBooleanQuery prepareBooleanQuery(QueryLanguage ql, String queryString, String baseURI); @Override Update prepareUpdate(QueryLanguage ql, String update, String baseURI); @Override boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts); @Override RepositoryResult<Resource> getContextIDs(); @Override RepositoryResult<Statement> getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred,
			Resource... contexts); @Override boolean isEmpty(); @Override void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler,
			Resource... contexts); @Override long size(Resource... contexts); @Override void clear(Resource... contexts); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override boolean isActive(); @Override String toString();  }
@Test public void testPrepareQuery_not_bypassed() throws Exception { Optional<TupleExpr> response = Optional.empty(); when(sailConnection.prepareQuery(any(), eq(Query.QueryType.TUPLE), any(), any())).thenReturn(response); when(sailConnection.evaluate(any(), any(), any(), anyBoolean())).thenReturn(new EmptyIteration<>()); TupleQuery query = (TupleQuery) subject.prepareQuery("SELECT * WHERE { ?s ?p ?o }"); query.evaluate(); verify(sailConnection).evaluate(any(TupleExpr.class), any(), any(), anyBoolean()); }
@Test public void testPrepareQuery_bypassed() throws Exception { TupleExpr expr = mock(TupleExpr.class); Optional<TupleExpr> response = Optional.of(expr); when(sailConnection.prepareQuery(any(), eq(Query.QueryType.GRAPH), any(), any())).thenReturn(response); when(sailConnection.evaluate(eq(expr), any(), any(), anyBoolean())).thenReturn(new EmptyIteration<>()); GraphQuery query = (GraphQuery) subject.prepareQuery("CONSTRUCT WHERE { ?s ?p ?o }"); query.evaluate(); verify(sailConnection).evaluate(eq(expr), any(), any(), anyBoolean()); }