AbstractSolrTestCase (Solr 3.6.2 API)
Keywords: org.apache.solr.util.AbstractSolrTestCase 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.util
Class AbstractSolrTestCase

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

    public abstract class AbstractSolrTestCase

extends LuceneTestCase

An Abstract base class that makes writing Solr JUnit tests "easier"

Test classes that subclass this need only specify the path to the schema.xml file (:TODO: the solrconfig.xml as well) and write some testMethods. This class takes care of creating/destroying the index, and provides several assert methods to assist you.

See Also:
  `setUp()`, `tearDown()`

Nested Class Summary
`static class` | `AbstractSolrTestCase.Doc` Neccessary to make method signatures un-ambiguous

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

Field Summary
`protected File` | `dataDir` The directory used to story the index managed by the TestHarness h
`protected 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 TestHarness.LocalRequestFactory` | `lrf` LocalRequestFactory initialized by initTestHarness using sensible defaults.
`static org.junit.rules.TestRule` | `solrClassRules`
`protected org.apache.solr.core.SolrConfig` | `solrConfig`
`org.junit.rules.TestRule` | `solrTestRules`

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
`AbstractSolrTestCase()`

Method Summary
`String` | `add(AbstractSolrTestCase.Doc doc, String... args)` Generates an <add><doc>...
`String` | `adoc(int commitWithin, String... fieldsAndValues)` Generates a simple <add><doc>...
`String` | `adoc(org.apache.solr.common.SolrInputDocument sdoc)` Generates a simple <add><doc>...
`String` | `adoc(String... fieldsAndValues)` Generates a simple <add><doc>...
`static void` | `afterClassAbstractSolrTestCase()`
`void` | `assertFailedU(String update)` Validates an update XML String failed
`void` | `assertFailedU(String message, String update)` Validates an update XML String failed
`void` | `assertQ(org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a query matches some XPath test expressions and closes the query
`void` | `assertQ(String message, org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a query matches some XPath test expressions and closes the query
`void` | `assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, int code)` Makes sure a query throws a SolrException with the listed response code
`void` | `assertQEx(String message, org.apache.solr.request.SolrQueryRequest req, org.apache.solr.common.SolrException.ErrorCode code)`
`void` | `assertU(String update)` Validates an update XML String is successful
`void` | `assertU(String message, String update)` Validates an update XML String is successful
`static void` | `beforeClassAbstractSolrTestCase()`
`String` | `commit(String... args)`
`String` | `delI(String id, String... args)` Generates a <delete>...
`String` | `delQ(String q, String... args)` Generates a <delete>...
`AbstractSolrTestCase.Doc` | `doc(String... fieldsAndValues)` Generates a simple <doc>...
`static File` | `getFile(String name)`
`abstract String` | `getSchemaFile()` Subclasses must define this method to return the name of the schema.xml they wish to use.
`abstract String` | `getSolrConfigFile()` Subclasses must define this method to return the name of the solrconfig.xml they wish to use.
`String` | `getSolrHome()` Subclasses can override this to change a test's solr home (default is in test-files)
`static void` | `ignoreException(String pattern)` Causes an exception matching the regex pattern to not be logged.
`String` | `optimize(String... args)`
`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)`
`org.apache.solr.request.SolrQueryRequest` | `req(String... q)` Generates a SolrQueryRequest using the LocalRequestFactory
`org.apache.solr.request.SolrQueryRequest` | `req(String[] params, String... moreParams)` Generates a SolrQueryRequest using the LocalRequestFactory
`static void` | `resetExceptionIgnores()`
`void` | `setUp()`
`void` | `tearDown()` Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the system property "solr.test.leavedatadir" is set.

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

### solrConfig

    protected org.apache.solr.core.SolrConfig solrConfig

### h

    protected TestHarness h

  Harness initialized by initTestHarness.

  For use in test methods as needed.

### lrf

    protected TestHarness.LocalRequestFactory lrf

  LocalRequestFactory initialized by initTestHarness using sensible defaults.

  For use in test methods as needed.

### solrClassRules

    public static org.junit.rules.TestRule solrClassRules

### solrTestRules

    public org.junit.rules.TestRule solrTestRules

### dataDir

    protected 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.

Constructor Detail

### AbstractSolrTestCase

    public AbstractSolrTestCase()

Method Detail

### getSchemaFile

    public abstract String getSchemaFile()

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

### getSolrConfigFile

    public abstract String getSolrConfigFile()

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

### getSolrHome

    public String getSolrHome()

  Subclasses can override this to change a test's solr home (default is in test-files)

### beforeClassAbstractSolrTestCase

    public static void beforeClassAbstractSolrTestCase()
                                                throws Exception

  Throws:
    `Exception`

### afterClassAbstractSolrTestCase

    public static void afterClassAbstractSolrTestCase()
                                               throws Exception

  Throws:
    `Exception`

### setUp

    public void setUp()
               throws Exception

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

### ignoreException

    public static void ignoreException(String pattern)

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

### resetExceptionIgnores

    public static void resetExceptionIgnores()

### 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.

### tearDown

    public void tearDown()
                  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.

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

### assertU

    public void assertU(String update)

  Validates an update XML String is successful

### assertU

    public void assertU(String message,
                        String update)

  Validates an update XML String is successful

### assertFailedU

    public void assertFailedU(String update)

  Validates an update XML String failed

### assertFailedU

    public void assertFailedU(String message,
                              String update)

  Validates an update XML String failed

### assertQ

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

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

### assertQ

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

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

### assertQEx

    public 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 void assertQEx(String message,
                          org.apache.solr.request.SolrQueryRequest req,
                          org.apache.solr.common.SolrException.ErrorCode code)

### optimize

    public String optimize(String... args)

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

### commit

    public String commit(String... args)

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

### adoc

    public 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.util.AbstractSolrTestCase.Doc, java.lang.String...)`, `doc(java.lang.String...)`

### adoc

    public String adoc(int commitWithin,
                       String... fieldsAndValues)

  Generates a simple <add><doc>... XML String with the commitWithin attribute.

  Parameters:
    `commitWithin` - the value of the commitWithin attribute
    `fieldsAndValues` - 0th and Even numbered args are fields names odds are field values.
  See Also:
    `add(org.apache.solr.util.AbstractSolrTestCase.Doc, java.lang.String...)`, `doc(java.lang.String...)`

### adoc

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

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

### add

    public String add(AbstractSolrTestCase.Doc 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.util.AbstractSolrTestCase.Doc, java.lang.String...)`, `doc(java.lang.String...)`

### delI

    public String delI(String id,
                       String... args)

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

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

### delQ

    public String delQ(String q,
                       String... args)

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

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

### doc

    public AbstractSolrTestCase.Doc 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...)`

### req

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

  Generates a SolrQueryRequest using the LocalRequestFactory

  See Also:
    `lrf`

### req

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

  Generates a SolrQueryRequest using the LocalRequestFactory

  See Also:
    `lrf`

### recurseDelete

    public static boolean recurseDelete(File f)

### getFile

    public static File getFile(String name)
                        throws IOException

  Throws:
    `IOException`
  See Also:
    `SolrTestCaseJ4.getFile(java.lang.String)`

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