org.apache.solr.util

## Class TestHarness

- java.lang.Object
- - org.apache.solr.util.BaseTestHarness
  - - org.apache.solr.util.TestHarness

-     public class TestHarness
      extends BaseTestHarness

  This class provides a simple harness that may be useful when writing testcases.

  This class lives in the tests-framework source tree (and not in the test source tree), so that it will be included with even the most minimal solr distribution, in order to encourage plugin writers to create unit tests for their plugins.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `TestHarness.LocalRequestFactory` A Factory that generates LocalSolrQueryRequest objects using a specified set of default options.
    `static class` | `TestHarness.TestCoresLocator`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected org.apache.solr.core.CoreContainer` | `container`
    `String` | `coreName`
    `org.apache.solr.handler.UpdateRequestHandler` | `updater`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TestHarness(org.apache.solr.core.NodeConfig nodeConfig)`
    `TestHarness(org.apache.solr.core.NodeConfig config, org.apache.solr.core.CoresLocator coresLocator)` Create a TestHarness using a specific config
    `TestHarness(Path solrHome, String solrXml)` Create a TestHarness using a specific solr home directory and solr xml
    `TestHarness(org.apache.solr.core.SolrResourceLoader loader, String solrXml)` Create a TestHarness using a specific solr resource loader and solr xml
    `TestHarness(String dataDirectory, org.apache.solr.core.SolrConfig solrConfig, org.apache.solr.schema.IndexSchema indexSchema)`
    `TestHarness(String dataDirectory, org.apache.solr.core.SolrConfig solrConfig, String schemaFile)`
    `TestHarness(String coreName, String dataDir, org.apache.solr.core.SolrConfig solrConfig, org.apache.solr.schema.IndexSchema indexSchema)`
    `TestHarness(String coreName, String dataDirectory, org.apache.solr.core.SolrConfig solrConfig, String schemaFile)`
    `TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static org.apache.solr.core.NodeConfig` | `buildTestNodeConfig(org.apache.solr.core.SolrResourceLoader loader)`
    `void` | `close()` Shuts down and frees any resources
    `static org.apache.solr.core.SolrConfig` | `createConfig(Path solrHome, String confFile)` Creates a SolrConfig object for the default test core using `createConfig(Path,String,String)`
    `static org.apache.solr.core.SolrConfig` | `createConfig(Path solrHome, String coreName, String confFile)` Creates a SolrConfig object for the specified coreName assuming it follows the basic conventions of being a relative path in the solrHome dir.
    `org.apache.solr.core.SolrCore` | `getCore()` Gets a core that does not have its refcount incremented (i.e.
    `org.apache.solr.core.CoreContainer` | `getCoreContainer()`
    `org.apache.solr.core.SolrCore` | `getCoreInc()` Gets the core with its reference count incremented.
    `TestHarness.LocalRequestFactory` | `getRequestFactory(String qtype, int start, int limit)`
    `TestHarness.LocalRequestFactory` | `getRequestFactory(String qtype, int start, int limit, Map<String,String> args)`
    `TestHarness.LocalRequestFactory` | `getRequestFactory(String qtype, int start, int limit, String... args)` 0 and Even numbered args are keys, Odd numbered args are values.
    `String` | `query(org.apache.solr.request.SolrQueryRequest req)` Processes a "query" using a user constructed SolrQueryRequest
    `String` | `query(String handler, org.apache.solr.request.SolrQueryRequest req)` Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
    `org.apache.solr.response.SolrQueryResponse` | `queryAndResponse(String handler, org.apache.solr.request.SolrQueryRequest req)` It is the users responsibility to close the request object when done with it.
    `void` | `reload()` Reloads the core
    `String` | `update(String xml)` Processes an "update" (add, commit or optimize) and returns the response as a String.
    `String` | `validateQuery(org.apache.solr.request.SolrQueryRequest req, String... tests)` Validates a "query" response against an array of XPath test strings

    - ### Methods inherited from class org.apache.solr.util.BaseTestHarness

      `checkUpdateStatus, commit, deleteById, deleteByQuery, evaluateXPath, getXmlDocumentBuilder, getXpath, makeSimpleDoc, optimize, simpleTag, validateErrorUpdate, validateUpdate, validateXPath`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### coreName

          public String coreName

    - #### container

          protected volatile org.apache.solr.core.CoreContainer container

    - #### updater

          public org.apache.solr.handler.UpdateRequestHandler updater

  - ### Constructor Detail

    - #### TestHarness

          public TestHarness(String coreName,
                             String dataDirectory,
                             org.apache.solr.core.SolrConfig solrConfig,
                             String schemaFile)

      Parameters:
        `coreName` - to initialize
        `dataDirectory` - path for index data, will not be cleaned up
        `solrConfig` - solronfig instance
        `schemaFile` - schema filename

    - #### TestHarness

          public TestHarness(String dataDirectory,
                             org.apache.solr.core.SolrConfig solrConfig,
                             String schemaFile)

      Parameters:
        `dataDirectory` - path for index data, will not be cleaned up
        `solrConfig` - solronfig instance
        `schemaFile` - schema filename

    - #### TestHarness

          public TestHarness(String dataDirectory,
                             org.apache.solr.core.SolrConfig solrConfig,
                             org.apache.solr.schema.IndexSchema indexSchema)

      Parameters:
        `dataDirectory` - path for index data, will not be cleaned up
        `solrConfig` - solrconfig instance
        `indexSchema` - schema instance

    - #### TestHarness

          public TestHarness(String coreName,
                             String dataDir,
                             String solrConfig,
                             String indexSchema)

      Parameters:
        `coreName` - to initialize
        `dataDir` - path for index data, will not be cleaned up
        `solrConfig` - solrconfig resource name
        `indexSchema` - schema resource name

    - #### TestHarness

          public TestHarness(String coreName,
                             String dataDir,
                             org.apache.solr.core.SolrConfig solrConfig,
                             org.apache.solr.schema.IndexSchema indexSchema)

    - #### TestHarness

          public TestHarness(Path solrHome,
                             String solrXml)

      Create a TestHarness using a specific solr home directory and solr xml
      Parameters:
        `solrHome` - the solr home directory
        `solrXml` - the text of a solrxml

    - #### TestHarness

          public TestHarness(org.apache.solr.core.SolrResourceLoader loader,
                             String solrXml)

      Create a TestHarness using a specific solr resource loader and solr xml
      Parameters:
        `loader` - the SolrResourceLoader to use
        `solrXml` - the text of a solrxml

    - #### TestHarness

          public TestHarness(org.apache.solr.core.NodeConfig nodeConfig)

    - #### TestHarness

          public TestHarness(org.apache.solr.core.NodeConfig config,
                             org.apache.solr.core.CoresLocator coresLocator)

      Create a TestHarness using a specific config
      Parameters:
        `config` - the ConfigSolr to use

  - ### Method Detail

    - #### createConfig

          public static org.apache.solr.core.SolrConfig createConfig(Path solrHome,
                                                                     String coreName,
                                                                     String confFile)

      Creates a SolrConfig object for the specified coreName assuming it follows the basic conventions of being a relative path in the solrHome dir. (ie: `${solrHome}/${coreName}/conf/${confFile}`

    - #### createConfig

          public static org.apache.solr.core.SolrConfig createConfig(Path solrHome,
                                                                     String confFile)

      Creates a SolrConfig object for the default test core using `createConfig(Path,String,String)`

    - #### buildTestNodeConfig

          public static org.apache.solr.core.NodeConfig buildTestNodeConfig(org.apache.solr.core.SolrResourceLoader loader)

    - #### getCoreContainer

          public org.apache.solr.core.CoreContainer getCoreContainer()

    - #### getCore

          public org.apache.solr.core.SolrCore getCore()

      Gets a core that does not have its refcount incremented (i.e. there is no need to close when done). This is not MT safe in conjunction with reloads!

    - #### getCoreInc

          public org.apache.solr.core.SolrCore getCoreInc()

      Gets the core with its reference count incremented. You must call core.close() when done!

    - #### reload

          public void reload()
                      throws Exception

      Description copied from class: `BaseTestHarness`
      Reloads the core
      Specified by:
        `reload` in class `BaseTestHarness`
      Throws:
        `Exception`

    - #### update

          public String update(String xml)

      Processes an "update" (add, commit or optimize) and returns the response as a String.
      Specified by:
        `update` in class `BaseTestHarness`
      Parameters:
        `xml` - The XML of the update
      Returns:
        The XML response to the update

    - #### validateQuery

          public String validateQuery(org.apache.solr.request.SolrQueryRequest req,
                                      String... tests)
                               throws Exception

      Validates a "query" response against an array of XPath test strings
      Parameters:
        `req` - the Query to process
      Returns:
        null if all good, otherwise the first test that fails.
      Throws:
        `Exception` - any exception in the response.
        `IOException` - if there is a problem writing the XML
      See Also:
        `LocalSolrQueryRequest`

    - #### query

          public String query(org.apache.solr.request.SolrQueryRequest req)
                       throws Exception

      Processes a "query" using a user constructed SolrQueryRequest
      Parameters:
        `req` - the Query to process, will be closed.
      Returns:
        The XML response to the query
      Throws:
        `Exception` - any exception in the response.
        `IOException` - if there is a problem writing the XML
      See Also:
        `LocalSolrQueryRequest`

    - #### query

          public String query(String handler,
                              org.apache.solr.request.SolrQueryRequest req)
                       throws Exception

      Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
      Parameters:
        `handler` - the name of the request handler to process the request
        `req` - the Query to process, will be closed.
      Returns:
        The XML response to the query
      Throws:
        `Exception` - any exception in the response.
        `IOException` - if there is a problem writing the XML
      See Also:
        `LocalSolrQueryRequest`

    - #### queryAndResponse

          public org.apache.solr.response.SolrQueryResponse queryAndResponse(String handler,
                                                                             org.apache.solr.request.SolrQueryRequest req)
                                                                      throws Exception

      It is the users responsibility to close the request object when done with it. This method does not set/clear SolrRequestInfo
      Throws:
        `Exception`

    - #### close

          public void close()

      Shuts down and frees any resources

    - #### getRequestFactory

          public TestHarness.LocalRequestFactory getRequestFactory(String qtype,
                                                                   int start,
                                                                   int limit)

    - #### getRequestFactory

          public TestHarness.LocalRequestFactory getRequestFactory(String qtype,
                                                                   int start,
                                                                   int limit,
                                                                   String... args)

      0 and Even numbered args are keys, Odd numbered args are values.

    - #### getRequestFactory

          public TestHarness.LocalRequestFactory getRequestFactory(String qtype,
                                                                   int start,
                                                                   int limit,
                                                                   Map<String,String> args)

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.