org.apache.solr.util

## Class RestTestHarness

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

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class RestTestHarness
      extends BaseTestHarness
      implements Closeable

  Facilitates testing Solr's REST API via a provided embedded Jetty

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RestTestHarness(RESTfulServerProvider serverProvider)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `adminQuery(String request)`
    `String` | `checkAdminResponseStatus(String xml, String code)`
    `String` | `checkResponseStatus(String xml, String code)`
    `void` | `close()`
    `String` | `delete(String request)` Processes a DELETE request using a URL path (with no context path) + optional query params, e.g.
    `String` | `getAdminURL()`
    `String` | `getBaseURL()`
    `String` | `post(String request, String content)` Processes a POST request using a URL path (with no context path) + optional query params, e.g.
    `String` | `put(String request, String content)` Processes a PUT request using a URL path (with no context path) + optional query params, e.g.
    `String` | `query(String request)` Processes a "query" using a URL path (with no context path) + optional query params, e.g.
    `void` | `reload()` Reloads the first core listed in the response to the core admin handler STATUS command
    `String` | `update(String xml)` Processes an "update" (add, commit or optimize) and returns the response as a String.
    `String` | `validatePut(String request, String content, String... tests)` Validates an XML PUT response against an array of XPath test strings
    `String` | `validateQuery(String request, String... tests)` Validates an XML "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`

- - ### Constructor Detail

    - #### RestTestHarness

          public RestTestHarness(RESTfulServerProvider serverProvider)

  - ### Method Detail

    - #### getBaseURL

          public String getBaseURL()

    - #### getAdminURL

          public String getAdminURL()

    - #### validateQuery

          public String validateQuery(String request,
                                      String... tests)
                               throws Exception

      Validates an XML "query" response against an array of XPath test strings
      Parameters:
        `request` - 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

    - #### validatePut

          public String validatePut(String request,
                                    String content,
                                    String... tests)
                             throws Exception

      Validates an XML PUT response against an array of XPath test strings
      Parameters:
        `request` - the PUT request to process
        `content` - the content to send with the PUT request
        `tests` - the validating XPath tests
      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

    - #### query

          public String query(String request)
                       throws Exception

      Processes a "query" using a URL path (with no context path) + optional query params, e.g. "/schema/fields?indent=on"
      Parameters:
        `request` - the URL path and optional query params
      Returns:
        The response to the query
      Throws:
        `Exception` - any exception in the response.

    - #### adminQuery

          public String adminQuery(String request)
                            throws Exception

      Throws:
        `Exception`

    - #### put

          public String put(String request,
                            String content)
                     throws IOException

      Processes a PUT request using a URL path (with no context path) + optional query params, e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
      Parameters:
        `request` - The URL path and optional query params
        `content` - The content to include with the PUT request
      Returns:
        The response to the PUT request
      Throws:
        `IOException`

    - #### delete

          public String delete(String request)
                        throws IOException

      Processes a DELETE request using a URL path (with no context path) + optional query params, e.g. "/schema/analysis/protwords/english", and returns the response content.
      Parameters:
        `request` - the URL path and optional query params
      Returns:
        The response to the DELETE request
      Throws:
        `IOException`

    - #### post

          public String post(String request,
                             String content)
                      throws IOException

      Processes a POST request using a URL path (with no context path) + optional query params, e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
      Parameters:
        `request` - The URL path and optional query params
        `content` - The content to include with the POST request
      Returns:
        The response to the POST request
      Throws:
        `IOException`

    - #### checkResponseStatus

          public String checkResponseStatus(String xml,
                                            String code)
                                     throws Exception

      Throws:
        `Exception`

    - #### checkAdminResponseStatus

          public String checkAdminResponseStatus(String xml,
                                                 String code)
                                          throws Exception

      Throws:
        `Exception`

    - #### reload

          public void reload()
                      throws Exception

      Reloads the first core listed in the response to the core admin handler STATUS command
      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

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

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