Class HttpTestBase
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.apache.sling.commons.testing.integration.HttpTestBase
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
HttpTest
public class HttpTestBase
extends junit.framework.TestCase
Base class for HTTP-based Sling Launchpad integration tests
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classClass that creates a test node under the given parentPath, and stores useful values for testing. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringMeans "don't care about Content-Type" in getContent(...) methodsstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected org.apache.commons.httpclient.HttpClientstatic final intstatic final StringIf this system property is set, the startup check is skipped.static final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringbase path for test filesprotected SlingIntegrationTestClientURLs stored here are deleted in tearDownstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.commons.httpclient.HttpMethodassertHttpStatus(String urlString, int expectedStatusCode) Verify that given URL returns expectedStatusCodeorg.apache.commons.httpclient.HttpMethodassertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) Verify that given URL returns expectedStatusCodevoidassertJavascript(String expectedOutput, String jsonData, String code) voidassertJavascript(String expectedOutput, String jsonData, String code, String testInfo) Evaluate given code using given jsonData as the "data" objectorg.apache.commons.httpclient.HttpMethodassertPostStatus(String url, int expectedStatusCode, List<org.apache.commons.httpclient.NameValuePair> postParams, String assertMessage) Execute a POST request and check statusexecuteScript(String localFilename) Upload script, execute with no parameters and return contentexecuteScript(String localFilename, List<org.apache.commons.httpclient.NameValuePair> params) Upload script, execute with given parameters (optional) and return contentgetContent(String url, String expectedContentType) retrieve the contents of given URL and assert its content type (default to HTTP GET method)getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params) retrieve the contents of given URL and assert its content type (default to HTTP GET method)getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params, int expectedStatusCode) retrieve the contents of given URL and assert its content type (default to HTTP GET method)getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params, int expectedStatusCode, String httpMethod) retrieve the contents of given URL and assert its content typeorg.apache.commons.httpclient.CredentialsGenerate default credentials used for HTTP requests.static StringgetResponseBodyAsStream(org.apache.commons.httpclient.HttpMethodBase m, int maxLength) Return m's response body as a string, optionally limiting the length that we readbooleanisBundleVersionAtLeast(String bundleSymbolicName, String version) Returns true if the bundle version deployed on the Sling instance is present and at least of the specified versionstatic StringremoveEndingSlash(String str) final voidsetReadinessContentType(String extension, String contentTypePrefix) Set the extension and content-type prefix to use for GET requests that check Sling readinessprotected voidsetUp()protected booleanReturn true if able to create and retrieve a node on serverprotected voidtearDown()uploadTestScript(String scriptPath, String localFilename, String filenameOnServer) upload rendering test script, and return its URL for future deletionprotected voidOn the server side, initialization of Sling bundles is done asynchronously once the webapp is started.Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
Field Details
-
PROPERTY_SKIP_STARTUP_CHECK
If this system property is set, the startup check is skipped.- See Also:
-
HTTP_URL
-
HTTP_BASE_URL
-
WEBDAV_BASE_URL
-
SERVLET_CONTEXT
-
READINESS_MEDIA_TYPE_PROP
- See Also:
-
DEFAULT_READINESS_MEDIA_TYPE
- See Also:
-
READY_URL_PROP_PREFIX
- See Also:
-
MAX_READY_URL_INDEX
public static final int MAX_READY_URL_INDEX- See Also:
-
TEST_PATH
base path for test files- See Also:
-
HTTP_METHOD_GET
- See Also:
-
HTTP_METHOD_POST
- See Also:
-
CONTENT_TYPE_HTML
- See Also:
-
CONTENT_TYPE_XML
- See Also:
-
CONTENT_TYPE_PLAIN
- See Also:
-
CONTENT_TYPE_JSON
- See Also:
-
CONTENT_TYPE_JS
- See Also:
-
CONTENT_TYPE_CSS
- See Also:
-
SLING_RESOURCE_TYPE
- See Also:
-
SLING_POST_SERVLET_CREATE_SUFFIX
- See Also:
-
DEFAULT_EXT
- See Also:
-
EXECUTE_RESOURCE_TYPE
-
READY_TIMEOUT_SECONDS
public static final int READY_TIMEOUT_SECONDS -
testClient
-
httpClient
protected org.apache.commons.httpclient.HttpClient httpClient -
CONTENT_TYPE_DONTCARE
Means "don't care about Content-Type" in getContent(...) methods- See Also:
-
urlsToDelete
URLs stored here are deleted in tearDown
-
-
Constructor Details
-
HttpTestBase
public HttpTestBase()
-
-
Method Details
-
removeEndingSlash
-
setUp
- Overrides:
setUpin classjunit.framework.TestCase- Throws:
Exception
-
getDefaultCredentials
public org.apache.commons.httpclient.Credentials getDefaultCredentials()Generate default credentials used for HTTP requests. -
tearDown
- Overrides:
tearDownin classjunit.framework.TestCase- Throws:
Exception
-
waitForSlingStartup
On the server side, initialization of Sling bundles is done asynchronously once the webapp is started. This method checks that everything's ready on the server side, by calling an URL that requires the SlingPostServlet and the JCR repository to work correctly.- Throws:
Exception
-
slingServerReady
Return true if able to create and retrieve a node on server- Throws:
Exception
-
assertHttpStatus
public org.apache.commons.httpclient.HttpMethod assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) throws IOException Verify that given URL returns expectedStatusCode- Returns:
- the HttpMethod executed
- Throws:
IOException
-
assertHttpStatus
public org.apache.commons.httpclient.HttpMethod assertHttpStatus(String urlString, int expectedStatusCode) throws IOException Verify that given URL returns expectedStatusCode- Returns:
- the HttpMethod executed
- Throws:
IOException
-
assertPostStatus
public org.apache.commons.httpclient.HttpMethod assertPostStatus(String url, int expectedStatusCode, List<org.apache.commons.httpclient.NameValuePair> postParams, String assertMessage) throws IOException Execute a POST request and check status- Returns:
- the HttpMethod executed
- Throws:
IOException
-
getContent
retrieve the contents of given URL and assert its content type (default to HTTP GET method)- Throws:
IOException
-
getContent
public String getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params) throws IOException retrieve the contents of given URL and assert its content type (default to HTTP GET method)- Throws:
IOException
-
getContent
public String getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params, int expectedStatusCode) throws IOException retrieve the contents of given URL and assert its content type (default to HTTP GET method)- Parameters:
expectedContentType- use CONTENT_TYPE_DONTCARE if must not be checked- Throws:
IOExceptionorg.apache.commons.httpclient.HttpException
-
getContent
public String getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params, int expectedStatusCode, String httpMethod) throws IOException retrieve the contents of given URL and assert its content type- Parameters:
expectedContentType- use CONTENT_TYPE_DONTCARE if must not be checkedhttpMethod- supports just GET and POST methods- Throws:
IOExceptionorg.apache.commons.httpclient.HttpException
-
uploadTestScript
public String uploadTestScript(String scriptPath, String localFilename, String filenameOnServer) throws IOException upload rendering test script, and return its URL for future deletion- Throws:
IOException
-
executeScript
Upload script, execute with no parameters and return content- Throws:
Exception
-
executeScript
public String executeScript(String localFilename, List<org.apache.commons.httpclient.NameValuePair> params) throws Exception Upload script, execute with given parameters (optional) and return content- Throws:
Exception
-
assertJavascript
public void assertJavascript(String expectedOutput, String jsonData, String code) throws IOException - Throws:
IOException
-
assertJavascript
public void assertJavascript(String expectedOutput, String jsonData, String code, String testInfo) throws IOException Evaluate given code using given jsonData as the "data" object- Throws:
IOException
-
getResponseBodyAsStream
public static String getResponseBodyAsStream(org.apache.commons.httpclient.HttpMethodBase m, int maxLength) throws IOException Return m's response body as a string, optionally limiting the length that we read- Parameters:
maxLength- if 0, no limit- Throws:
IOException
-
setReadinessContentType
Set the extension and content-type prefix to use for GET requests that check Sling readiness -
isBundleVersionAtLeast
Returns true if the bundle version deployed on the Sling instance is present and at least of the specified version- Parameters:
bundleSymbolicName- the bundle name to checkversion- the minimal version of the bundle that should be deployed- Returns:
- true if the bundle is deployed with the specified version, false if it is not deployed or the version it too old
- Throws:
IOException
-