SolrTestCaseJ4 (Solr 3.6.2 API)
Keywords: org.apache.solr.SolrTestCaseJ4 class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.solr
Class SolrTestCaseJ4

    java.lang.Object
      org.junit.Assert
          org.apache.lucene.util.LuceneTestCase
              org.apache.solr.SolrTestCaseJ4

Direct Known Subclasses:
  BaseDistributedSearchTestCase, SolrJettyTestBase

    public abstract class SolrTestCaseJ4

extends LuceneTestCase

A junit4 Solr test harness that extends LuceneTestCaseJ4. Unlike AbstractSolrTestCase, a new core is not created for each test method.

Nested Class Summary
`static class` | `SolrTestCaseJ4.Doc`
`static class` | `SolrTestCaseJ4.Fld`
`protected class` | `SolrTestCaseJ4.FldType`
`static class` | `SolrTestCaseJ4.FVal`
`static class` | `SolrTestCaseJ4.IRange`
`static class` | `SolrTestCaseJ4.IVals`
`static class` | `SolrTestCaseJ4.SVal`
`static class` | `SolrTestCaseJ4.Vals`
`static class` | `SolrTestCaseJ4.XmlDoc` Neccessary to make method signatures un-ambiguous

Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase
`LuceneTestCase.Nightly`

Field Summary
`protected static String` | `configString`
`protected static File` | `dataDir` The directory used to story the index managed by the TestHarness h
`protected static TestHarness` | `h` Harness initialized by initTestHarness.
`static org.slf4j.Logger` | `log` Initializes things your test might need Creates a dataDir in the "java.io.tmpdir" initializes the TestHarness h using this data directory, and getSchemaPath() initializes the LocalRequestFactory lrf using sensible defaults.
`protected static TestHarness.LocalRequestFactory` | `lrf` LocalRequestFactory initialized by initTestHarness using sensible defaults.
`static SolrTestCaseJ4.IRange` | `ONE_ONE`
`protected static String` | `schemaString`
`static org.junit.rules.TestRule` | `solrClassRules`
`protected static org.apache.solr.core.SolrConfig` | `solrConfig`
`org.junit.rules.TestRule` | `solrTestRules`
`static SolrTestCaseJ4.IRange` | `ZERO_ONE`
`static SolrTestCaseJ4.IRange` | `ZERO_TWO`

Fields inherited from class org.apache.lucene.util.LuceneTestCase
`classRules, random, RANDOM_MULTIPLIER, ruleChain, stores, TEMP_DIR, TEST_CLEAN_THREADS, TEST_DIRECTORY, TEST_ITER, TEST_ITER_MIN, TEST_LINE_DOCS_FILE, TEST_LOCALE, TEST_NIGHTLY, TEST_SEED, TEST_TIMEZONE, TEST_VERSION_CURRENT, testsFailed, VERBOSE`

Constructor Summary
`SolrTestCaseJ4()`

