-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ issue #15 ] Added (not yet completed) SparqlSearchComponent test case
- Loading branch information
agazzarini
committed
Feb 15, 2015
1 parent
5eaa108
commit 1b7001a
Showing
2 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../src/test/java/org/gazzax/labs/solrdf/search/component/SparqlSearchComponentTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.gazzax.labs.solrdf.search.component; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.solr.common.SolrException; | ||
import org.apache.solr.common.params.CommonParams; | ||
import org.apache.solr.common.params.ModifiableSolrParams; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* {@link SparqlSearchComponent} test case. | ||
* | ||
* @author Andrea Gazzarini | ||
* @since 1.0 | ||
*/ | ||
public class SparqlSearchComponentTestCase { | ||
private SparqlSearchComponent cut; | ||
private SolrQueryRequest request; | ||
private ModifiableSolrParams params = new ModifiableSolrParams(); | ||
|
||
private final static String SAMPLE_SPARQL_SELECT = "SELECT * WHERE { ?s ?p ?o }"; | ||
private final static String ANOTHER_SAMPLE_SPARQL_SELECT = "SELECT ?s WHERE { ?s ?p ?o }"; | ||
|
||
@Before | ||
public void setUp() { | ||
cut = new SparqlSearchComponent(); | ||
request = mock(SolrQueryRequest.class); | ||
when(request.getParams()).thenReturn(params); | ||
} | ||
|
||
/** | ||
* Query string can be passed in request with the "q" parameter. | ||
*/ | ||
@Test | ||
public void queryStringIn_q_parameter() { | ||
params.add(CommonParams.Q, SAMPLE_SPARQL_SELECT); | ||
|
||
final String queryString = cut.queryString(request); | ||
assertEquals(SAMPLE_SPARQL_SELECT, queryString); | ||
} | ||
|
||
/** | ||
* Query string can be passed in request with the "query" parameter. | ||
*/ | ||
@Test | ||
public void queryStringIn_query_parameter() { | ||
params.add(CommonParams.QUERY, SAMPLE_SPARQL_SELECT); | ||
|
||
final String queryString = cut.queryString(request); | ||
assertEquals(SAMPLE_SPARQL_SELECT, queryString); | ||
} | ||
|
||
/** | ||
* If both "q" and "query" parameters have been specified, then "q" got a higher priority. | ||
*/ | ||
@Test | ||
public void queryAndQ() { | ||
params.add(CommonParams.QUERY, SAMPLE_SPARQL_SELECT); | ||
params.add(CommonParams.Q, ANOTHER_SAMPLE_SPARQL_SELECT); | ||
|
||
final String queryString = cut.queryString(request); | ||
assertEquals(ANOTHER_SAMPLE_SPARQL_SELECT, queryString); | ||
} | ||
|
||
/** | ||
* If the incoming request doesn't contain a query then an exception is thrown. | ||
*/ | ||
@Test | ||
public void nullQuery() { | ||
assertNull(request.getParams().get(CommonParams.Q)); | ||
assertNull(request.getParams().get(CommonParams.QUERY)); | ||
|
||
try { | ||
cut.queryString(request); | ||
} catch (final SolrException expected) { | ||
assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, expected.code()); | ||
} | ||
} | ||
} |