Class RestTestBase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase

public abstract class RestTestBase extends SolrTestCaseJ4
Test base class incorporating a SolrJettyTestRule and RestTestHarness.
  • Field Details

  • Constructor Details

    • RestTestBase

      public RestTestBase()
  • Method Details

    • cleanUpHarness

      public static void cleanUpHarness()
    • createJettyAndHarness

      public static void createJettyAndHarness(Path solrHome, String configFile, String schemaFile) throws Exception
      Starts Solr/Jetty and creates a core "collection1. The coreRootDirectory is set to a temp dir.
      Parameters:
      solrHome - The solrHome; read-only. Also the configSetBaseDir having "collection1".
      configFile - core: defaults to solrconfig.xml
      schemaFile - core: defaults to schema.xml
      Throws:
      Exception
    • getJetty

      protected static JettySolrRunner getJetty()
    • restartJetty

      protected static void restartJetty() throws Exception
      Restarts Jetty and recreates the RestTestHarness with a new HttpClient. Use this instead of calling getJetty().stop()/start() directly.
      Throws:
      Exception
    • getBaseUrl

      protected static String getBaseUrl()
      URL to Solr
    • getCoreUrl

      protected static String getCoreUrl()
      URL to the core
    • getSolrClient

      protected static org.apache.solr.client.solrj.SolrClient getSolrClient()
    • 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
    • checkUpdateU

      public static void checkUpdateU(String update, String... tests)
    • assertQ

      public static void assertQ(String request, String... tests)
      Validates a query matches some XPath test expressions
      Parameters:
      request - a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
    • JQ

      public static String JQ(String request) throws IOException
      Makes a query request and returns the JSON string response
      Parameters:
      request - a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
      Throws:
      IOException
    • assertJQ

      public static void assertJQ(String request, String... tests) throws Exception
      Validates a query matches some JSON test expressions using the default double delta tolerance.
      Throws:
      Exception
      See Also:
    • assertJQ

      public static void assertJQ(String request, double delta, String... tests) throws IOException
      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:
      request - a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
      delta - tolerance allowed in comparing float/double values
      tests - JSON path expression + '==' + expected value
      Throws:
      IOException
    • assertJPut

      public static void assertJPut(String request, String content, String... tests) throws IOException
      Validates the response from a PUT request matches some JSON test expressions
      Throws:
      IOException
      See Also:
    • assertJPut

      public static void assertJPut(String request, String content, double delta, String... tests) throws IOException
      Validates the response from a PUT request 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:
      request - a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
      content - The content to include with the PUT request
      delta - tolerance allowed in comparing float/double values
      tests - JSON path expression + '==' + expected value
      Throws:
      IOException
    • assertJPost

      public static void assertJPost(String request, String content, String... tests) throws Exception
      Validates the response from a POST request matches some JSON test expressions
      Throws:
      Exception
      See Also:
    • assertJPost

      public static void assertJPost(String request, String content, double delta, String... tests) throws Exception
      Validates the response from a PUT request 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:
      request - a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
      content - The content to include with the PUT request
      delta - tolerance allowed in comparing float/double values
      tests - JSON path expression + '==' + expected value
      Throws:
      Exception
    • assertJDelete

      public static void assertJDelete(String request, String... tests) throws Exception
      Deletes a resource and then matches some JSON test expressions against the response using the default double delta tolerance.
      Throws:
      Exception
      See Also:
    • assertJDelete

      public static void assertJDelete(String request, double delta, String... tests) throws Exception
      Deletes a resource and then matches some JSON test expressions against the response using the specified double delta tolerance.
      Throws:
      Exception