Method Summary
`static String` | `add(SolrTestCaseJ4.XmlDoc doc, String... args)` Generates an <add><doc>...
`static String` | `adoc(org.apache.solr.common.SolrInputDocument sdoc)` Generates a simple <add><doc>...
`static String` | `adoc(String... fieldsAndValues)` Generates a simple <add><doc>...
`static void` | `afterClassSolrTestCase()`
`static void` | `assertFailedU(String update)` Validates an update XML String failed
`static void` | `assertFailedU(String message, String update)` Validates an update XML String failed
`static void` | `assertJQ(org.apache.solr.request.SolrQueryRequest req, double delta, String... tests)` Validates a query matches some JSON test expressions and closes the query.
`static void` | `assertJQ(org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a query matches some JSON test expressions using the default double delta tollerance.
`static void` | `assertQ(org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a query matches some XPath test expressions and closes the query
`static void` | `assertQ(String message, org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a query matches some XPath test expressions and closes the query
`static void` | `assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, int code)` Makes sure a query throws a SolrException with the listed response code
`static void` | `assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code)`
`static void` | `assertU(String update)` Validates an update XML String is successful
`static void` | `assertU(String message, String update)` Validates an update XML String is successful
`static void` | `beforeClassSolrTestCase()`
`void` | `clearIndex()`
`static void` | `closeDirectories()`
`static String` | `commit(String... args)`
`static Comparator<SolrTestCaseJ4.Doc>` | `createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators)`
`static Comparator<SolrTestCaseJ4.Doc>` | `createComparator(String field, boolean asc, boolean sortMissingLast, boolean sortMissingFirst, boolean sortMissingAsZero)`
`static SolrTestCaseJ4.Doc` | `createDoc(List<SolrTestCaseJ4.FldType> descriptor)`
`static Comparator<SolrTestCaseJ4.Doc>` | `createSort(org.apache.solr.schema.IndexSchema schema, List<SolrTestCaseJ4.FldType> fieldTypes, String[] out)`
`static void` | `createTempDir()`
`static void` | `deleteCore()` Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set.
`static String` | `delI(String id)` Generates a <delete>...
`static String` | `delQ(String q)` Generates a <delete>...
`static SolrTestCaseJ4.XmlDoc` | `doc(String... fieldsAndValues)` Generates a simple <doc>...
`static void` | `endTrackingSearchers()`
`protected static String` | `getClassName()`
`static File` | `getFile(String name)` Gets a resource from the context classloader as `File`.
`static Throwable` | `getRootCause(Throwable t)`
`static String` | `getSchemaFile()` Subclasses must define this method to return the name of the schema.xml they wish to use.
`protected static String` | `getSimpleClassName()`
`static String` | `getSolrConfigFile()` Subclasses must define this method to return the name of the solrconfig.xml they wish to use.
`static void` | `ignoreException(String pattern)` Causes an exception matching the regex pattern to not be logged.
`Map<Comparable,SolrTestCaseJ4.Doc>` | `indexDocs(List<SolrTestCaseJ4.FldType> descriptor, Map<Comparable,SolrTestCaseJ4.Doc> model, int nDocs)`
`static void` | `initCore()`
`static void` | `initCore(String config, String schema)` Call initCore in @BeforeClass to instantiate a solr core in your test class.
`static void` | `initCore(String config, String schema, String solrHome)` Call initCore in @BeforeClass to instantiate a solr core in your test class.
`static String` | `optimize(String... args)`
`static org.apache.solr.common.params.ModifiableSolrParams` | `params(String... params)`
`void` | `postSetUp()` Subclasses that override setUp can optionally call this method to log the fact that their setUp process has ended.
`void` | `preTearDown()` Subclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started.
`static boolean` | `recurseDelete(File f)`
`static org.apache.solr.request.SolrQueryRequest` | `req(org.apache.solr.common.params.SolrParams params, String... moreParams)` Generates a SolrQueryRequest
`static org.apache.solr.request.SolrQueryRequest` | `req(String... q)` Generates a SolrQueryRequest using the LocalRequestFactory
`static org.apache.solr.request.SolrQueryRequest` | `req(String[] params, String... moreParams)` Generates a SolrQueryRequest using the LocalRequestFactory
`static void` | `resetExceptionIgnores()`
`void` | `setUp()`
`static void` | `startTrackingSearchers()`
`void` | `tearDown()`
`static String` | `TEST_HOME()`
`static String` | `toJSON(SolrTestCaseJ4.Doc doc)`
`static String` | `updateJ(String json, org.apache.solr.common.params.SolrParams args)` Send JSON update commands

Methods inherited from class org.apache.lucene.util.LuceneTestCase
`afterClassLuceneTestCaseJ4, alwaysIgnoredTestMethod, assertEquals, assertEquals, assertEquals, assertEquals, assertSaneFieldCaches, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, beforeClassLuceneTestCaseJ4, dumpArray, dumpIterator, getDataFile, getName, getTestClass, getTestLabel, isTestThread, localeForName, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newField, newField, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newSearcher, newSearcher, newTieredMergePolicy, newTieredMergePolicy, purgeFieldCache, randomDirectory, randomLocale, randomTimeZone, rarely, rarely, reportAdditionalFailureInfo, reportPartialFailureInfo, setMergeFactor, setUseCompoundFile, usually, usually`

Methods inherited from class org.junit.Assert
`assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### solrClassRules

    public static org.junit.rules.TestRule solrClassRules

### solrTestRules

    public org.junit.rules.TestRule solrTestRules

### configString

    protected static String configString

### schemaString

    protected static String schemaString

### solrConfig

    protected static org.apache.solr.core.SolrConfig solrConfig

### h

    protected static TestHarness h

  Harness initialized by initTestHarness.

  For use in test methods as needed.

### lrf

    protected static TestHarness.LocalRequestFactory lrf

  LocalRequestFactory initialized by initTestHarness using sensible defaults.

  For use in test methods as needed.

### dataDir

    protected static File dataDir

  The directory used to story the index managed by the TestHarness h

### log

    public static org.slf4j.Logger log

  Initializes things your test might need
  - Creates a dataDir in the "java.io.tmpdir"
  - initializes the TestHarness h using this data directory, and getSchemaPath()
  - initializes the LocalRequestFactory lrf using sensible defaults.

