org.apache.sling.commons.testing.integration
Class HttpTestBase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.sling.commons.testing.integration.HttpTestBase
All Implemented Interfaces:
junit.framework.Test

public class HttpTestBase
extends junit.framework.TestCase

Base class for HTTP-based Sling Launchpad integration tests


Nested Class Summary
protected  class HttpTestBase.TestNode
          Class that creates a test node under the given parentPath, and stores useful values for testing.
 
Field Summary
static String CONTENT_TYPE_CSS
           
static String CONTENT_TYPE_DONTCARE
          Means "don't care about Content-Type" in getContent(...) methods
static String CONTENT_TYPE_HTML
           
static String CONTENT_TYPE_JS
           
static String CONTENT_TYPE_JSON
           
static String CONTENT_TYPE_PLAIN
           
static String CONTENT_TYPE_XML
           
static String DEFAULT_EXT
           
static String EXECUTE_RESOURCE_TYPE
           
static String HTTP_BASE_URL
           
protected  org.apache.commons.httpclient.HttpClient httpClient
           
static int READY_TIMEOUT_SECONDS
           
static String SERVLET_CONTEXT
           
static String SLING_POST_SERVLET_CREATE_SUFFIX
           
static String SLING_RESOURCE_TYPE
           
static String TEST_PATH
          base path for test files
protected  SlingIntegrationTestClient testClient
           
protected  List<String> urlsToDelete
          URLs stored here are deleted in tearDown
static String WEBDAV_BASE_URL
           
 
Constructor Summary
HttpTestBase()
           
 
Method Summary
protected  org.apache.commons.httpclient.HttpMethod assertHttpStatus(String urlString, int expectedStatusCode)
          Verify that given URL returns expectedStatusCode
protected  org.apache.commons.httpclient.HttpMethod assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage)
          Verify that given URL returns expectedStatusCode
protected  void assertJavascript(String expectedOutput, String jsonData, String code)
           
protected  void assertJavascript(String expectedOutput, String jsonData, String code, String testInfo)
          Evaluate given code using given jsonData as the "data" object
protected  org.apache.commons.httpclient.HttpMethod assertPostStatus(String url, int expectedStatusCode, List<org.apache.commons.httpclient.NameValuePair> postParams, String assertMessage)
          Execute a POST request and check status
protected  String executeScript(String localFilename)
          Upload script, execute with no parameters and return content
protected  String executeScript(String localFilename, List<org.apache.commons.httpclient.NameValuePair> params)
          Upload script, execute with given parameters (optional) and return content
protected  String getContent(String url, String expectedContentType)
          retrieve the contents of given URL and assert its content type
protected  String getContent(String url, String expectedContentType, List<org.apache.commons.httpclient.NameValuePair> params)
           
protected  String 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
static String getResponseBodyAsStream(org.apache.commons.httpclient.HttpMethodBase m, int maxLength)
          Return m's response body as a string, optionally limiting the length that we read
protected static String removeEndingSlash(String str)
           
protected  void setUp()
           
protected  boolean slingServerReady()
          Return true if able to create and retrieve a node on server
protected  void tearDown()
           
protected  String uploadTestScript(String scriptPath, String localFilename, String filenameOnServer)
          upload rendering test script, and return its URL for future deletion
protected  void waitForSlingStartup()
          On the server side, initialization of Sling bundles is done asynchronously once the webapp is started.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTTP_BASE_URL

public static final String HTTP_BASE_URL

WEBDAV_BASE_URL

public static final String WEBDAV_BASE_URL

SERVLET_CONTEXT

public static final String SERVLET_CONTEXT

TEST_PATH

public static final String TEST_PATH
base path for test files

See Also:
Constant Field Values

CONTENT_TYPE_HTML

public static final String CONTENT_TYPE_HTML
See Also:
Constant Field Values

CONTENT_TYPE_XML

public static final String CONTENT_TYPE_XML
See Also:
Constant Field Values

CONTENT_TYPE_PLAIN

public static final String CONTENT_TYPE_PLAIN
See Also:
Constant Field Values

CONTENT_TYPE_JSON

public static final String CONTENT_TYPE_JSON
See Also:
Constant Field Values

CONTENT_TYPE_JS

public static final String CONTENT_TYPE_JS
See Also:
Constant Field Values

CONTENT_TYPE_CSS

public static final String CONTENT_TYPE_CSS
See Also:
Constant Field Values

SLING_RESOURCE_TYPE

public static final String SLING_RESOURCE_TYPE
See Also:
Constant Field Values

SLING_POST_SERVLET_CREATE_SUFFIX

public static final String SLING_POST_SERVLET_CREATE_SUFFIX
See Also:
Constant Field Values

DEFAULT_EXT

public static final String DEFAULT_EXT
See Also:
Constant Field Values

EXECUTE_RESOURCE_TYPE

public static final String EXECUTE_RESOURCE_TYPE

READY_TIMEOUT_SECONDS

public static final int READY_TIMEOUT_SECONDS

testClient

protected SlingIntegrationTestClient testClient

httpClient

protected org.apache.commons.httpclient.HttpClient httpClient

CONTENT_TYPE_DONTCARE

public static final String CONTENT_TYPE_DONTCARE
Means "don't care about Content-Type" in getContent(...) methods

See Also:
Constant Field Values

urlsToDelete

protected final List<String> urlsToDelete
URLs stored here are deleted in tearDown

Constructor Detail

HttpTestBase

public HttpTestBase()
Method Detail

removeEndingSlash

protected static String removeEndingSlash(String str)

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

waitForSlingStartup

protected void waitForSlingStartup()
                            throws Exception
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

protected boolean slingServerReady()
                            throws Exception
Return true if able to create and retrieve a node on server

Throws:
Exception

assertHttpStatus

protected 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

protected 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

protected 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

protected String getContent(String url,
                            String expectedContentType)
                     throws IOException
retrieve the contents of given URL and assert its content type

Throws:
IOException

getContent

protected String getContent(String url,
                            String expectedContentType,
                            List<org.apache.commons.httpclient.NameValuePair> params)
                     throws IOException
Throws:
IOException

getContent

protected 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

Parameters:
expectedContentType - use CONTENT_TYPE_DONTCARE if must not be checked
Throws:
IOException
org.apache.commons.httpclient.HttpException

uploadTestScript

protected String uploadTestScript(String scriptPath,
                                  String localFilename,
                                  String filenameOnServer)
                           throws IOException
upload rendering test script, and return its URL for future deletion

Throws:
IOException

executeScript

protected String executeScript(String localFilename)
                        throws Exception
Upload script, execute with no parameters and return content

Throws:
Exception

executeScript

protected 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

protected void assertJavascript(String expectedOutput,
                                String jsonData,
                                String code)
                         throws IOException
Throws:
IOException

assertJavascript

protected 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


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.