-
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 ] Sparql11UpdateRdfDataLoader (unit) test case
- Loading branch information
agazzarini
committed
Mar 23, 2015
1 parent
996a7fd
commit 539c081
Showing
3 changed files
with
96 additions
and
4 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
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
85 changes: 85 additions & 0 deletions
85
.../test/java/org/gazzax/labs/solrdf/handler/update/Sparql11UpdateRdfDataLoaderTestCase.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,85 @@ | ||
package org.gazzax.labs.solrdf.handler.update; | ||
|
||
import static org.gazzax.labs.solrdf.TestUtility.randomString; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.solr.common.SolrException; | ||
import org.apache.solr.common.SolrException.ErrorCode; | ||
import org.apache.solr.common.params.CommonParams; | ||
import org.apache.solr.common.params.ModifiableSolrParams; | ||
import org.apache.solr.common.util.ContentStream; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
import org.apache.solr.update.processor.UpdateRequestProcessor; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.hp.hpl.jena.query.QueryParseException; | ||
|
||
/** | ||
* Test case for {@link Sparql11UpdateRdfDataLoader}. | ||
* | ||
* @author Andrea Gazzarini | ||
* @since 1.0 | ||
*/ | ||
public class Sparql11UpdateRdfDataLoaderTestCase { | ||
private Sparql11UpdateRdfDataLoader cut; | ||
private SolrQueryRequest request; | ||
private SolrQueryResponse response; | ||
private ContentStream stream; | ||
private UpdateRequestProcessor processor; | ||
private ModifiableSolrParams parameters; | ||
|
||
@Before | ||
public void setUp() { | ||
cut = new Sparql11UpdateRdfDataLoader(); | ||
request = mock(SolrQueryRequest.class); | ||
response = mock(SolrQueryResponse.class); | ||
parameters = new ModifiableSolrParams(); | ||
stream = mock(ContentStream.class); | ||
processor = mock(UpdateRequestProcessor.class); | ||
|
||
when(request.getParams()).thenReturn(parameters); | ||
} | ||
|
||
/** | ||
* In case of a null query a {@link QueryParseException} must be raised. | ||
*/ | ||
@Test | ||
public void nullOrEmptyQuery() { | ||
final String [] invalidQueries = {"", " "}; | ||
for (final String invalidQuery : invalidQueries) { | ||
parameters.set(CommonParams.Q, invalidQuery); | ||
try { | ||
cut.load(request, response, stream, processor); | ||
fail(); | ||
} catch (final Exception expected) { | ||
assertTrue(expected instanceof SolrException); | ||
assertEquals(ErrorCode.BAD_REQUEST.code, ((SolrException)expected).code()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* In case of an invalid query a {@link QueryParseException} must be raised. | ||
*/ | ||
@Test | ||
public void invalidQuery() { | ||
final String [] invalidQueries = {"BLABALBALABLA", randomString()}; | ||
|
||
for (final String invalidQuery : invalidQueries) { | ||
parameters.set(CommonParams.Q, invalidQuery); | ||
try { | ||
cut.load(request, response, stream, processor); | ||
fail(); | ||
} catch (final Exception expected) { | ||
assertTrue(expected instanceof QueryParseException); | ||
} | ||
} | ||
} | ||
} |