SparqlQueryFactory implements QueryFactory { @Override public QueryImpl createNativeQuery(String sparql) { Objects.requireNonNull(sparql); final QueryImpl q = new QueryImpl(queryParser.parseQuery(sparql), connection); q.useBackupOntology(uow.useBackupOntologyForQueryProcessing()); return q; } SparqlQueryFactory(UnitOfWorkImpl uow, ConnectionWrapper connection); @Override QueryImpl createNativeQuery(String sparql); @Override TypedQueryImpl<T> createNativeQuery(String sparql, Class<T> resultClass); @Override QueryImpl createNativeQuery(String sparql, String resultSetMapping); @Override QueryImpl createQuery(String query); @Override TypedQueryImpl<T> createQuery(String query, Class<T> resultClass); @Override QueryImpl createNamedQuery(String name); @Override TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass);  }
@Test public void testCreateNativeQuery() { final Query q = factory.createNativeQuery(QUERY); assertNotNull(q); verify(uowMock).useBackupOntologyForQueryProcessing(); }
@Test(expected = NullPointerException.class) public void testCreateNativeQueryNull() { final Query q = factory.createNativeQuery(null); assert q == null; }
@Test public void testCreateNativeQueryTyped() { final TypedQuery<OWLClassA> q = factory.createNativeQuery(QUERY, CLS); assertNotNull(q); verify(uowMock).useBackupOntologyForQueryProcessing(); }
@Test(expected = NullPointerException.class) public void testCreateNativeQueryTypedNullQuery() { final TypedQuery<OWLClassA> q = factory.createNativeQuery(null, CLS); assert q == null; }
@Test(expected = NullPointerException.class) public void testCreateNativeQueryTypedNullType() { final TypedQuery<OWLClassA> q = factory.createNativeQuery(QUERY, (Class<OWLClassA>) null); assert q == null; }
@Test public void createQueryWithMappingPassesCorrectMapperToQueryInstance() { final String mapping = "testMapping"; final SparqlResultMapper mapperMock = mock(SparqlResultMapper.class); final ResultSetMappingManager managerMock = mock(ResultSetMappingManager.class); when(uowMock.getResultSetMappingManager()).thenReturn(managerMock); when(managerMock.getMapper(mapping)).thenReturn(mapperMock); final Query q = factory.createNativeQuery(QUERY, mapping); assertNotNull(q); verify(managerMock).getMapper(mapping); }