Author: markt
Date: Thu Sep 13 21:02:40 2012
New Revision: 1384525
URL: http://svn.apache.org/viewvc?rev=1384525&view=rev
Log:
Complete unit tests for DirResourceSet mounted at the root of the web
application
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.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=1384525&r1=1384524&r2=1384525&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
Thu Sep 13 21:02:40 2012
@@ -144,10 +144,20 @@ public class DirResourceSet extends Abst
@Override
public boolean write(String path, InputStream is) {
+ checkPath(path);
+
+ if (is == null) {
+ throw new NullPointerException(
+ sm.getString("dirResourceSet.writeNpe"));
+ }
+
File dest = new File(base, path);
+ if (dest.exists()) {
+ throw new IllegalArgumentException(
+ sm.getString("dirResourceSet.writeExists"));
+ }
- try {
- FileOutputStream fos = new FileOutputStream(dest);
+ try (FileOutputStream fos = new FileOutputStream(dest)) {
IOTools.flow(is, fos);
} catch (IOException ioe) {
return false;
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1384525&r1=1384524&r2=1384525&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
Thu Sep 13 21:02:40 2012
@@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+dirResourceSet.writeExists=The target of the write already exists
+dirResourceSet.writeNpe=The input stream may not be null
+
fileResource.getCanonicalPathFail=Unable to determine the canonical path for
the resource [{0}]
fileResource.getCreationFail=Unable to determine the creation time for the
resource [{0}]
fileResource.getUrlFail=Unable to determine a URL for the resource [{0}]
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=1384525&r1=1384524&r2=1384525&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
Thu Sep 13 21:02:40 2012
@@ -16,7 +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;
@@ -213,14 +215,51 @@ public class TestDirResourceSet {
Assert.assertTrue(dirResourceSet.mkdir("/new-test"));
File file = new File("test/webresources/new-test");
- Assert.assertTrue(file.exists());
+ Assert.assertTrue(file.isDirectory());
Assert.assertTrue(file.delete());
}
- /* TODO Implement this test
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteEmpty() {
+ dirResourceSet.write("", null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteRoot() {
+ InputStream is = new ByteArrayInputStream("test".getBytes());
+ dirResourceSet.write("/", is);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteDirA() {
+ InputStream is = new ByteArrayInputStream("test".getBytes());
+ dirResourceSet.write("/d1", is);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteDirB() {
+ InputStream is = new ByteArrayInputStream("test".getBytes());
+ dirResourceSet.write("/d1/", is);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWriteFile() {
+ InputStream is = new ByteArrayInputStream("test".getBytes());
+ dirResourceSet.write("/d1/d1-f1.txt", is);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testWriteNew() {
+ dirResourceSet.write("/new-test", null);
+ }
+
@Test
public void testWrite() {
- Assert.fail("Not yet implemented");
+ InputStream is = new ByteArrayInputStream("test".getBytes());
+ Assert.assertTrue(dirResourceSet.write("/new-test", is));
+
+ File file = new File("test/webresources/new-test");
+ Assert.assertTrue(file.exists());
+ Assert.assertTrue(file.delete());
}
- */
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]