convert some more tests to junit4

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@965330 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-07-19 00:06:18 +00:00
parent 1f10f8ba7f
commit 7912d72cfe
8 changed files with 129 additions and 62 deletions

View File

@ -16,7 +16,7 @@ package org.apache.solr.handler;
* limitations under the License.
*/
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.common.util.ContentStream;
@ -26,6 +26,11 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.handler.extraction.ExtractingParams;
import org.apache.solr.handler.extraction.ExtractingRequestHandler;
import org.apache.solr.handler.extraction.ExtractingDocumentLoader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.List;
import java.util.ArrayList;
@ -36,18 +41,20 @@ import java.io.File;
*
*
**/
public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
@Override
public String getSchemaFile() {
return "schema.xml";
public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
@Before
public void setUp() throws Exception {
super.setUp();
clearIndex();
assertU(commit());
}
@Test
public void testExtraction() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -134,6 +141,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
}
@Test
public void testDefaultField() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -177,7 +185,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
assertQ(req("+id:simple2 +t_href:[* TO *]"), "//*[@numFound='1']");
}
@Test
public void testLiterals() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -231,7 +239,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
}
@Test
public void testPlainTextSpecifyingMimeType() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -250,6 +258,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
assertQ(req("extractedContent:Apache"), "//*[@numFound='1']");
}
@Test
public void testPlainTextSpecifyingResourceName() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -271,7 +280,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
// Note: If you load a plain text file specifying neither MIME type nor filename, extraction will silently fail. This is because Tika's
// automatic MIME type detection will fail, and it will default to using an empty-string-returning default parser
@Test
public void testExtractOnly() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -308,6 +317,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
}
@Test
public void testXPath() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null);
@ -323,6 +333,7 @@ public class ExtractingRequestHandlerTest extends AbstractSolrTestCase {
}
/** test arabic PDF extraction is functional */
@Test
public void testArabicPDF() throws Exception {
ExtractingRequestHandler handler = (ExtractingRequestHandler)
h.getCore().getRequestHandler("/update/extract");

View File

@ -17,8 +17,10 @@
package org.apache.solr.handler;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.util.AbstractSolrTestCase;
import static org.junit.Assert.*;
/**
* A base class for all analysis request handler tests.
@ -26,7 +28,7 @@ import org.apache.solr.util.AbstractSolrTestCase;
* @version $Id$
* @since solr 1.4
*/
public abstract class AnalysisRequestHandlerTestBase extends AbstractSolrTestCase {
public abstract class AnalysisRequestHandlerTestBase extends SolrTestCaseJ4 {
protected void assertToken(NamedList token, TokenInfo info) {
assertEquals(info.getText(), token.get("text"));

View File

@ -26,6 +26,11 @@ import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@ -40,17 +45,13 @@ public class DocumentAnalysisRequestHandlerTest extends AnalysisRequestHandlerTe
private DocumentAnalysisRequestHandler handler;
@Override
public String getSchemaFile() {
return "schema.xml";
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
handler = new DocumentAnalysisRequestHandler();
@ -60,6 +61,7 @@ public class DocumentAnalysisRequestHandlerTest extends AnalysisRequestHandlerTe
/**
* Tests the {@link DocumentAnalysisRequestHandler#resolveAnalysisRequest(org.apache.solr.request.SolrQueryRequest)}
*/
@Test
public void testResolveAnalysisRequest() throws Exception {
String docsInput =
@ -108,6 +110,7 @@ public class DocumentAnalysisRequestHandlerTest extends AnalysisRequestHandlerTe
* Tests the {@link DocumentAnalysisRequestHandler#handleAnalysisRequest(org.apache.solr.client.solrj.request.DocumentAnalysisRequest,
* org.apache.solr.schema.IndexSchema)}
*/
@Test
public void testHandleAnalysisRequest() throws Exception {
SolrInputDocument document = new SolrInputDocument();

View File

@ -25,6 +25,11 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.client.solrj.request.FieldAnalysisRequest;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.List;
@ -39,24 +44,21 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB
private FieldAnalysisRequestHandler handler;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
handler = new FieldAnalysisRequestHandler();
}
@Override
public String getSchemaFile() {
return "schema.xml";
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
}
/**
* Tests the {@link FieldAnalysisRequestHandler#resolveAnalysisRequest(org.apache.solr.request.SolrQueryRequest)}
*/
@Test
public void testResolveAnalysisRequest() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.add(AnalysisParams.FIELD_NAME, "text,nametext");
@ -101,6 +103,7 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB
* Tests the {@link FieldAnalysisRequestHandler#handleAnalysisRequest(org.apache.solr.client.solrj.request.FieldAnalysisRequest,
* org.apache.solr.schema.IndexSchema)}
*/
@Test
public void testHandleAnalysisRequest() throws Exception {
FieldAnalysisRequest request = new FieldAnalysisRequest();
@ -293,6 +296,7 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB
}
@Test
public void testCharFilterAnalysis() throws Exception {
FieldAnalysisRequest request = new FieldAnalysisRequest();

View File

@ -16,30 +16,33 @@
*/
package org.apache.solr.search;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.response.SolrQueryResponse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.*;
import junit.framework.TestCase;
public class TestRangeQuery extends AbstractSolrTestCase {
public String getSchemaFile() { return "schema11.xml"; }
public String getSolrConfigFile() { return "solrconfig.xml"; }
public String getCoreName() { return "basic"; }
public class TestRangeQuery extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema11.xml");
}
@Before
public void setUp() throws Exception {
// if you override setUp or tearDown, you better call
// the super classes version
super.setUp();
}
public void tearDown() throws Exception {
// if you override setUp or tearDown, you better call
// the super classes version
super.tearDown();
clearIndex();
assertU(commit());
}
Random r = new Random(1);
@ -69,7 +72,7 @@ public class TestRangeQuery extends AbstractSolrTestCase {
}
}
@Test
public void testRangeQueries() throws Exception {
// ensure that we aren't losing precision on any fields in addition to testing other non-numeric fields
// that aren't tested in testRandomRangeQueries()
@ -197,6 +200,7 @@ public class TestRangeQuery extends AbstractSolrTestCase {
}
@Test
public void testRandomRangeQueries() throws Exception {
String handler="";
final String[] fields = {"foo_s","foo_i","foo_l","foo_f","foo_d" // SortableIntField, etc

View File

@ -24,6 +24,7 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MapSolrParams;
@ -31,18 +32,31 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.SolrIndexReader;
import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
*
*/
public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
public class DirectUpdateHandlerTest extends SolrTestCaseJ4 {
public String getSchemaFile() { return "schema12.xml"; }
public String getSolrConfigFile() { return "solrconfig.xml"; }
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema12.xml");
}
@Before
public void setUp() throws Exception {
super.setUp();
clearIndex();
assertU(commit());
}
@Test
public void testRequireUniqueKey() throws Exception
{
SolrCore core = h.getCore();
@ -83,6 +97,7 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
catch( SolrException ex ) { } // expected
}
@Test
public void testUncommit() throws Exception {
addSimpleDoc("A");
@ -96,6 +111,7 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
);
}
@Test
public void testAddCommit() throws Exception {
addSimpleDoc("A");
@ -117,6 +133,7 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
);
}
@Test
public void testDeleteCommit() throws Exception {
addSimpleDoc("A");
addSimpleDoc("B");
@ -159,7 +176,12 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
);
}
@Test
public void testAddRollback() throws Exception {
// re-init the core
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
addSimpleDoc("A");
// commit "A"
@ -209,7 +231,12 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
);
}
@Test
public void testDeleteRollback() throws Exception {
// re-init the core
deleteCore();
initCore("solrconfig.xml", "schema12.xml");
addSimpleDoc("A");
addSimpleDoc("B");
@ -276,6 +303,7 @@ public class DirectUpdateHandlerTest extends AbstractSolrTestCase {
);
}
@Test
public void testExpungeDeletes() throws Exception {
assertU(adoc("id","1"));
assertU(adoc("id","2"));

View File

@ -18,22 +18,28 @@
package org.apache.solr.update;
import org.apache.lucene.document.Document;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.SolrCore;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.schema.FieldType;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
*
*/
public class DocumentBuilderTest extends AbstractSolrTestCase {
public class DocumentBuilderTest extends SolrTestCaseJ4 {
@Override public String getSchemaFile() { return "schema.xml"; }
@Override public String getSolrConfigFile() { return "solrconfig.xml"; }
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
}
@Test
public void testBuildDocument() throws Exception
{
SolrCore core = h.getCore();
@ -50,6 +56,7 @@ public class DocumentBuilderTest extends AbstractSolrTestCase {
}
}
@Test
public void testNullField()
{
SolrCore core = h.getCore();
@ -61,6 +68,7 @@ public class DocumentBuilderTest extends AbstractSolrTestCase {
assertNull( out.get( "name" ) );
}
@Test
public void testMultiField() throws Exception {
SolrCore core = h.getCore();

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.MultiMapSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.UpdateParams;
@ -31,32 +32,35 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.XmlUpdateRequestHandler;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.AbstractSolrTestCase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
*/
public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase {
public class SignatureUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
/** modified by tests as needed */
private String processor = "dedupe";
@Override
public String getSchemaFile() {
return "schema12.xml";
}
@Override
public String getSolrConfigFile() {
return "solrconfig.xml";
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema12.xml");
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
clearIndex();
assertU(commit());
processor = "dedupe"; // set the default that most tests expect
}
@Test
public void testDupeDetection() throws Exception {
SolrCore core = h.getCore();
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(
@ -103,6 +107,7 @@ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase {
factory.setEnabled(false);
}
@Test
public void testMultiThreaded() throws Exception {
UpdateRequestProcessorChain chained = h.getCore().getUpdateProcessingChain(
"dedupe");
@ -182,6 +187,7 @@ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase {
/**
* a non-indexed signatureField is fine as long as overwriteDupes==false
*/
@Test
public void testNonIndexedSignatureField() throws Exception {
SolrCore core = h.getCore();
@ -197,6 +203,7 @@ public class SignatureUpdateProcessorFactoryTest extends AbstractSolrTestCase {
2l, core.getSearcher().get().getReader().numDocs());
}
@Test
public void testFailNonIndexedSigWithOverwriteDupes() throws Exception {
SolrCore core = h.getCore();
SignatureUpdateProcessorFactory f = new SignatureUpdateProcessorFactory();