DefaultAddQuery implements AddQuery { @Override public StreamsQuery addQuery(final String query, final boolean isActive, final boolean isInsert) throws RyaStreamsException { requireNonNull(query); try { parser.parseQuery(query, null); } catch (final MalformedQueryException e) { throw new RyaStreamsException("Could not add the query because the SPARQL is invalid.", e); } return repository.add(query, isActive, isInsert); } DefaultAddQuery(final QueryRepository repository); @Override StreamsQuery addQuery(final String query, final boolean isActive, final boolean isInsert);  }
@Test public void addQuery_validSparql() throws Exception { final String sparql = "SELECT * WHERE { ?person <urn:worksAt> ?business }"; final QueryRepository repo = mock(QueryRepository.class); final AddQuery addQuery = new DefaultAddQuery(repo); addQuery.addQuery(sparql, true, true); verify(repo, times(1)).add(eq(sparql), eq(true), eq(true)); }
@Test(expected = RyaStreamsException.class) public void addQuery_invalidSparql() throws Exception { final String sparql = "This is not sparql."; final QueryRepository repo = mock(QueryRepository.class); final AddQuery addQuery = new DefaultAddQuery(repo); addQuery.addQuery(sparql, true, true); }