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 java.lang.String CONTENT_TYPE_CSS
           
static java.lang.String CONTENT_TYPE_DONTCARE
          Means "don't care about Content-Type" in getContent(...) methods
static java.lang.String CONTENT_TYPE_HTML
           
static java.lang.String CONTENT_TYPE_JS
           
static java.lang.String CONTENT_TYPE_JSON
           
static java.lang.String CONTENT_TYPE_PLAIN
           
static java.lang.String CONTENT_TYPE_XML
           
static java.lang.String DEFAULT_EXT
           
static java.lang.String HTTP_BASE_URL
           
protected  org.apache.commons.httpclient.HttpClient httpClient
           
static java.lang.String SLING_POST_SERVLET_CREATE_SUFFIX
           
static java.lang.String SLING_RESOURCE_TYPE
           
static java.lang.String TEST_PATH
          base path for test files
protected  SlingIntegrationTestClient testClient
           
protected  java.util.List<java.lang.String> urlsToDelete
          URLs stored here are deleted in tearDown
static java.lang.String WEBDAV_BASE_URL
           
 
Constructor Summary
HttpTestBase()
           
 
Method Summary
protected  void assertHttpStatus(java.lang.String urlString, int expectedStatusCode)
          Verify that given URL returns expectedStatusCode
protected  void assertHttpStatus(java.lang.String urlString, int expectedStatusCode, java.lang.String assertMessage)
          Verify that given URL returns expectedStatusCode
protected  void assertJavascript(java.lang.String expectedOutput, java.lang.String jsonData, java.lang.String code)
           
protected  void assertJavascript(java.lang.String expectedOutput, java.lang.String jsonData, java.lang.String code, java.lang.String testInfo)
          Evaluate given code using given jsonData as the "data" object
protected  void assertPostStatus(java.lang.String url, int expectedStatusCode, java.util.List<org.apache.commons.httpclient.NameValuePair> postParams, java.lang.String assertMessage)
          Execute a POST request and check status
protected  java.lang.String getContent(java.lang.String url, java.lang.String expectedContentType)
          retrieve the contents of given URL and assert its content type
protected  java.lang.String getContent(java.lang.String url, java.lang.String expectedContentType, java.util.List<org.apache.commons.httpclient.NameValuePair> params)
           
protected  java.lang.String getContent(java.lang.String url, java.lang.String expectedContentType, java.util.List<org.apache.commons.httpclient.NameValuePair> params, int expectedStatusCode)
          retrieve the contents of given URL and assert its content type
protected static java.lang.String removeEndingSlash(java.lang.String str)
           
protected  void setUp()
           
protected  boolean slingServerReady()
          Return true if able to create and retrieve a node on server
protected  void tearDown()
           
protected  java.lang.String uploadTestScript(java.lang.String scriptPath, java.lang.String localFilename, java.lang.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 java.lang.String HTTP_BASE_URL

WEBDAV_BASE_URL

public static final java.lang.String WEBDAV_BASE_URL

TEST_PATH

public static final java.lang.String TEST_PATH
base path for test files

See Also:
Constant Field Values

CONTENT_TYPE_HTML

public static final java.lang.String CONTENT_TYPE_HTML
See Also:
Constant Field Values

CONTENT_TYPE_XML

public static final java.lang.String CONTENT_TYPE_XML
See Also:
Constant Field Values

CONTENT_TYPE_PLAIN

public static final java.lang.String CONTENT_TYPE_PLAIN
See Also:
Constant Field Values

CONTENT_TYPE_JSON

public static final java.lang.String CONTENT_TYPE_JSON
See Also:
Constant Field Values

CONTENT_TYPE_JS

public static final java.lang.String CONTENT_TYPE_JS
See Also:
Constant Field Values

CONTENT_TYPE_CSS

public static final java.lang.String CONTENT_TYPE_CSS
See Also:
Constant Field Values

SLING_RESOURCE_TYPE

public static final java.lang.String SLING_RESOURCE_TYPE
See Also:
Constant Field Values

SLING_POST_SERVLET_CREATE_SUFFIX

public static final java.lang.String SLING_POST_SERVLET_CREATE_SUFFIX
See Also:
Constant Field Values

DEFAULT_EXT

public static final java.lang.String DEFAULT_EXT
See Also:
Constant Field Values

testClient

protected SlingIntegrationTestClient testClient

httpClient

protected org.apache.commons.httpclient.HttpClient httpClient

CONTENT_TYPE_DONTCARE

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

See Also:
Constant Field Values

urlsToDelete

protected final java.util.List<java.lang.String> urlsToDelete
URLs stored here are deleted in tearDown

Constructor Detail

HttpTestBase

public HttpTestBase()
Method Detail

removeEndingSlash

protected static java.lang.String removeEndingSlash(java.lang.String str)

setUp

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

tearDown

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

waitForSlingStartup

protected void waitForSlingStartup()
                            throws java.lang.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:
java.lang.Exception

slingServerReady

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

Throws:
java.lang.Exception

assertHttpStatus

protected void assertHttpStatus(java.lang.String urlString,
                                int expectedStatusCode,
                                java.lang.String assertMessage)
                         throws java.io.IOException
Verify that given URL returns expectedStatusCode

Throws:
java.io.IOException

assertHttpStatus

protected void assertHttpStatus(java.lang.String urlString,
                                int expectedStatusCode)
                         throws java.io.IOException
Verify that given URL returns expectedStatusCode

Throws:
java.io.IOException

assertPostStatus

protected void assertPostStatus(java.lang.String url,
                                int expectedStatusCode,
                                java.util.List<org.apache.commons.httpclient.NameValuePair> postParams,
                                java.lang.String assertMessage)
                         throws java.io.IOException
Execute a POST request and check status

Throws:
java.io.IOException

getContent

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

Throws:
java.io.IOException

getContent

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

getContent

protected java.lang.String getContent(java.lang.String url,
                                      java.lang.String expectedContentType,
                                      java.util.List<org.apache.commons.httpclient.NameValuePair> params,
                                      int expectedStatusCode)
                               throws java.io.IOException
retrieve the contents of given URL and assert its content type

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

uploadTestScript

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

Throws:
java.io.IOException

assertJavascript

protected void assertJavascript(java.lang.String expectedOutput,
                                java.lang.String jsonData,
                                java.lang.String code)
                         throws java.io.IOException
Throws:
java.io.IOException

assertJavascript

protected void assertJavascript(java.lang.String expectedOutput,
                                java.lang.String jsonData,
                                java.lang.String code,
                                java.lang.String testInfo)
                         throws java.io.IOException
Evaluate given code using given jsonData as the "data" object

Throws:
java.io.IOException


Copyright © 2007-2009. All Rights Reserved.