incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1441365 - in /sling/trunk/launchpad/integration-tests/src/main: java/org/apache/sling/launchpad/webapp/integrationtest/ java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ resources/integration-test/servl...
Date Fri, 01 Feb 2013 10:00:17 GMT
Author: asanso
Date: Fri Feb  1 10:00:17 2013
New Revision: 1441365

URL: http://svn.apache.org/viewvc?rev=1441365&view=rev
Log:
SLING-2718 - Add integration test for the error handling mechanism. 
adding more integration tests

Added:
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/401.jsp
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/500.jsp
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/Throwable.jsp
    sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/
    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/RenderingTestBase.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolver/errorhandler/ErrorHandlingTest.java

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RenderingTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RenderingTestBase.java?rev=1441365&r1=1441364&r2=1441365&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RenderingTestBase.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RenderingTestBase.java
Fri Feb  1 10:00:17 2013
@@ -36,4 +36,10 @@ public abstract class RenderingTestBase 
             fail("Content does not contain '" + expected + "' (content=" + content + ")");
         }
     }
+    
+    protected void assertNotContains(String content, String notExpected) {
+    	if(content.contains(notExpected)) {
+            fail("Content contains '" + notExpected + "' (content=" + content + ")");
+        }
+    }
 }

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=1441365&r1=1441364&r2=1441365&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
Fri Feb  1 10:00:17 2013
@@ -17,6 +17,9 @@
 package org.apache.sling.launchpad.webapp.integrationtest.servlets.resolver.errorhandler;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.sling.launchpad.webapp.integrationtest.JspTestBase;
 
 
@@ -24,21 +27,38 @@ import org.apache.sling.launchpad.webapp
 public class ErrorHandlingTest extends JspTestBase {
 
 	public final static String TEST_ROOT = "/apps";
- 
+
+	public final static String THROW_ERROR_PATH= "servlets/errorhandler/testErrorHandler";
+
+	public final static String THROW_ERROR_PAGE= "testErrorHandler.jsp";
+
 	public static final String ERROR_HANDLER_PATH = "/apps/sling/servlet/errorhandler";
 
 	private static final String NOT_EXISTING_NODE_PATH="/notExisting";
 
+	private static final String SELECTOR_500 =".500";
+
+	private static final String SELECTOR_401 =".401";
+
+	private static final String SELECTOR_THROWABLE =".throwable";
+
 	private String testNodePath;
 
 	@Override
 	protected void setUp() throws Exception {
 		super.setUp();
 		scriptPath = TEST_ROOT;
-		testClient.mkdirs(HTTP_BASE_URL, "/apps/sling/servlet/errorhandler");
+		testClient.mkdirs(HTTP_BASE_URL, ERROR_HANDLER_PATH);
+		testClient.mkdirs(HTTP_BASE_URL, TEST_ROOT+"/"+THROW_ERROR_PATH);
 		uploadTestScript("servlets/errorhandler/404.jsp", "sling/servlet/errorhandler/404.jsp");
-		
-		testNodePath = testClient.createNode(HTTP_BASE_URL + TEST_ROOT, null);
+		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(THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE, THROW_ERROR_PATH+"/"+THROW_ERROR_PAGE);
+
+		final Map<String, String> props = new HashMap<String, String>();
+		props.put(SLING_RESOURCE_TYPE, TEST_ROOT+"/"+THROW_ERROR_PATH);
+		testNodePath = testClient.createNode(HTTP_BASE_URL + TEST_ROOT, props);
 	}
 
 	@Override
@@ -53,4 +73,25 @@ public class ErrorHandlingTest extends J
 		assertContains(getContent(url, CONTENT_TYPE_HTML,null,200), expected);
 	}
 
+	public void test_500_errorhandling() 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), expected);
+		//assertNotContains(getContent(url, CONTENT_TYPE_HTML,null,200), "All good");
+	}
+
+	public void test_401_errorhandling() throws IOException{
+		final String expected = "401 Unauthorized - custom error page";
+		final String url =  testNodePath +SELECTOR_401+".html"; 
+		assertContains(getContent(url, CONTENT_TYPE_HTML,null,401), expected);
+		//assertNotContains(getContent(url, CONTENT_TYPE_HTML,null,401), "All good");	
+	}
+
+	public void test_throwable_errorhandling() throws IOException{	
+		final String expected = "Exception thrown - custom error page";
+		final String url =  testNodePath +SELECTOR_THROWABLE+".html";
+		assertContains(getContent(url, CONTENT_TYPE_HTML,null,200), expected);
+		assertNotContains(getContent(url, CONTENT_TYPE_HTML,null,200), "All good");
+	}
+
 }

Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/401.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/401.jsp?rev=1441365&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/401.jsp
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/401.jsp
Fri Feb  1 10:00:17 2013
@@ -0,0 +1,34 @@
+<!--
+/*
+ * 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">
+<!-- simple JSP rendering test -->
+<%@page session="false"%>
+<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
+<%
+String customMessage= "custom error page";
+%>
+<html>
+	<head>
+		<title>401 Unauthorized</title>
+	</head>
+	<body>
+		<h1>401 Unauthorized - <%=customMessage%></h1>
+	</body>
+</html>
\ No newline at end of file

Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/500.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/500.jsp?rev=1441365&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/500.jsp
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/500.jsp
Fri Feb  1 10:00:17 2013
@@ -0,0 +1,34 @@
+<!--
+/*
+ * 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">
+<!-- simple JSP rendering test -->
+<%@page session="false"%>
+<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
+<%
+String customMessage= "custom error page";
+%>
+<html>
+	<head>
+		<title>500 Internal Server Error</title>
+	</head>
+	<body>
+		<h1>Internal Server Error (500) - <%=customMessage%></h1>
+	</body>
+</html>
\ No newline at end of file

Added: sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/Throwable.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/Throwable.jsp?rev=1441365&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/Throwable.jsp
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/Throwable.jsp
Fri Feb  1 10:00:17 2013
@@ -0,0 +1,34 @@
+<!--
+/*
+ * 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">
+<!-- simple JSP rendering test -->
+<%@page session="false"%>
+<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"%>
+<%
+String customMessage= "custom error page";
+%>
+<html>
+	<head>
+		<title>Exception thrown</title>
+	</head>
+	<body>
+		<h1>Exception thrown - <%=customMessage%></h1>
+	</body>
+</html>
\ No newline at end of file

Added: 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=1441365&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/resources/integration-test/servlets/errorhandler/testErrorHandler/testErrorHandler.jsp
Fri Feb  1 10:00:17 2013
@@ -0,0 +1,42 @@
+<!--
+/*
+ * 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"
+	import="java.util.Arrays, org.apache.sling.api.SlingHttpServletRequest" 
+%>
+
+<%	
+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;
+
+if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_401))
{
+	 response.setStatus(401);
+	 response.sendError(401);
+}else if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_500))
{
+	response.setStatus(500);
+ 	response.sendError(500);
+}else if(Arrays.asList(slingRequest.getRequestPathInfo().getSelectors()).contains(SELECTOR_THROWABLE))
{
+	throw new Exception("throwable selector was specified");
+}
+%>
+All good



Mime
View raw message