Package org.apache.solr.util
Class RestTestHarness
java.lang.Object
org.apache.solr.util.BaseTestHarness
org.apache.solr.util.RestTestHarness
Facilitates testing Solr's REST API via Jetty HttpClient. Immutable and cheap to construct.
-
Constructor Summary
ConstructorsConstructorDescriptionRestTestHarness(org.eclipse.jetty.client.HttpClient httpClient, URI baseUri) Creates a RestTestHarness for the given base URL using the provided HttpClient. -
Method Summary
Modifier and TypeMethodDescriptionadminQuery(String request) checkAdminResponseStatus(String request, int code) Processes a DELETE request using a URL path (with no context path) + optional query params, e.g.org.eclipse.jetty.client.HttpClientintProcesses a HEAD request using a URL path (with no context path) + optional query params and returns the status code.newWithUrl(String baseUrl) Creates a new instance for the specified URL, sharing the underlying HTTP client.Processes a POST request using a URL path (with no context path) + optional query params, e.g.Processes a PUT request using a URL path (with no context path) + optional query params, e.g.Processes a "query" using a URL path (with no context path) + optional query params, e.g.voidreload()Reloads the first core listed in the response to the core admin handler STATUS commandtoString()Processes an "update" (add, commit or optimize) and returns the response as a String.Methods inherited from class org.apache.solr.util.BaseTestHarness
checkUpdateStatus, commit, deleteById, deleteByQuery, evaluateXPath, getXmlDocumentBuilder, getXpath, makeSimpleDoc, optimize, simpleTag, validateErrorUpdate, validateUpdate, validateXPath
-
Constructor Details
-
RestTestHarness
Creates a RestTestHarness for the given base URL using the provided HttpClient.- Parameters:
httpClient- The HttpClient to use for requests (not closed by this harness)baseUri- The base URI (e.g., "http://localhost:8983/solr/collection1")
-
-
Method Details
-
newWithUrl
Creates a new instance for the specified URL, sharing the underlying HTTP client. -
toString
-
getBaseURL
-
getBaseURI
-
getAdminURL
-
query
Processes a "query" using a URL path (with no context path) + optional query params, e.g. "/schema/fields?indent=off"- Parameters:
request- the URL path and optional query params- Returns:
- The response to the query
- Throws:
IOException- any exception in the response.
-
adminQuery
- Throws:
IOException
-
head
Processes a HEAD request using a URL path (with no context path) + optional query params and returns the status code.- Parameters:
request- The URL path and optional query params- Returns:
- The HTTP status code
- Throws:
IOException
-
put
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 paramsjson- The content to include with the PUT request- Returns:
- The response to the PUT request
- Throws:
IOException
-
delete
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
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 paramsjson- The content to include with the POST request- Returns:
- The response to the POST request
- Throws:
IOException
-
checkAdminResponseStatus
- Throws:
Exception
-
reload
Reloads the first core listed in the response to the core admin handler STATUS command- Specified by:
reloadin classBaseTestHarness- Throws:
Exception
-
update
Processes an "update" (add, commit or optimize) and returns the response as a String.- Specified by:
updatein classBaseTestHarness- Parameters:
xml- The XML of the update- Returns:
- The XML response to the update
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()
-