Skip to content

Commit

Permalink
[ issue #15 ] Added SparqlQParser Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
agazzarini committed Feb 14, 2015
1 parent a5d33ba commit 5eaa108
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.solr.search.SyntaxError;

import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QueryParseException;

/**
* A SPARQL Query Parser.
Expand Down Expand Up @@ -37,7 +36,7 @@ public class SparqlQParser extends QParser {
public Query parse() throws SyntaxError {
try {
return new SparqlQuery(QueryFactory.create(qstr));
} catch (final QueryParseException exception) {
} catch (final Exception exception) {
throw new SyntaxError(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.gazzax.labs.solrdf.search.qparser;

import static org.gazzax.labs.solrdf.TestUtility.randomString;
import static org.mockito.Mockito.mock;

import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.QParser;
import org.apache.solr.search.SyntaxError;
import org.junit.Before;
import org.junit.Test;

/**
* {@link SparqlQParser} test case.
*
* @author Andrea Gazzarini
* @since 1.0
*/
public class SparqlQParserTestCase {
private QParser cut;

private SolrQueryRequest request;
private SolrParams localParams;
private SolrParams params;

@Before
public void setUp() {
request = mock(SolrQueryRequest.class);
}

/**
* If a null query string is given, then an exception must be raised.
*/
@Test
public void nullQueryString() {
cut = new SparqlQParser(null, localParams, params, request);

try {
cut.parse();
} catch(final SyntaxError expected) {
// Nothing, as this is the expected behaviour
}
}

/**
* If an invalid query string is given, then an exception must be raised.
*/
@Test
public void invalidQueryString() {
cut = new SparqlQParser(randomString(), localParams, params, request);

try {
cut.parse();
} catch(final SyntaxError expected) {
// Nothing, as this is the expected behaviour
}
}

/**
* Positive test case.
*
* @throws Exception hopefully never, otherwise the test fails.
*/
@Test
public void validQueryString() throws Exception {
cut = new SparqlQParser("SELECT * WHERE { ?s ?p ?o }", localParams, params, request);

try {
cut.parse();
} catch(final SyntaxError expected) {
// Nothing, as this is the expected behaviour
}
}
}

0 comments on commit 5eaa108

Please sign in to comment.