tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1384757 - in /tomcat/sandbox/trunk-resources: java/org/apache/catalina/webresources/ test/org/apache/catalina/webresources/
Date Fri, 14 Sep 2012 13:18:41 GMT
Author: markt
Date: Fri Sep 14 13:18:40 2012
New Revision: 1384757

URL: http://svn.apache.org/viewvc?rev=1384757&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=1384757&r1=1384756&r2=1384757&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 13:18:40 2012
@@ -133,16 +133,29 @@ 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
+            pathInJar = pathInJar.substring(1);
             Enumeration<JarEntry> entries = base.entries();
             while (entries.hasMoreElements()) {
                 JarEntry entry = entries.nextElement();
                 String name = entry.getName();
-                if (name.startsWith(pathInJar)) {
-                    int i = name.lastIndexOf('/');
-                    if (i > -1) {
-                        name = name.substring(i);
+                if (name.length() > pathInJar.length() &&
+                        name.startsWith(pathInJar)) {
+                    if (name.charAt(name.length() - 1) == '/') {
+                        name = name.substring(
+                                pathInJar.length(), name.length() - 1);
+                    } else {
+                        name = name.substring(pathInJar.length());
+                    }
+                    if (name.length() == 0) {
+                        continue;
+                    }
+                    if (name.charAt(0) == '/') {
+                        name = name.substring(1);
+                    }
+                    if (name.length() > 0 && name.lastIndexOf('/') == -1) {
+                        result.add(name);
                     }
-                    result.add(name);
                 }
             }
         }

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=1384757&r1=1384756&r2=1384757&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 13:18:40 2012
@@ -16,6 +16,9 @@
  */
 package org.apache.catalina.webresources;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -43,6 +46,8 @@ public abstract class AbstractTestResour
         resourceSet.getResource("");
     }
 
+    //------------------------------------------------------------ getResource()
+
     @Test
     public final void testGetResourceRoot() {
         WebResource webResource = resourceSet.getResource(getMount() + "/");
@@ -76,4 +81,61 @@ public abstract class AbstractTestResour
         Assert.assertEquals(
                 getMount() + "/d1/d1-f1.txt", webResource.getWebappPath());
     }
+
+    //------------------------------------------------------------------- list()
+
+    @Test(expected = IllegalArgumentException.class)
+    public final void testListEmpty() {
+        resourceSet.list("");
+    }
+
+    @Test
+    public final void testListRoot() {
+        String[] results = resourceSet.list(getMount() + "/");
+
+        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 final void testListDirA() {
+        String[] results = resourceSet.list(getMount() + "/d1");
+
+        Set<String> expected = new HashSet<>();
+        expected.add("d1-f1.txt");
+
+        for (String result : results) {
+            Assert.assertTrue(result, expected.remove(result));
+        }
+        Assert.assertEquals(0, expected.size());
+    }
+
+    @Test
+    public final void testListDirB() {
+        String[] results = resourceSet.list(getMount() + "/d1/");
+
+        Set<String> expected = new HashSet<>();
+        expected.add("d1-f1.txt");
+
+        for (String result : results) {
+            Assert.assertTrue(result, expected.remove(result));
+        }
+        Assert.assertEquals(0, expected.size());
+    }
+
+    @Test
+    public final void testListFile() {
+        String[] results = resourceSet.list(getMount() + "/d1/d1-f1.txt");
+
+        Assert.assertNotNull(results);
+        Assert.assertEquals(0, results.length);
+    }
 }

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=1384757&r1=1384756&r2=1384757&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 13:18:40 2012
@@ -34,4 +34,12 @@ public abstract class AbstractTestResour
         WebResource webResource = resourceSet.getResource("/");
         Assert.assertFalse(webResource.exists());
     }
+
+    @Test
+    public final void testListAbove() {
+        String[] results = resourceSet.list("/");
+
+        Assert.assertNotNull(results);
+        Assert.assertEquals(0, results.length);
+    }
 }

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=1384757&r1=1384756&r2=1384757&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 13:18:40 2012
@@ -36,61 +36,6 @@ public class TestDirResourceSet extends 
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void testListEmpty() {
-        resourceSet.list("");
-    }
-
-    @Test
-    public void testListRoot() {
-        String[] results = resourceSet.list("/");
-
-        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 testListDirA() {
-        String[] results = resourceSet.list("/d1");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListDirB() {
-        String[] results = resourceSet.list("/d1/");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListFile() {
-        String[] results = resourceSet.list("/d1/d1-f1.txt");
-
-        Assert.assertNotNull(results);
-        Assert.assertEquals(0, results.length);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
     public void testListWebAppPathsEmpty() {
         resourceSet.listWebAppPaths("");
     }

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=1384757&r1=1384756&r2=1384757&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 13:18:40 2012
@@ -36,69 +36,6 @@ public class TestDirResourceSetMount ext
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void testListEmpty() {
-        resourceSet.list("");
-    }
-
-    @Test
-    public void testListAbove() {
-        String[] results = resourceSet.list("/");
-
-        Assert.assertNotNull(results);
-        Assert.assertEquals(0, results.length);
-    }
-
-    @Test
-    public void testListRoot() {
-        String[] results = resourceSet.list("/mount");
-
-        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 testListDirA() {
-        String[] results = resourceSet.list("/mount/d1");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListDirB() {
-        String[] results = resourceSet.list("/mount/d1/");
-
-        Set<String> expected = new HashSet<>();
-        expected.add("d1-f1.txt");
-
-        for (String result : results) {
-            Assert.assertTrue(result, expected.remove(result));
-        }
-        Assert.assertEquals(0, expected.size());
-    }
-
-    @Test
-    public void testListFile() {
-        String[] results = resourceSet.list("/mount/d1/d1-f1.txt");
-
-        Assert.assertNotNull(results);
-        Assert.assertEquals(0, results.length);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
     public void testListWebAppPathsEmpty() {
         resourceSet.listWebAppPaths("");
     }



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


Mime
View raw message