### ZERO_ONE

    public static final SolrTestCaseJ4.IRange ZERO_ONE

### ZERO_TWO

    public static final SolrTestCaseJ4.IRange ZERO_TWO

### ONE_ONE

    public static final SolrTestCaseJ4.IRange ONE_ONE

Constructor Detail

### SolrTestCaseJ4

    public SolrTestCaseJ4()

Method Detail

### beforeClassSolrTestCase

    public static void beforeClassSolrTestCase()
                                        throws Exception

  Throws:
    `Exception`

### afterClassSolrTestCase

    public static void afterClassSolrTestCase()
                                       throws Exception

  Throws:
    `Exception`

### closeDirectories

    public static void closeDirectories()
                                 throws Exception

  Throws:
    `Exception`

### setUp

    public void setUp()
               throws Exception

  Overrides:
    `setUp` in class `LuceneTestCase`
  Throws:
    `Exception`

### tearDown

    public void tearDown()
                  throws Exception

  Overrides:
    `tearDown` in class `LuceneTestCase`
  Throws:
    `Exception`

### initCore

    public static void initCore(String config,
                                String schema)
                         throws Exception

  Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be called for you via SolrTestCaseJ4 @AfterClass

  Throws:
    `Exception`

### initCore

    public static void initCore(String config,
                                String schema,
                                String solrHome)
                         throws Exception

  Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be called for you via SolrTestCaseJ4 @AfterClass

  Throws:
    `Exception`

### startTrackingSearchers

    public static void startTrackingSearchers()

### endTrackingSearchers

    public static void endTrackingSearchers()

### ignoreException

    public static void ignoreException(String pattern)

  Causes an exception matching the regex pattern to not be logged.

### resetExceptionIgnores

    public static void resetExceptionIgnores()

### getClassName

    protected static String getClassName()

### getSimpleClassName

    protected static String getSimpleClassName()

### getSchemaFile

    public static String getSchemaFile()

  Subclasses must define this method to return the name of the schema.xml they wish to use.

### getSolrConfigFile

    public static String getSolrConfigFile()

  Subclasses must define this method to return the name of the solrconfig.xml they wish to use.

### createTempDir

    public static void createTempDir()

### initCore

    public static void initCore()
                         throws Exception

  Throws:
    `Exception`

### postSetUp

    public void postSetUp()

  Subclasses that override setUp can optionally call this method to log the fact that their setUp process has ended.

### preTearDown

    public void preTearDown()

  Subclasses that override tearDown can optionally call this method to log the fact that the tearDown process has started. This is necessary since subclasses will want to call super.tearDown() at the *end* of their tearDown method.

### deleteCore

    public static void deleteCore()
                           throws Exception

  Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set.

  Throws:
    `Exception`

### assertU

    public static void assertU(String update)

  Validates an update XML String is successful

### assertU

    public static void assertU(String message,
                               String update)

  Validates an update XML String is successful

### assertFailedU

    public static void assertFailedU(String update)

  Validates an update XML String failed

### assertFailedU

    public static void assertFailedU(String message,
                                     String update)

  Validates an update XML String failed

### assertQ

    public static void assertQ(org.apache.solr.request.SolrQueryRequest req,
                               String... tests)

  Validates a query matches some XPath test expressions and closes the query

### assertQ

    public static void assertQ(String message,
                               org.apache.solr.request.SolrQueryRequest req,
                               String... tests)

  Validates a query matches some XPath test expressions and closes the query

### assertJQ

    public static void assertJQ(org.apache.solr.request.SolrQueryRequest req,
                                String... tests)
                         throws Exception

  Validates a query matches some JSON test expressions using the default double delta tollerance.

  Throws:
    `Exception`
  See Also:
    `JSONTestUtil.DEFAULT_DELTA`, `assertJQ(SolrQueryRequest,double,String...)`

### assertJQ

    public static void assertJQ(org.apache.solr.request.SolrQueryRequest req,
                                double delta,
                                String... tests)
                         throws Exception

  Validates a query matches some JSON test expressions and closes the query. The text expression is of the form path:JSON. To facilitate easy embedding in Java strings, the JSON can have double quotes replaced with single quotes.

  Please use this with care: this makes it easy to match complete structures, but doing so can result in fragile tests if you are matching more than what you want to test.

  Parameters:
    `req` - Solr request to execute
    `delta` - tollerance allowed in comparing float/double values
    `tests` - JSON path expression + '==' + expected value
  Throws:
    `Exception`

### assertQEx

    public static void assertQEx(String message,
                                 org.apache.solr.request.SolrQueryRequest req,
                                 int code)

  Makes sure a query throws a SolrException with the listed response code

