Author: kkolinko
Date: Thu Apr 29 10:24:14 2010
New Revision: 939253

URL: http://svn.apache.org/viewvc?rev=939253&view=rev
Log:
Tests for Servlet 3.0 support of bundling static resources in 
META-INF/resources subdirectory of a jar file.
It is a separate web application, because the old "webapp-3.0" has 
metadata-complete="true".

The tests in TestStandardContextResources are currently failing,
and thus are disabled until a solution is found. See the comment in 
TestStandardContextResources.java

Added:
    
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java   
(with props)
    tomcat/trunk/test/webapp-3.0-fragments/
    tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/
    tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/lib/
    tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/lib/resources.jar   (with 
props)
    tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml   (with props)
    tomcat/trunk/test/webapp-3.0-fragments/folder/
    tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp   (with props)
    tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp   (with props)
    tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp   (with props)

Added: 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java?rev=939253&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java 
(added)
+++ 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java 
Thu Apr 29 10:24:14 2010
@@ -0,0 +1,153 @@
+/*
+ *  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.
+ */
+
+package org.apache.catalina.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestStandardContextResources extends TomcatBaseTest {
+
+    public void testResources() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0-fragments");
+        // app dir is relative to server home
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+        tomcat.start();
+
+        if (false) {
+            // FIXME: These tests are currently failing. See comment in 
testResources2() below.
+            
+        assertPageContains("/test/resourceA.jsp",
+                "<p>resourceA.jsp in the web application</p>");
+        assertPageContains("/test/resourceB.jsp",
+                "<p>resourceB.jsp in resources.jar</p>");
+        assertPageContains("/test/folder/resourceC.jsp",
+                "<p>resourceC.jsp in the web application</p>");
+        assertPageContains("/test/folder/resourceD.jsp",
+                "<p>resourceD.jsp in resources.jar</p>");
+        assertPageContains("/test/folder/resourceE.jsp",
+                "<p>resourceE.jsp in the web application</p>");
+        }
+    }
+
+    public void testResources2() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0-fragments");
+        // app dir is relative to server home
+        StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
+                appDir.getAbsolutePath());
+
+        Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
+        ctx.addServletMapping("/getresource", "getresource");
+
+        tomcat.start();
+
+        // FIXME: These tests are currently failing.
+        //
+        // I do not have a fix yet, but I know the following:
+        // when trying to get "/resourceB.jsp" in 
ApplicationContext#getResource()
+        // an Exception is caught and silently swallowed. That exception is
+        //
+        // java.lang.IllegalStateException: zip file closed
+        // at java.util.jar.JarFile.getMetaInfEntryNames(Native Method)
+        // at java.util.jar.JarFile.maybeInstantiateVerifier(JarFile.java:277)
+        // at java.util.jar.JarFile.getInputStream(JarFile.java:381)
+        // at 
org.apache.naming.resources.WARDirContext$WARResource.streamContent(WARDirContext.java:951)
+        // at 
org.apache.naming.resources.ProxyDirContext.cacheLoad(ProxyDirContext.java:1578)
+        // at 
org.apache.naming.resources.ProxyDirContext.cacheLookup(ProxyDirContext.java:1458)
+        // at 
org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:292)
+        // at 
org.apache.catalina.core.ApplicationContext.getResource(ApplicationContext.java:506)
+        // at 
org.apache.catalina.core.ApplicationContextFacade.getResource(ApplicationContextFacade.java:196)
+        // at 
org.apache.catalina.core.TestStandardContextResources$GetResourceServlet.doGet(TestStandardContextResources.java:126)
+        //
+        if (false) {
+        
+        assertPageContains("/test/getresource?path=/resourceA.jsp",
+                "<p>resourceA.jsp in the web application</p>");
+        assertPageContains("/test/getresource?path=/resourceB.jsp",
+                "<p>resourceB.jsp in resources.jar</p>");
+        assertPageContains("/test/getresource?path=/folder/resourceC.jsp",
+                "<p>resourceC.jsp in the web application</p>");
+        assertPageContains("/test/getresource?path=/folder/resourceD.jsp",
+                "<p>resourceD.jsp in resources.jar</p>");
+        assertPageContains("/test/getresource?path=/folder/resourceE.jsp",
+                "<p>resourceE.jsp in the web application</p>");
+        }
+    }
+
+    /**
+     * A servlet that prints the requested resource. The path to the requested
+     * resource is passed as a parameter, <code>path</code>.
+     */
+    public static class GetResourceServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            resp.setContentType("text/plain");
+
+            ServletContext context = getServletContext();
+
+            // Check resources individually
+            URL url = context.getResource(req.getParameter("path"));
+            if (url == null) {
+                resp.getWriter().println("Not found");
+                return;
+            }
+
+            InputStream input = url.openStream();
+            OutputStream output = resp.getOutputStream();
+            try {
+                byte[] buffer = new byte[4000];
+                for (int len; (len = input.read(buffer)) > 0;) {
+                    output.write(buffer, 0, len);
+                }
+            } finally {
+                input.close();
+                output.close();
+            }
+        }
+    }
+
+    private void assertPageContains(String pageUrl, String expected)
+            throws IOException {
+        ByteChunk res = getUrl("http://localhost:"; + getPort() + pageUrl);
+
+        String result = res.toString();
+        assertTrue(result, result.indexOf(expected) > 0);
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/lib/resources.jar
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/lib/resources.jar?rev=939253&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/lib/resources.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml?rev=939253&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml (added)
+++ tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml Thu Apr 29 10:24:14 
2010
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<web-app xmlns="http://java.sun.com/xml/ns/javaee";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
+  version="3.0"
+  metadata-complete="false">  
+
+  <display-name>Tomcat Test Application</display-name>
+  <description>
+     Used as part of the Tomcat unit tests when a full web application is
+     required.
+  </description>
+</web-app>
\ No newline at end of file

Propchange: tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp?rev=939253&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp (added)
+++ tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp Thu Apr 29 
10:24:14 2010
@@ -0,0 +1,21 @@
+<%--
+ 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.
+--%>
+<%--
+  Resource file that is present both in the web application and in the
+  WEB-INF/lib/resources.jar file. The one in the web application should win.
+--%>
+<p>resourceC.jsp in the web application</p>

Propchange: tomcat/trunk/test/webapp-3.0-fragments/folder/resourceC.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp?rev=939253&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp (added)
+++ tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp Thu Apr 29 
10:24:14 2010
@@ -0,0 +1,20 @@
+<%--
+ 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.
+--%>
+<%--
+  Resource file that is present in the web application only.
+--%>
+<p>resourceE.jsp in the web application</p>

Propchange: tomcat/trunk/test/webapp-3.0-fragments/folder/resourceE.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp?rev=939253&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp (added)
+++ tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp Thu Apr 29 10:24:14 
2010
@@ -0,0 +1,21 @@
+<%--
+ 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.
+--%>
+<%--
+  Resource file that is present both in the web application and in the
+  WEB-INF/lib/resources.jar file. The one in the web application should win.
+--%>
+<p>resourceA.jsp in the web application</p>

Propchange: tomcat/trunk/test/webapp-3.0-fragments/resourceA.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to