Don't create directory when requiring file. Improve unit test.
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 8 May 2009 09:28:57 +0000 (09:28 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 8 May 2009 09:28:57 +0000 (09:28 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2431 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/FileExecutionResourcesTest.java

index 316633a80decb1f50f548b22b6423fc04d2e1a74..e6530832ad7638ea7d41babadfe64363df49a4b9 100644 (file)
@@ -53,7 +53,9 @@ public class FileExecutionResources implements ExecutionResources {
        public Resource getWritableResource(String relativePath) {
                File file = getFile(relativePath);
                File parentDir = file.getParentFile();
+
                if (!parentDir.exists()) {
+                       // Creates if necessary
                        if (log.isTraceEnabled())
                                log.trace("Creating parent directory " + parentDir);
                        parentDir.mkdirs();
@@ -72,13 +74,6 @@ public class FileExecutionResources implements ExecutionResources {
                                + executionContext.getUuid();
                File executionDir = new File(path);
 
-               // Creates if necessary
-               if (!executionDir.exists()) {
-                       if (log.isDebugEnabled())
-                               log.debug("Creating execution directory " + executionDir);
-                       executionDir.mkdirs();
-               }
-
                return new File(executionDir.getPath() + File.separator
                                + relativePath.replace('/', File.separatorChar));
        }
index d1e4ec59d4f0d5efaa3c241f5851e9266c50611d..63bd58c3cd476fda393c8b8d5549feb9ade32800 100644 (file)
@@ -19,13 +19,17 @@ public class FileExecutionResourcesTest extends TestCase {
                try {
                        // Resource
                        Resource resource = executionResources
-                                       .getWritableResource("subdir/textRes.txt");
+                                       .getWritableResource("subdir1/textRes.txt");
+                       assertTrue(resource.getFile().getParentFile().exists());
+                       assertFalse(resource.getFile().exists());
                        FileUtils.writeStringToFile(resource.getFile(), expected);
                        reached = FileUtils.readFileToString(resource.getFile());
                        assertEquals(expected, reached);
 
                        // File
-                       File file = executionResources.getFile("subdir/textFile.txt");
+                       File file = executionResources.getFile("subdir2/textFile.txt");
+                       assertFalse(file.getParentFile().exists());
+                       assertFalse(file.exists());
                        FileUtils.writeStringToFile(file, expected);
                        reached = FileUtils.readFileToString(file);
                        assertEquals(expected, reached);