### assertQEx

    public static void assertQEx(String message,
                                 org.apache.solr.request.SolrQueryRequest req,
                                 org.apache.solr.common.SolrException.ErrorCode code)

### optimize

    public static String optimize(String... args)

  See Also:
    `TestHarness.optimize(java.lang.String...)`

### commit

    public static String commit(String... args)

  See Also:
    `TestHarness.commit(java.lang.String...)`

### adoc

    public static String adoc(String... fieldsAndValues)

  Generates a simple <add><doc>... XML String with no options

  Parameters:
    `fieldsAndValues` - 0th and Even numbered args are fields names odds are field values.
  See Also:
    `add(org.apache.solr.SolrTestCaseJ4.XmlDoc, java.lang.String...)`, `doc(java.lang.String...)`

### adoc

    public static String adoc(org.apache.solr.common.SolrInputDocument sdoc)

  Generates a simple <add><doc>... XML String with no options

### add

    public static String add(SolrTestCaseJ4.XmlDoc doc,
                             String... args)

  Generates an <add><doc>... XML String with options on the add.

  Parameters:
    `doc` - the Document to add
    `args` - 0th and Even numbered args are param names, Odds are param values.
  See Also:
    `add(org.apache.solr.SolrTestCaseJ4.XmlDoc, java.lang.String...)`, `doc(java.lang.String...)`

### delI

    public static String delI(String id)

  Generates a <delete>... XML string for an ID

  See Also:
    `TestHarness.deleteById(java.lang.String, java.lang.String...)`

### delQ

    public static String delQ(String q)

  Generates a <delete>... XML string for an query

  See Also:
    `TestHarness.deleteByQuery(java.lang.String, java.lang.String...)`

### doc

    public static SolrTestCaseJ4.XmlDoc doc(String... fieldsAndValues)

  Generates a simple <doc>... XML String with no options

  Parameters:
    `fieldsAndValues` - 0th and Even numbered args are fields names, Odds are field values.
  See Also:
    `TestHarness.makeSimpleDoc(java.lang.String...)`

### params

    public static org.apache.solr.common.params.ModifiableSolrParams params(String... params)

### req

    public static org.apache.solr.request.SolrQueryRequest req(String... q)

  Generates a SolrQueryRequest using the LocalRequestFactory

  See Also:
    `lrf`

### req

    public static org.apache.solr.request.SolrQueryRequest req(String[] params,
                                                               String... moreParams)

  Generates a SolrQueryRequest using the LocalRequestFactory

  See Also:
    `lrf`

### req

    public static org.apache.solr.request.SolrQueryRequest req(org.apache.solr.common.params.SolrParams params,
                                                               String... moreParams)

  Generates a SolrQueryRequest

### recurseDelete

    public static boolean recurseDelete(File f)

### clearIndex

    public void clearIndex()

### updateJ

    public static String updateJ(String json,
                                 org.apache.solr.common.params.SolrParams args)
                          throws Exception

  Send JSON update commands

  Throws:
    `Exception`

### indexDocs

    public Map<Comparable,SolrTestCaseJ4.Doc> indexDocs(List<SolrTestCaseJ4.FldType> descriptor,
                                                        Map<Comparable,SolrTestCaseJ4.Doc> model,
                                                        int nDocs)
                                                 throws Exception

  Throws:
    `Exception`

### createDoc

    public static SolrTestCaseJ4.Doc createDoc(List<SolrTestCaseJ4.FldType> descriptor)

### createSort

    public static Comparator<SolrTestCaseJ4.Doc> createSort(org.apache.solr.schema.IndexSchema schema,
                                                            List<SolrTestCaseJ4.FldType> fieldTypes,
                                                            String[] out)

### createComparator

    public static Comparator<SolrTestCaseJ4.Doc> createComparator(String field,
                                                                  boolean asc,
                                                                  boolean sortMissingLast,
                                                                  boolean sortMissingFirst,
                                                                  boolean sortMissingAsZero)

### createComparator

    public static Comparator<SolrTestCaseJ4.Doc> createComparator(List<Comparator<SolrTestCaseJ4.Doc>> comparators)

### toJSON

    public static String toJSON(SolrTestCaseJ4.Doc doc)

### getFile

    public static File getFile(String name)

  Gets a resource from the context classloader as `File`. This method should only be used, if a real file is needed. To get a stream, code should prefer `Class.getResourceAsStream(java.lang.String)` using `this.getClass()`.

### TEST_HOME

    public static String TEST_HOME()

### getRootCause

    public static Throwable getRootCause(Throwable t)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD