tomcat-dev mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1384827&view=rev
Log:
Complete the unit tests for DirResourceSet and JarResourceSet

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
    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
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java?rev=1384827&r1=1384826&r2=1384827&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
Fri Sep 14 15:47:07 2012
@@ -159,8 +159,7 @@ public class DirResourceSet extends Abst
         }
 
         if (dest.exists()) {
-            throw new IllegalArgumentException(
-                    sm.getString("dirResourceSet.writeExists"));
+            return false;
         }
 
         try (FileOutputStream fos = new FileOutputStream(dest)) {

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=1384827&r1=1384826&r2=1384827&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:47:07 2012
@@ -208,6 +208,11 @@ public class JarResourceSet extends Abst
     public boolean write(String path, InputStream is) {
         checkPath(path);
 
+        if (is == null) {
+            throw new NullPointerException(
+                    sm.getString("dirResourceSet.writeNpe"));
+        }
+
         return false;
     }
 }

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=1384827&r1=1384826&r2=1384827&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:47:07 2012
@@ -16,6 +16,9 @@
  */
 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;
 
@@ -31,6 +34,7 @@ public abstract class AbstractTestResour
     protected WebResourceSet resourceSet;
 
     protected abstract WebResourceSet getWebResourceSet();
+    protected abstract boolean isWriteable();
 
     public String getMount() {
         return "";
@@ -195,4 +199,95 @@ public abstract class AbstractTestResour
 
         Assert.assertEquals(0, results.size());
     }
+
+    //------------------------------------------------------------------ mkdir()
+
+    @Test(expected = IllegalArgumentException.class)
+    public final void testMkdirEmpty() {
+        resourceSet.mkdir("");
+    }
+
+    @Test
+    public final void testMkdirRoot() {
+        Assert.assertFalse(resourceSet.mkdir(getMount() + "/"));
+    }
+
+    @Test
+    public final void testMkdirDirA() {
+        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1"));
+    }
+
+    @Test
+    public final void testMkdirDirB() {
+        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1/"));
+    }
+
+    @Test
+    public final void testMkdirFile() {
+        Assert.assertFalse(resourceSet.mkdir(getMount() + "/d1/d1-f1.txt"));
+    }
+
+    @Test
+    public final void testMkdirNew() {
+        if (isWriteable()) {
+            Assert.assertTrue(resourceSet.mkdir(getMount() + "/new-test"));
+
+            File file = new File("test/webresources/dir1/new-test");
+            Assert.assertTrue(file.isDirectory());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.assertFalse(resourceSet.mkdir(getMount() + "/new-test"));
+        }
+    }
+
+    //------------------------------------------------------------------ write()
+
+    @Test(expected = IllegalArgumentException.class)
+    public final void testWriteEmpty() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        resourceSet.write("", is);
+    }
+
+    @Test
+    public final void testWriteRoot() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        Assert.assertFalse(resourceSet.write(getMount() + "/", is));
+    }
+
+    @Test
+    public final void testWriteDirA() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        Assert.assertFalse(resourceSet.write(getMount() + "/d1", is));
+    }
+
+    @Test
+    public final void testWriteDirB() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        Assert.assertFalse(resourceSet.write(getMount() + "/d1/", is));
+    }
+
+    @Test
+    public final void testWriteFile() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        Assert.assertFalse(resourceSet.write(getMount() + "/d1/d1-f1.txt", is));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public final void testWriteNew() {
+        resourceSet.write(getMount() + "/new-test", null);
+    }
+
+    @Test
+    public final void testWrite() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        if (isWriteable()) {
+            Assert.assertTrue(resourceSet.write(getMount() + "/new-test", is));
+
+            File file = new File("test/webresources/dir1/new-test");
+            Assert.assertTrue(file.exists());
+            Assert.assertTrue(file.delete());
+        } else {
+            Assert.assertFalse(resourceSet.write(getMount() + "/new-test", is));
+        }
+    }
 }

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=1384827&r1=1384826&r2=1384827&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:47:07 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.catalina.webresources;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.util.Set;
 
 import org.junit.Assert;
@@ -51,4 +53,15 @@ public abstract class AbstractTestResour
 
         Assert.assertEquals(0, results.size());
     }
+
+    @Test
+    public void testMkdirAbove() {
+        Assert.assertFalse(resourceSet.mkdir("/"));
+    }
+
+    @Test
+    public void testWriteAbove() {
+        InputStream is = new ByteArrayInputStream("test".getBytes());
+        Assert.assertFalse(resourceSet.write("/", is));
+    }
 }

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=1384827&r1=1384826&r2=1384827&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:47:07 2012
@@ -16,12 +16,7 @@
  */
 package org.apache.catalina.webresources;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.InputStream;
-
-import org.junit.Assert;
-import org.junit.Test;
 
 import org.apache.catalina.WebResourceSet;
 
@@ -33,82 +28,8 @@ public class TestDirResourceSet extends 
         return new DirResourceSet(new TesterWebResourceRoot(), f, "", "");
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testMkdirEmpty() {
-        resourceSet.mkdir("");
-    }
-
-    @Test
-    public void testMkdirRoot() {
-        Assert.assertFalse(resourceSet.mkdir("/"));
-    }
-
-    @Test
-    public void testMkdirDirA() {
-        Assert.assertFalse(resourceSet.mkdir("/d1"));
-    }
-
-    @Test
-    public void testMkdirDirB() {
-        Assert.assertFalse(resourceSet.mkdir("/d1/"));
-    }
-
-    @Test
-    public void testMkdirFile() {
-        Assert.assertFalse(resourceSet.mkdir("/d1/d1-f1.txt"));
-    }
-
-    @Test
-    public void testMkdirNew() {
-        Assert.assertTrue(resourceSet.mkdir("/new-test"));
-
-        File file = new File("test/webresources/dir1/new-test");
-        Assert.assertTrue(file.isDirectory());
-        Assert.assertTrue(file.delete());
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteEmpty() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteRoot() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteDirA() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/d1", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteDirB() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/d1/", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteFile() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/d1/d1-f1.txt", is);
-    }
-
-    @Test(expected = NullPointerException.class)
-    public void testWriteNew() {
-        resourceSet.write("/new-test", null);
-    }
-
-    @Test
-    public void testWrite() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertTrue(resourceSet.write("/new-test", is));
-
-        File file = new File("test/webresources/dir1/new-test");
-        Assert.assertTrue(file.exists());
-        Assert.assertTrue(file.delete());
+    @Override
+    protected boolean isWriteable() {
+        return true;
     }
 }

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=1384827&r1=1384826&r2=1384827&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:47:07 2012
@@ -16,12 +16,7 @@
  */
 package org.apache.catalina.webresources;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.InputStream;
-
-import org.junit.Assert;
-import org.junit.Test;
 
 import org.apache.catalina.WebResourceSet;
 
@@ -33,93 +28,8 @@ public class TestDirResourceSetMount ext
         return new DirResourceSet(new TesterWebResourceRoot(), f, "/mount", "");
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testMkdirEmpty() {
-        resourceSet.mkdir("");
-    }
-
-    @Test
-    public void testMkdirAbove() {
-        Assert.assertFalse(resourceSet.mkdir("/"));
-    }
-
-    @Test
-    public void testMkdirRoot() {
-        Assert.assertFalse(resourceSet.mkdir("/mount"));
-    }
-
-    @Test
-    public void testMkdirDirA() {
-        Assert.assertFalse(resourceSet.mkdir("/mount/d1"));
-    }
-
-    @Test
-    public void testMkdirDirB() {
-        Assert.assertFalse(resourceSet.mkdir("/mount/d1/"));
-    }
-
-    @Test
-    public void testMkdirFile() {
-        Assert.assertFalse(resourceSet.mkdir("/mount/d1/d1-f1.txt"));
-    }
-
-    @Test
-    public void testMkdirNew() {
-        Assert.assertTrue(resourceSet.mkdir("/mount/new-test"));
-
-        File file = new File("test/webresources/dir1/new-test");
-        Assert.assertTrue(file.isDirectory());
-        Assert.assertTrue(file.delete());
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteEmpty() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("", is);
-   }
-
-    @Test
-    public void testWriteAbove() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertFalse(resourceSet.write("/", is));
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteRoot() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/mount", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteDirA() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/mount/d1", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteDirB() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/mount/d1/", is);
-    }
-
-    @Test(expected = IllegalArgumentException.class)
-    public void testWriteFile() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        resourceSet.write("/mount/d1/d1-f1.txt", is);
-    }
-
-    @Test(expected = NullPointerException.class)
-    public void testWriteNew() {
-        resourceSet.write("/mount/new-test", null);
-    }
-
-    @Test
-    public void testWrite() {
-        InputStream is = new ByteArrayInputStream("test".getBytes());
-        Assert.assertTrue(resourceSet.write("/mount/new-test", is));
-
-        File file = new File("test/webresources/dir1/new-test");
-        Assert.assertTrue(file.exists());
-        Assert.assertTrue(file.delete());
+    @Override
+    protected boolean isWriteable() {
+        return true;
     }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java?rev=1384827&r1=1384826&r2=1384827&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java
Fri Sep 14 15:47:07 2012
@@ -28,4 +28,9 @@ public class TestJarResourceSet extends 
         return new JarResourceSet(
                 new TesterWebResourceRoot(), f, "", "");
     }
+
+    @Override
+    protected boolean isWriteable() {
+        return false;
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java?rev=1384827&r1=1384826&r2=1384827&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java
Fri Sep 14 15:47:07 2012
@@ -28,4 +28,8 @@ public class TestJarResourceSetInternal 
                 new TesterWebResourceRoot(), f, "", "/dir1");
     }
 
+    @Override
+    protected boolean isWriteable() {
+        return false;
+    }
 }

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java?rev=1384827&r1=1384826&r2=1384827&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java
Fri Sep 14 15:47:07 2012
@@ -28,4 +28,9 @@ public class TestJarResourceSetMount ext
         return new JarResourceSet(
                 new TesterWebResourceRoot(), f, "/mount", "");
     }
+
+    @Override
+    protected boolean isWriteable() {
+        return false;
+    }
 }



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


Mime
View raw message