You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/11/12 11:29:01 UTC
svn commit: r1638735 - in /sling/trunk/launchpad/integration-tests/src/main:
java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/
resources/integration-test/servlets/errorhandler/
resources/integration-test/servlets/er...
Author: bdelacretaz
Date: Wed Nov 12 10:29:01 2014
New Revision: 1638735
URL: http://svn.apache.org/r1638735
Log:
SLING-4143 - add tests for exceptions in error handling scripts, demonstrate current behavior
Added:
sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/421.jsp
Modified:
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/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=1638735&r1=1638734&r2=1638735&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 Wed Nov 12 10:29:01 2014
@@ -41,6 +41,7 @@ public class ErrorHandlingTest extends R
private static final String SELECTOR_500 =".500";
private static final String SELECTOR_401 =".401";
+ private static final String SELECTOR_421 =".421";
private static final String SELECTOR_THROWABLE =".throwable";
@@ -60,6 +61,7 @@ public class ErrorHandlingTest extends R
uploadTestScript("servlets/errorhandler/Throwable.jsp", "sling/servlet/errorhandler/Throwable.jsp");
uploadTestScript("servlets/errorhandler/500.jsp", "sling/servlet/errorhandler/500.jsp");
uploadTestScript("servlets/errorhandler/401.jsp", "sling/servlet/errorhandler/401.jsp");
+ uploadTestScript("servlets/errorhandler/421.jsp", "sling/servlet/errorhandler/421.jsp");
uploadTestScript(THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE, THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE);
final Map<String, String> props = new HashMap<String, String>();
@@ -104,7 +106,8 @@ public class ErrorHandlingTest extends R
public void test_404_errorhandling() throws Throwable{
final String expected = "No resource found (404) - custom error page";
- final String url = testNodePath+NOT_EXISTING_NODE_PATH +".html";
+ final String url = testNodePath+NOT_EXISTING_NODE_PATH +".html";
+ // 404.jsp does not set status so we get 200
assertWithRetries(url, 200, expected);
}
@@ -120,9 +123,37 @@ public class ErrorHandlingTest extends R
assertWithRetries(url, 401, expected);
}
+ public void test_421_plain() throws Throwable{
+ final String expected = "421 test - 421 error page";
+ final String url = testNodePath +SELECTOR_421+".html";
+ assertWithRetries(url, 421, expected);
+ }
+
+ public void test_421_312() throws Throwable{
+ final String expected = "421 test - 421 error page";
+ final String url = testNodePath + SELECTOR_421 + ".312.html";
+ assertWithRetries(url, 312, expected);
+ }
+
+ public void test_421_exception() throws Throwable{
+ // we get a blank page in this case
+ final String expected = "";
+ final String url = testNodePath + SELECTOR_421 + ".errorScriptException.html";
+ assertWithRetries(url, 421, expected);
+ }
+
+ public void test_421_error() throws Throwable{
+ // we get a blank page in this case
+ final String expected = "";
+ final String url = testNodePath + SELECTOR_421 + ".errorScriptError.html";
+ assertWithRetries(url, 421, expected);
+ }
+
public void test_throwable_errorhandling() throws Throwable{
final String expected = "Exception thrown - custom error page";
final String url = testNodePath +SELECTOR_THROWABLE+".html";
+
+ // Throwable.jsp doesn't set status by default so we get 200
assertWithRetries(url, 200, expected);
}
Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/421.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/421.jsp?rev=1638735&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/421.jsp (added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/421.jsp Wed Nov 12 10:29:01 2014
@@ -0,0 +1,56 @@
+<!--
+/*
+ * 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.
+-->
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+
+<!--
+ Test setting various status codes and throwing
+ exceptions in the error handler script
+-->
+<%@page
+ session="false"
+ import="java.util.List, java.util.Arrays, org.apache.sling.api.SlingHttpServletRequest"
+%>
+<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
+
+<html>
+ <head>
+ <title>421 test</title>
+ </head>
+
+<%
+String customMessage= "421 error page";
+final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
+final List selectors = Arrays.asList(slingRequest.getRequestPathInfo().getSelectors());
+if(selectors.contains("312")) {
+ response.setStatus(312);
+}
+if(selectors.contains("errorScriptException")) {
+ throw new Exception("Exception in error handler");
+}
+if(selectors.contains("errorScriptError")) {
+ throw new Error("Error in error handler");
+}
+
+%>
+
+ <body>
+ <h1>421 test - <%=customMessage%></h1>
+ </body>
+</html>
\ No newline at end of file
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=1638735&r1=1638734&r2=1638735&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 Wed Nov 12 10:29:01 2014
@@ -22,8 +22,11 @@
import="java.util.Arrays, org.apache.sling.api.SlingHttpServletRequest"
%>
-<%
+<%
+// Script that handles the /apps/testNode, sending various error codes
+// or throwing exceptions according to request selectors
final String SELECTOR_401 ="401";
+final String SELECTOR_421 ="421";
final String SELECTOR_500 ="500";
final String SELECTOR_THROWABLE ="throwable";
final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
@@ -31,6 +34,9 @@ final SlingHttpServletRequest slingReque
if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_401)) {
response.setStatus(401);
response.sendError(401);
+}else if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_421)) {
+ response.setStatus(421);
+ response.sendError(421,"421 from rendering script");
}else if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_500)) {
response.setStatus(500);
response.sendError(500);