Author: asanso
Date: Thu Feb 7 10:46:59 2013
New Revision: 1443396
URL: http://svn.apache.org/viewvc?rev=1443396&view=rev
Log:
SLING-2718 - Add integration test for the error handling mechanism.
- adding more integration tests also for POST operations
- improve the common testing to support POST operations
Added:
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/POST.jsp
Modified:
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
sling/trunk/launchpad/integration-tests/pom.xml
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
Modified:
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=1443396&r1=1443395&r2=1443396&view=diff
==============================================================================
---
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
(original)
+++
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
Thu Feb 7 10:46:59 2013
@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
@@ -56,6 +55,9 @@ public class HttpTestBase extends TestCa
/** base path for test files */
public static final String TEST_PATH = "/launchpad-integration-tests";
+
+ public static final String HTTP_METHOD_GET = "GET";
+ public static final String HTTP_METHOD_POST = "POST";
public static final String CONTENT_TYPE_HTML = "text/html";
public static final String CONTENT_TYPE_XML = "application/xml";
@@ -335,30 +337,49 @@ public class HttpTestBase extends TestCa
return post;
}
- /** retrieve the contents of given URL and assert its content type */
+ /** retrieve the contents of given URL and assert its content type
(default to HTTP GET method)*/
protected String getContent(String url, String expectedContentType) throws
IOException {
return getContent(url, expectedContentType, null);
}
+ /** retrieve the contents of given URL and assert its content type
(default to HTTP GET method)*/
protected String getContent(String url, String expectedContentType,
List<NameValuePair> params) throws IOException {
return getContent(url, expectedContentType, params,
HttpServletResponse.SC_OK);
}
- /** retrieve the contents of given URL and assert its content type
+ /** retrieve the contents of given URL and assert its content type
(default to HTTP GET method)
* @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be
checked
* @throws IOException
* @throws HttpException */
protected String getContent(String url, String expectedContentType,
List<NameValuePair> params, int expectedStatusCode) throws IOException {
- final GetMethod get = new GetMethod(url);
- if(params != null) {
+ return getContent(url, expectedContentType, params, expectedStatusCode,
HTTP_METHOD_GET);
+ }
+
+ /** retrieve the contents of given URL and assert its content type
+ * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be
checked
+ * @param httMethod supports just GET and POST methods
+ * @throws IOException
+ * @throws HttpException */
+ protected String getContent(String url, String expectedContentType,
List<NameValuePair> params, int expectedStatusCode, String httpMethod) throws
IOException {
+ HttpMethodBase method = null;
+
+ if (HTTP_METHOD_GET.equals(httpMethod)){
+ method= new GetMethod(url);
+ }else if (HTTP_METHOD_POST.equals(httpMethod)){
+ method = new PostMethod(url);
+ } else{
+ fail("Http Method not supported in this test suite, method:
"+httpMethod);
+ }
+
+ if(params != null) {
final NameValuePair [] nvp = new NameValuePair[0];
- get.setQueryString(params.toArray(nvp));
+ method.setQueryString(params.toArray(nvp));
}
- final int status = httpClient.executeMethod(get);
- final String content = getResponseBodyAsStream(get, 0);
+ final int status = httpClient.executeMethod(method);
+ final String content = getResponseBodyAsStream(method, 0);
assertEquals("Expected status " + expectedStatusCode + " for " + url +
" (content=" + content + ")",
expectedStatusCode,status);
- final Header h = get.getResponseHeader("Content-Type");
+ final Header h = method.getResponseHeader("Content-Type");
if(expectedContentType == null) {
if(h!=null) {
fail("Expected null Content-Type, got " + h.getValue());
@@ -378,7 +399,9 @@ public class HttpTestBase extends TestCa
);
}
return content.toString();
+
}
+
/** upload rendering test script, and return its URL for future deletion */
protected String uploadTestScript(String scriptPath, String
localFilename,String filenameOnServer) throws IOException {
Modified: sling/trunk/launchpad/integration-tests/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/pom.xml?rev=1443396&r1=1443395&r2=1443396&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/pom.xml (original)
+++ sling/trunk/launchpad/integration-tests/pom.xml Thu Feb 7 10:46:59 2013
@@ -131,7 +131,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.testing</artifactId>
- <version>2.0.10</version>
+ <version>2.0.13-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Modified:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java?rev=1443396&r1=1443395&r2=1443396&view=diff
==============================================================================
---
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java
(original)
+++
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java
Thu Feb 7 10:46:59 2013
@@ -19,7 +19,6 @@ package org.apache.sling.launchpad.webap
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.sling.launchpad.webapp.integrationtest.JspTestBase;
@@ -55,6 +54,7 @@ public class ErrorHandlingTest extends J
uploadTestScript("servlets/errorhandler/500.jsp",
"sling/servlet/errorhandler/500.jsp");
uploadTestScript("servlets/errorhandler/401.jsp",
"sling/servlet/errorhandler/401.jsp");
uploadTestScript(THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE,
THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE);
+ uploadTestScript(THROW_ERROR_PATH+"/"+"POST.jsp",
THROW_ERROR_PATH+"/"+"POST.jsp");
final Map<String, String> props = new HashMap<String, String>();
props.put(SLING_RESOURCE_TYPE, TEST_ROOT+"/"+THROW_ERROR_PATH);
@@ -93,5 +93,12 @@ public class ErrorHandlingTest extends J
assertContains(getContent(url, CONTENT_TYPE_HTML,null,200),
expected);
assertNotContains(getContent(url, CONTENT_TYPE_HTML,null,200),
"All good");
}
+
+ public void test_500_errorhandling_POST_operation() throws IOException{
+ final String expected = "Internal Server Error (500) - custom
error page";
+ final String url = testNodePath +SELECTOR_500+".html";
+ assertContains(getContent(url,
CONTENT_TYPE_HTML,null,500,HTTP_METHOD_POST), expected);
+ //assertNotContains(getContent(url,
CONTENT_TYPE_HTML,null,200), "All good");
+ }
}
Added:
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/POST.jsp
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/POST.jsp?rev=1443396&view=auto
==============================================================================
---
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/POST.jsp
(added)
+++
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/POST.jsp
Thu Feb 7 10:46:59 2013
@@ -0,0 +1,27 @@
+<!--
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<%@page
+ session="false"
+%>
+
+<%
+response.setStatus(500);
+response.sendError(500);
+%>
Modified:
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp?rev=1443396&r1=1443395&r2=1443396&view=diff
==============================================================================
---
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
(original)
+++
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
Thu Feb 7 10:46:59 2013
@@ -25,7 +25,6 @@
<%
final String SELECTOR_401 ="401";
final String SELECTOR_500 ="500";
-final String SELECTOR_SEND_ERROR ="sendError";
final String SELECTOR_THROWABLE ="throwable";
final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;