tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1384821 - in /tomcat/sandbox/trunk-resources: java/org/apache/catalina/webresources/ test/org/apache/catalina/webresources/
Date Fri, 14 Sep 2012 15:28:44 GMT
Author: markt
Date: Fri Sep 14 15:28:43 2012
New Revision: 1384821

URL: http://svn.apache.org/viewvc?rev=1384821&view=rev
Log:
More unit test reafctoring, more Jar resource handling bugs

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java?rev=1384821&r1=1384820&r2=1384821&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java
Fri Sep 14 15:28:43 2012
@@ -170,13 +170,26 @@ public class JarResourceSet extends Abst
         if (path.startsWith(webAppMount)) {
             String pathInJar =
                     internalPath + path.substring(webAppMount.length());
+            // Always strip off the leading '/' to get the JAR path and make
+            // sure it ends in '/'
+            if (pathInJar.charAt(pathInJar.length() - 1) == '/') {
+                pathInJar = pathInJar.substring(1);
+            } else {
+                pathInJar = pathInJar.substring(1) + '/';
+            }
             Enumeration<JarEntry> entries = base.entries();
             while (entries.hasMoreElements()) {
                 JarEntry entry = entries.nextElement();
                 String name = entry.getName();
-                if (name.startsWith(pathInJar)) {
-                    result.add(webAppMount +
-                            name.substring(internalPath.length()));
+                if (name.length() > pathInJar.length() &&
+                        name.startsWith(pathInJar)) {
+                    int nextSlash = name.indexOf('/', pathInJar.length());
+                    if (nextSlash == -1 || nextSlash == name.length() - 1) {
+                        if (name.startsWith(pathInJar)) {
+                            result.add(webAppMount + '/' +
+                                    name.substring(internalPath.length()));
+                        }
+                    }
                 }
             }
         }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java?rev=1384821&r1=1384820&r2=1384821&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java
Fri Sep 14 15:28:43 2012
@@ -138,4 +138,61 @@ public abstract class AbstractTestResour
         Assert.assertNotNull(results);
         Assert.assertEquals(0, results.length);
     }
+
+    //-------------------------------------------------------- listWebAppPaths()
+
+    @Test(expected = IllegalArgumentException.class)
+    public final void testListWebAppPathsEmpty() {
+        resourceSet.listWebAppPaths("");
+    }
+
+    @Test
+    public final void testListWebAppPathsRoot() {
+        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/");
+
+        Set<String> expected = new HashSet<>();
+        expected.add(getMount() + "/d1/");
+        expected.add(getMount() + "/d2/");
+        expected.add(getMount() + "/f1.txt");
+        expected.add(getMount() + "/f2.txt");
+
+        for (String result : results) {
+            Assert.assertTrue(result, expected.remove(result));
+        }
+        Assert.assertEquals(0, expected.size());
+    }
+
+    @Test
+    public final void testListWebAppPathsDirA() {
+        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/d1");
+
+        Set<String> expected = new HashSet<>();
+        expected.add(getMount() + "/d1/d1-f1.txt");
+
+        for (String result : results) {
+            Assert.assertTrue(result, expected.remove(result));
+        }
+        Assert.assertEquals(0, expected.size());
+    }
+
+    @Test
+    public final void testListWebAppPathsDirB() {
+        Set<String> results = resourceSet.listWebAppPaths(getMount() + "/d1/");
+
+        Set<String> expected = new HashSet<>();
+        expected.add(getMount() + "/d1/d1-f1.txt");
+
+        for (String result : results) {
+            Assert.assertTrue(result, expected.remove(result));
+        }
+        Assert.assertEquals(0, expected.size());
+    }
+
+    @Test
+    public final void testListWebAppPathsFile() {
+        Set<String> results =
+                resourceSet.listWebAppPaths(getMount() + "/d1/d1-f1.txt");
+
+        Assert.assertEquals(0, results.size());
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java?rev=1384821&r1=1384820&r2=1384821&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java
Fri Sep 14 15:28:43 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.catalina.webresources;
 
+import java.util.Set;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -42,4 +44,11 @@ public abstract class AbstractTestResour
         Assert.assertNotNull(results);
         Assert.assertEquals(0, results.length);
     }
+
+    @Test
+    public final void testListWebAppPathsAbove() {
+        Set<String> results = resourceSet.listWebAppPaths("/");
+
+        Assert.assertEquals(0, results.size());
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java?rev=1384821&r1=1384820&r2=1384821&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java
Fri Sep 14 15:28:43 2012
@@ -19,8 +19,6 @@ package org.apache.catalina.webresources
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -36,60 +34,6 @@ public class TestDirResourceSet extends 
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void testListWebAppPathsEmpty() {
-        resourceSet.listWebAppPaths("");
-    }
-
-    @Test
-    public void testListWebAppPathsRoot() {
-        Set<String> results = resourceSet.listWebAppPaths("/");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/d1/");
-        expected.add("/d2/");
-        expected.add("/f1.txt");
-        expected.add("/f2.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsDirA() {
-        Set<String> results = resourceSet.listWebAppPaths("/d1");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/d1/d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsDirB() {
-        Set<String> results = resourceSet.listWebAppPaths("/d1/");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/d1/d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsFile() {
-        Set<String> results = resourceSet.listWebAppPaths("/d1/d1-f1.txt");
-
-        Assert.assertEquals(0, results.size());
-    }
-
-    @Test(expected = IllegalArgumentException.class)
     public void testMkdirEmpty() {
         resourceSet.mkdir("");
     }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java?rev=1384821&r1=1384820&r2=1384821&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java
Fri Sep 14 15:28:43 2012
@@ -19,8 +19,6 @@ package org.apache.catalina.webresources
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -36,68 +34,6 @@ public class TestDirResourceSetMount ext
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void testListWebAppPathsEmpty() {
-        resourceSet.listWebAppPaths("");
-    }
-
-    @Test
-    public void testListWebAppPathsAbove() {
-        Set<String> results = resourceSet.listWebAppPaths("/");
-
-        Assert.assertEquals(0, results.size());
-    }
-
-    @Test
-    public void testListWebAppPathsRoot() {
-        Set<String> results = resourceSet.listWebAppPaths("/mount");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/mount/d1/");
-        expected.add("/mount/d2/");
-        expected.add("/mount/f1.txt");
-        expected.add("/mount/f2.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsDirA() {
-        Set<String> results = resourceSet.listWebAppPaths("/mount/d1");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/mount/d1/d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsDirB() {
-        Set<String> results = resourceSet.listWebAppPaths("/mount/d1/");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("/mount/d1/d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListWebAppPathsFile() {
-        Set<String> results =
-                resourceSet.listWebAppPaths("/mount/d1/d1-f1.txt");
-
-        Assert.assertEquals(0, results.size());
-    }
-
-    @Test(expected = IllegalArgumentException.class)
     public void testMkdirEmpty() {
         resourceSet.mkdir("");
     }



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


Mime
View raw message