Author: markt Date: Fri Sep 14 12:57:36 2012 New Revision: 1384748 URL: http://svn.apache.org/viewvc?rev=1384748&view=rev Log: Start to refactor unit tests to reduce duplication. Fix failures for Jar based resources identified so far.
Added: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java (with props) tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java (with props) tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java (with props) tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java (with props) tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java (with props) tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java (with props) tomcat/sandbox/trunk-resources/test/webresources/dir1-internal.jar (with props) tomcat/sandbox/trunk-resources/test/webresources/dir1.jar (with props) Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceSet.java tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSet.java tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetMount.java Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java?rev=1384748&r1=1384747&r2=1384748&view=diff ============================================================================== --- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java (original) +++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResource.java Fri Sep 14 12:57:36 2012 @@ -34,13 +34,30 @@ public class JarResource extends Abstrac private final JarFile base; private final String baseUrl; private final JarEntry resource; + private final String name; public JarResource(WebResourceRoot root, JarFile base, String baseUrl, - JarEntry jarEntry, String webAppPath) { + JarEntry jarEntry, String internalPath, String webAppPath) { super(root, webAppPath); this.base = base; this.baseUrl = "jar:" + baseUrl; this.resource = jarEntry; + + String resourceName = resource.getName(); + if (resourceName.charAt(resourceName.length() - 1) == '/') { + resourceName = resourceName.substring(0, resourceName.length() - 1); + } + if (internalPath.length() > 0 && resourceName.equals( + internalPath.subSequence(1, internalPath.length()))) { + name = ""; + } else { + int index = resourceName.lastIndexOf('/'); + if (index == -1) { + name = resourceName; + } else { + name = resourceName.substring(index + 1); + } + } } @Override @@ -70,13 +87,7 @@ public class JarResource extends Abstrac @Override public String getName() { - String path = resource.getName(); - int index = path.lastIndexOf('/'); - if (index == -1) { - return path; - } else { - return path.substring(index + 1); - } + return name; } @Override Added: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java?rev=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java (added) +++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,114 @@ +/* + * 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.webresources; + +import java.io.File; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.catalina.WebResourceRoot; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; + +public class JarResourceRoot extends AbstractResource { + + private static final Log log = LogFactory.getLog(JarResourceRoot.class); + + private final File base; + private final String baseUrl; + + public JarResourceRoot(WebResourceRoot root, File base, String baseUrl, + String webAppPath) { + super(root, webAppPath); + this.base = base; + this.baseUrl = "jar:" + baseUrl; + } + + @Override + public long getLastModified() { + return base.lastModified(); + } + + @Override + public boolean exists() { + return true; + } + + @Override + public boolean isDirectory() { + return true; + } + + @Override + public boolean isFile() { + return false; + } + + @Override + public boolean delete() { + return false; + } + + @Override + public String getName() { + return ""; + } + + @Override + public long getContentLength() { + return -1; + } + + @Override + public String getCanonicalPath() { + return null; + } + + @Override + public boolean canRead() { + return true; + } + + @Override + public InputStream getInputStream() { + return null; + } + + @Override + public long getCreation() { + return base.lastModified(); + } + + @Override + public URL getURL() { + try { + return new URL(baseUrl + "!/"); + } catch (MalformedURLException e) { + if (log.isDebugEnabled()) { + log.debug(sm.getString("fileResource.getUrlFail", + "", baseUrl), e); + } + return null; + } + } + + @Override + protected Log getLog() { + return log; + } +} Propchange: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/JarResourceRoot.java ------------------------------------------------------------------------------ svn:eol-style = native 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=1384748&r1=1384747&r2=1384748&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 12:57:36 2012 @@ -73,14 +73,52 @@ public class JarResourceSet extends Abst @Override public WebResource getResource(String path) { + checkPath(path); + + /* + * Implementation notes + * + * The path parameter passed into this method always starts with '/'. + * + * The path parameter passed into this method may or may not end with a + * '/'. JarFile.getEntry() will return a matching directory entry + * whether or not the name ends in a '/'. However, if the entry is + * requested without the '/' subsequent calls to JarEntry.isDirectory() + * will return false. + * + * Paths in JARs never start with '/'. Leading '/' need to be removed + * before any JarFile.getEntry() call. + */ + + // If the JAR has been mounted below the web application root, return + // an empty resource for requests outside of the mount point. + if (path.startsWith(webAppMount)) { - String pathInJar = - internalPath + path.substring(webAppMount.length()); - JarEntry jarEntry = base.getJarEntry(pathInJar.toString()); - if (jarEntry == null) { - return new EmptyResource(root, path); + String pathInJar = internalPath + path.substring( + webAppMount.length(), path.length()); + // Always strip off the leading '/' to get the JAR path + pathInJar = pathInJar.substring(1); + if (pathInJar.equals("")) { + // Special case + return new JarResourceRoot(root, new File(base.getName()), + pathInJar, path); } else { - return new JarResource(root, base, baseUrl, jarEntry, path); + JarEntry jarEntry = null; + if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) { + jarEntry = base.getJarEntry(pathInJar + '/'); + if (jarEntry != null) { + path = path + '/'; + } + } + if (jarEntry == null) { + jarEntry = base.getJarEntry(pathInJar); + } + if (jarEntry == null) { + return new EmptyResource(root, path); + } else { + return new JarResource(root, base, baseUrl, jarEntry, + internalPath, path); + } } } else { return new EmptyResource(root, path); @@ -89,6 +127,8 @@ public class JarResourceSet extends Abst @Override public String[] list(String path) { + checkPath(path); + ArrayList<String> result = new ArrayList<>(); if (path.startsWith(webAppMount)) { String pathInJar = @@ -111,6 +151,8 @@ public class JarResourceSet extends Abst @Override public Set<String> listWebAppPaths(String path) { + checkPath(path); + ResourceSet<String> result = new ResourceSet<>(); if (path.startsWith(webAppMount)) { String pathInJar = @@ -131,11 +173,15 @@ public class JarResourceSet extends Abst @Override public boolean mkdir(String path) { + checkPath(path); + return false; } @Override public boolean write(String path, InputStream is) { + checkPath(path); + return false; } } Added: 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=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java (added) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,79 @@ +/* + * 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.webresources; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import org.apache.catalina.WebResource; +import org.apache.catalina.WebResourceSet; + +public abstract class AbstractTestResourceSet { + + protected WebResourceSet resourceSet; + + protected abstract WebResourceSet getWebResourceSet(); + + public String getMount() { + return ""; + } + + @Before + public final void setup() { + resourceSet = getWebResourceSet(); + } + + @Test(expected = IllegalArgumentException.class) + public final void testGetResourceEmpty() { + resourceSet.getResource(""); + } + + @Test + public final void testGetResourceRoot() { + WebResource webResource = resourceSet.getResource(getMount() + "/"); + Assert.assertTrue(webResource.isDirectory()); + Assert.assertEquals("", webResource.getName()); + Assert.assertEquals(getMount() + "/", webResource.getWebappPath()); + } + + @Test + public final void testGetResourceDirA() { + WebResource webResource = resourceSet.getResource(getMount() + "/d1"); + Assert.assertTrue(webResource.isDirectory()); + Assert.assertEquals("d1", webResource.getName()); + Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath()); + } + + @Test + public final void testGetResourceDirB() { + WebResource webResource = resourceSet.getResource(getMount() + "/d1/"); + Assert.assertTrue(webResource.isDirectory()); + Assert.assertEquals("d1", webResource.getName()); + Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath()); + } + + @Test + public final void testGetResourceFile() { + WebResource webResource = + resourceSet.getResource(getMount() + "/d1/d1-f1.txt"); + Assert.assertTrue(webResource.isFile()); + Assert.assertEquals("d1-f1.txt", webResource.getName()); + Assert.assertEquals( + getMount() + "/d1/d1-f1.txt", webResource.getWebappPath()); + } +} Propchange: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSet.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java (added) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,37 @@ +/* + * 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.webresources; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.WebResource; + +public abstract class AbstractTestResourceSetMount + extends AbstractTestResourceSet { + + @Override + public final String getMount() { + return "/mount"; + } + + @Test + public final void testGetResourceAbove() { + WebResource webResource = resourceSet.getResource("/"); + Assert.assertFalse(webResource.exists()); + } +} Propchange: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/AbstractTestResourceSetMount.java ------------------------------------------------------------------------------ svn:eol-style = native 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=1384748&r1=1384747&r2=1384748&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 12:57:36 2012 @@ -23,67 +23,26 @@ import java.util.HashSet; import java.util.Set; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import org.apache.catalina.WebResource; +import org.apache.catalina.WebResourceSet; -public class TestDirResourceSet { +public class TestDirResourceSet extends AbstractTestResourceSet { - protected DirResourceSet dirResourceSet; - - @Before - public void setup() { + @Override + public WebResourceSet getWebResourceSet() { File f = new File("test/webresources/dir1"); - dirResourceSet = new DirResourceSet( - new TesterWebResourceRoot(), f, "", ""); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetResourceEmpty() { - dirResourceSet.getResource(""); - } - - @Test - public void testGetResourceRoot() { - WebResource webResource = dirResourceSet.getResource("/"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("", webResource.getName()); - Assert.assertEquals("/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceDirA() { - WebResource webResource = dirResourceSet.getResource("/d1"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("d1", webResource.getName()); - Assert.assertEquals("/d1/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceDirB() { - WebResource webResource = dirResourceSet.getResource("/d1/"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("d1", webResource.getName()); - Assert.assertEquals("/d1/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceFile() { - WebResource webResource = dirResourceSet.getResource("/d1/d1-f1.txt"); - Assert.assertTrue(webResource.isFile()); - Assert.assertEquals("d1-f1.txt", webResource.getName()); - Assert.assertEquals("/d1/d1-f1.txt", webResource.getWebappPath()); + return new DirResourceSet(new TesterWebResourceRoot(), f, "", ""); } @Test(expected = IllegalArgumentException.class) public void testListEmpty() { - dirResourceSet.list(""); + resourceSet.list(""); } @Test public void testListRoot() { - String[] results = dirResourceSet.list("/"); + String[] results = resourceSet.list("/"); Set<String> expected = new HashSet<>(); expected.add("d1"); @@ -99,7 +58,7 @@ public class TestDirResourceSet { @Test public void testListDirA() { - String[] results = dirResourceSet.list("/d1"); + String[] results = resourceSet.list("/d1"); Set<String> expected = new HashSet<>(); expected.add("d1-f1.txt"); @@ -112,7 +71,7 @@ public class TestDirResourceSet { @Test public void testListDirB() { - String[] results = dirResourceSet.list("/d1/"); + String[] results = resourceSet.list("/d1/"); Set<String> expected = new HashSet<>(); expected.add("d1-f1.txt"); @@ -125,7 +84,7 @@ public class TestDirResourceSet { @Test public void testListFile() { - String[] results = dirResourceSet.list("/d1/d1-f1.txt"); + String[] results = resourceSet.list("/d1/d1-f1.txt"); Assert.assertNotNull(results); Assert.assertEquals(0, results.length); @@ -133,12 +92,12 @@ public class TestDirResourceSet { @Test(expected = IllegalArgumentException.class) public void testListWebAppPathsEmpty() { - dirResourceSet.listWebAppPaths(""); + resourceSet.listWebAppPaths(""); } @Test public void testListWebAppPathsRoot() { - Set<String> results = dirResourceSet.listWebAppPaths("/"); + Set<String> results = resourceSet.listWebAppPaths("/"); Set<String> expected = new HashSet<>(); expected.add("/d1/"); @@ -154,7 +113,7 @@ public class TestDirResourceSet { @Test public void testListWebAppPathsDirA() { - Set<String> results = dirResourceSet.listWebAppPaths("/d1"); + Set<String> results = resourceSet.listWebAppPaths("/d1"); Set<String> expected = new HashSet<>(); expected.add("/d1/d1-f1.txt"); @@ -167,7 +126,7 @@ public class TestDirResourceSet { @Test public void testListWebAppPathsDirB() { - Set<String> results = dirResourceSet.listWebAppPaths("/d1/"); + Set<String> results = resourceSet.listWebAppPaths("/d1/"); Set<String> expected = new HashSet<>(); expected.add("/d1/d1-f1.txt"); @@ -180,39 +139,39 @@ public class TestDirResourceSet { @Test public void testListWebAppPathsFile() { - Set<String> results = dirResourceSet.listWebAppPaths("/d1/d1-f1.txt"); + Set<String> results = resourceSet.listWebAppPaths("/d1/d1-f1.txt"); Assert.assertEquals(0, results.size()); } @Test(expected = IllegalArgumentException.class) public void testMkdirEmpty() { - dirResourceSet.mkdir(""); + resourceSet.mkdir(""); } @Test public void testMkdirRoot() { - Assert.assertFalse(dirResourceSet.mkdir("/")); + Assert.assertFalse(resourceSet.mkdir("/")); } @Test public void testMkdirDirA() { - Assert.assertFalse(dirResourceSet.mkdir("/d1")); + Assert.assertFalse(resourceSet.mkdir("/d1")); } @Test public void testMkdirDirB() { - Assert.assertFalse(dirResourceSet.mkdir("/d1/")); + Assert.assertFalse(resourceSet.mkdir("/d1/")); } @Test public void testMkdirFile() { - Assert.assertFalse(dirResourceSet.mkdir("/d1/d1-f1.txt")); + Assert.assertFalse(resourceSet.mkdir("/d1/d1-f1.txt")); } @Test public void testMkdirNew() { - Assert.assertTrue(dirResourceSet.mkdir("/new-test")); + Assert.assertTrue(resourceSet.mkdir("/new-test")); File file = new File("test/webresources/dir1/new-test"); Assert.assertTrue(file.isDirectory()); @@ -222,42 +181,42 @@ public class TestDirResourceSet { @Test(expected = IllegalArgumentException.class) public void testWriteEmpty() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("", is); + resourceSet.write("", is); } @Test(expected = IllegalArgumentException.class) public void testWriteRoot() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/", is); + resourceSet.write("/", is); } @Test(expected = IllegalArgumentException.class) public void testWriteDirA() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/d1", is); + resourceSet.write("/d1", is); } @Test(expected = IllegalArgumentException.class) public void testWriteDirB() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/d1/", is); + resourceSet.write("/d1/", is); } @Test(expected = IllegalArgumentException.class) public void testWriteFile() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/d1/d1-f1.txt", is); + resourceSet.write("/d1/d1-f1.txt", is); } @Test(expected = NullPointerException.class) public void testWriteNew() { - dirResourceSet.write("/new-test", null); + resourceSet.write("/new-test", null); } @Test public void testWrite() { InputStream is = new ByteArrayInputStream("test".getBytes()); - Assert.assertTrue(dirResourceSet.write("/new-test", is)); + Assert.assertTrue(resourceSet.write("/new-test", is)); File file = new File("test/webresources/dir1/new-test"); Assert.assertTrue(file.exists()); Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java?rev=1384748&r1=1384747&r2=1384748&view=diff ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java (original) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestDirResourceSetInternal.java Fri Sep 14 12:57:36 2012 @@ -18,13 +18,14 @@ package org.apache.catalina.webresources import java.io.File; +import org.apache.catalina.WebResourceSet; + public class TestDirResourceSetInternal extends TestDirResourceSet { @Override - public void setup() { - File f = new File("test"); - dirResourceSet = new DirResourceSet( + public WebResourceSet getWebResourceSet() { + File f = new File("test/"); + return new DirResourceSet( new TesterWebResourceRoot(), f, "", "webresources/dir1"); } - } 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=1384748&r1=1384747&r2=1384748&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 12:57:36 2012 @@ -23,74 +23,26 @@ import java.util.HashSet; import java.util.Set; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import org.apache.catalina.WebResource; +import org.apache.catalina.WebResourceSet; -public class TestDirResourceSetMount { +public class TestDirResourceSetMount extends AbstractTestResourceSetMount { - private DirResourceSet dirResourceSet; - - @Before - public void setup() { + @Override + public WebResourceSet getWebResourceSet() { File f = new File("test/webresources/dir1"); - dirResourceSet = new DirResourceSet( - new TesterWebResourceRoot(), f, "/mount", ""); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetResourceEmpty() { - dirResourceSet.getResource(""); - } - - @Test - public void testGetResourceAbove() { - WebResource webResource = dirResourceSet.getResource("/"); - Assert.assertFalse(webResource.exists()); - } - - @Test - public void testGetResourceRoot() { - WebResource webResource = dirResourceSet.getResource("/mount"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("mount", webResource.getName()); - Assert.assertEquals("/mount/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceDirA() { - WebResource webResource = dirResourceSet.getResource("/mount/d1"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("d1", webResource.getName()); - Assert.assertEquals("/mount/d1/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceDirB() { - WebResource webResource = dirResourceSet.getResource("/mount/d1/"); - Assert.assertTrue(webResource.isDirectory()); - Assert.assertEquals("d1", webResource.getName()); - Assert.assertEquals("/mount/d1/", webResource.getWebappPath()); - } - - @Test - public void testGetResourceFile() { - WebResource webResource = - dirResourceSet.getResource("/mount/d1/d1-f1.txt"); - Assert.assertTrue(webResource.isFile()); - Assert.assertEquals("d1-f1.txt", webResource.getName()); - Assert.assertEquals("/mount/d1/d1-f1.txt", webResource.getWebappPath()); + return new DirResourceSet(new TesterWebResourceRoot(), f, "/mount", ""); } @Test(expected = IllegalArgumentException.class) public void testListEmpty() { - dirResourceSet.list(""); + resourceSet.list(""); } @Test public void testListAbove() { - String[] results = dirResourceSet.list("/"); + String[] results = resourceSet.list("/"); Assert.assertNotNull(results); Assert.assertEquals(0, results.length); @@ -98,7 +50,7 @@ public class TestDirResourceSetMount { @Test public void testListRoot() { - String[] results = dirResourceSet.list("/mount"); + String[] results = resourceSet.list("/mount"); Set<String> expected = new HashSet<>(); expected.add("d1"); @@ -114,7 +66,7 @@ public class TestDirResourceSetMount { @Test public void testListDirA() { - String[] results = dirResourceSet.list("/mount/d1"); + String[] results = resourceSet.list("/mount/d1"); Set<String> expected = new HashSet<>(); expected.add("d1-f1.txt"); @@ -127,7 +79,7 @@ public class TestDirResourceSetMount { @Test public void testListDirB() { - String[] results = dirResourceSet.list("/mount/d1/"); + String[] results = resourceSet.list("/mount/d1/"); Set<String> expected = new HashSet<>(); expected.add("d1-f1.txt"); @@ -140,7 +92,7 @@ public class TestDirResourceSetMount { @Test public void testListFile() { - String[] results = dirResourceSet.list("/mount/d1/d1-f1.txt"); + String[] results = resourceSet.list("/mount/d1/d1-f1.txt"); Assert.assertNotNull(results); Assert.assertEquals(0, results.length); @@ -148,19 +100,19 @@ public class TestDirResourceSetMount { @Test(expected = IllegalArgumentException.class) public void testListWebAppPathsEmpty() { - dirResourceSet.listWebAppPaths(""); + resourceSet.listWebAppPaths(""); } @Test public void testListWebAppPathsAbove() { - Set<String> results = dirResourceSet.listWebAppPaths("/"); + Set<String> results = resourceSet.listWebAppPaths("/"); Assert.assertEquals(0, results.size()); } @Test public void testListWebAppPathsRoot() { - Set<String> results = dirResourceSet.listWebAppPaths("/mount"); + Set<String> results = resourceSet.listWebAppPaths("/mount"); Set<String> expected = new HashSet<>(); expected.add("/mount/d1/"); @@ -176,7 +128,7 @@ public class TestDirResourceSetMount { @Test public void testListWebAppPathsDirA() { - Set<String> results = dirResourceSet.listWebAppPaths("/mount/d1"); + Set<String> results = resourceSet.listWebAppPaths("/mount/d1"); Set<String> expected = new HashSet<>(); expected.add("/mount/d1/d1-f1.txt"); @@ -189,7 +141,7 @@ public class TestDirResourceSetMount { @Test public void testListWebAppPathsDirB() { - Set<String> results = dirResourceSet.listWebAppPaths("/mount/d1/"); + Set<String> results = resourceSet.listWebAppPaths("/mount/d1/"); Set<String> expected = new HashSet<>(); expected.add("/mount/d1/d1-f1.txt"); @@ -203,44 +155,44 @@ public class TestDirResourceSetMount { @Test public void testListWebAppPathsFile() { Set<String> results = - dirResourceSet.listWebAppPaths("/mount/d1/d1-f1.txt"); + resourceSet.listWebAppPaths("/mount/d1/d1-f1.txt"); Assert.assertEquals(0, results.size()); } @Test(expected = IllegalArgumentException.class) public void testMkdirEmpty() { - dirResourceSet.mkdir(""); + resourceSet.mkdir(""); } @Test public void testMkdirAbove() { - Assert.assertFalse(dirResourceSet.mkdir("/")); + Assert.assertFalse(resourceSet.mkdir("/")); } @Test public void testMkdirRoot() { - Assert.assertFalse(dirResourceSet.mkdir("/mount")); + Assert.assertFalse(resourceSet.mkdir("/mount")); } @Test public void testMkdirDirA() { - Assert.assertFalse(dirResourceSet.mkdir("/mount/d1")); + Assert.assertFalse(resourceSet.mkdir("/mount/d1")); } @Test public void testMkdirDirB() { - Assert.assertFalse(dirResourceSet.mkdir("/mount/d1/")); + Assert.assertFalse(resourceSet.mkdir("/mount/d1/")); } @Test public void testMkdirFile() { - Assert.assertFalse(dirResourceSet.mkdir("/mount/d1/d1-f1.txt")); + Assert.assertFalse(resourceSet.mkdir("/mount/d1/d1-f1.txt")); } @Test public void testMkdirNew() { - Assert.assertTrue(dirResourceSet.mkdir("/mount/new-test")); + Assert.assertTrue(resourceSet.mkdir("/mount/new-test")); File file = new File("test/webresources/dir1/new-test"); Assert.assertTrue(file.isDirectory()); @@ -250,48 +202,48 @@ public class TestDirResourceSetMount { @Test(expected = IllegalArgumentException.class) public void testWriteEmpty() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("", is); + resourceSet.write("", is); } @Test public void testWriteAbove() { InputStream is = new ByteArrayInputStream("test".getBytes()); - Assert.assertFalse(dirResourceSet.write("/", is)); + Assert.assertFalse(resourceSet.write("/", is)); } @Test(expected = IllegalArgumentException.class) public void testWriteRoot() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/mount", is); + resourceSet.write("/mount", is); } @Test(expected = IllegalArgumentException.class) public void testWriteDirA() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/mount/d1", is); + resourceSet.write("/mount/d1", is); } @Test(expected = IllegalArgumentException.class) public void testWriteDirB() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/mount/d1/", is); + resourceSet.write("/mount/d1/", is); } @Test(expected = IllegalArgumentException.class) public void testWriteFile() { InputStream is = new ByteArrayInputStream("test".getBytes()); - dirResourceSet.write("/mount/d1/d1-f1.txt", is); + resourceSet.write("/mount/d1/d1-f1.txt", is); } @Test(expected = NullPointerException.class) public void testWriteNew() { - dirResourceSet.write("/mount/new-test", null); + resourceSet.write("/mount/new-test", null); } @Test public void testWrite() { InputStream is = new ByteArrayInputStream("test".getBytes()); - Assert.assertTrue(dirResourceSet.write("/mount/new-test", is)); + Assert.assertTrue(resourceSet.write("/mount/new-test", is)); File file = new File("test/webresources/dir1/new-test"); Assert.assertTrue(file.exists()); Added: 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=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java (added) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,31 @@ +/* + * 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.webresources; + +import java.io.File; + +import org.apache.catalina.WebResourceSet; + +public class TestJarResourceSet extends AbstractTestResourceSet { + + @Override + public WebResourceSet getWebResourceSet() { + File f = new File("test/webresources/dir1.jar"); + return new JarResourceSet( + new TesterWebResourceRoot(), f, "", ""); + } +} Propchange: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSet.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java (added) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,31 @@ +/* + * 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.webresources; + +import java.io.File; + +import org.apache.catalina.WebResourceSet; + +public class TestJarResourceSetInternal extends AbstractTestResourceSet { + @Override + public WebResourceSet getWebResourceSet() { + File f = new File("test/webresources/dir1-internal.jar"); + return new JarResourceSet( + new TesterWebResourceRoot(), f, "", "/dir1"); + } + +} Propchange: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetInternal.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1384748&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java (added) +++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java Fri Sep 14 12:57:36 2012 @@ -0,0 +1,31 @@ +/* + * 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.webresources; + +import java.io.File; + +import org.apache.catalina.WebResourceSet; + +public class TestJarResourceSetMount extends AbstractTestResourceSetMount { + + @Override + public WebResourceSet getWebResourceSet() { + File f = new File("test/webresources/dir1.jar"); + return new JarResourceSet( + new TesterWebResourceRoot(), f, "/mount", ""); + } +} Propchange: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TestJarResourceSetMount.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/sandbox/trunk-resources/test/webresources/dir1-internal.jar URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/webresources/dir1-internal.jar?rev=1384748&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/sandbox/trunk-resources/test/webresources/dir1-internal.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: tomcat/sandbox/trunk-resources/test/webresources/dir1.jar URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/webresources/dir1.jar?rev=1384748&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/sandbox/trunk-resources/test/webresources/dir1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org