Author: schultz Date: Wed Jun 6 20:47:42 2012 New Revision: 1347111 URL: http://svn.apache.org/viewvc?rev=1347111&view=rev Log: Backport of r1347108 and 1347109 from trunk: clean-up of test case.
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1347108-1347109 Modified: tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1347111&r1=1347110&r2=1347111&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java Wed Jun 6 20:47:42 2012 @@ -42,6 +42,7 @@ import org.junit.Test; import org.apache.catalina.core.StandardContext; import org.apache.catalina.deploy.ContextEnvironment; import org.apache.catalina.deploy.ContextResource; +import org.apache.catalina.startup.ExpandWar; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.util.buf.ByteChunk; @@ -93,57 +94,24 @@ public class TestNamingContext extends T } - // Recursively deletes a directory and its contents - private boolean rmdir(File dir) - { - if(!dir.exists()) return false; - if(!dir.isDirectory()) return false; - - File[] files = dir.listFiles(); - if(null != files) { - for(int i=0; i<files.length; ++i) { - if(files[i].isDirectory()) - { - if(!rmdir(files[i])) { - return false; - } - } else { - if(!files[i].delete()) { - return false; - } - } - } - } - return dir.delete(); - } - @Test - public void testAliases() throws Exception - { + public void testAliases() throws Exception { // Some sample text String foxText = "The quick brown fox jumps over the lazy dog"; String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; // Set up a temporary docBase and some alternates that we can // set up as aliases. - File tmpDir = new File(System.getProperty("java.io.tmpdir"), + File tmpDir = new File(getTemporaryDirectory(), "tomcat-unit-test." + TestNamingContext.class.getName()); - if(tmpDir.exists()) - { - // Remove any old test files - if(tmpDir.isDirectory()) { - if(!rmdir(tmpDir)) - throw new IOException("Could not delete old temp directory: " + tmpDir); - } else { - if(!tmpDir.delete()) - throw new IOException("Could not delete old temp file: " + tmpDir); - } - } + // Make sure we've got a clean slate + ExpandWar.delete(tmpDir); + File docBase = new File(tmpDir, "docBase"); File alternate1 = new File(tmpDir, "alternate1"); File alternate2 = new File(tmpDir, "alternate2"); - + if(!tmpDir.mkdirs()) throw new IOException("Could not create temp directory " + tmpDir); if(!docBase.mkdir()) @@ -173,7 +141,7 @@ public class TestNamingContext extends T Assert.assertNotNull(file); Assert.assertTrue(file instanceof Resource); - + byte[] buffer = new byte[4096]; Resource res = (Resource)file; @@ -187,7 +155,7 @@ public class TestNamingContext extends T Assert.assertNotNull(file); Assert.assertTrue(file instanceof Resource); - + res = (Resource)file; len = res.streamContent().read(buffer); contents = new String(buffer, 0, len, "UTF-8"); @@ -217,7 +185,7 @@ public class TestNamingContext extends T Assert.assertNotNull(file); Assert.assertTrue(file instanceof Resource); - + res = (Resource)file; len = res.streamContent().read(buffer); contents = new String(buffer, 0, len, "UTF-8"); @@ -225,8 +193,7 @@ public class TestNamingContext extends T assertEquals(loremIpsum, contents); // Clean-up - if(!rmdir(tmpDir)) - throw new IOException("Could not clean-up temp directory" + tmpDir); + addDeleteOnTearDown(tmpDir); } public static final class Bug49994Servlet extends HttpServlet { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org