Skip to content

Commit 101c07b

Browse files
committed
Add unit tests for FileUtilsTest
1 parent 1613977 commit 101c07b

File tree

6 files changed

+529
-156
lines changed

6 files changed

+529
-156
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@
174174
<version>1.17.3</version>
175175
<scope>test</scope>
176176
</dependency>
177+
<!-- We use mockito-inline as it supports mocking static methods -->
177178
<dependency>
178179
<groupId>org.mockito</groupId>
179-
<artifactId>mockito-all</artifactId>
180-
<version>1.10.19</version>
180+
<artifactId>mockito-inline</artifactId>
181+
<version>4.7.0</version>
181182
<scope>test</scope>
182183
</dependency>
183184
</dependencies>

src/main/java/org/commonwl/view/researchobject/ROBundleFactory.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
package org.commonwl.view.researchobject;
2121

22-
import org.apache.commons.io.FileUtils;
2322
import org.apache.commons.io.FilenameUtils;
2423
import org.apache.taverna.robundle.Bundle;
2524
import org.apache.taverna.robundle.fs.BundleFileSystem;
2625
import org.commonwl.view.git.GitDetails;
26+
import org.commonwl.view.util.FileUtils;
2727
import org.commonwl.view.workflow.Workflow;
2828
import org.commonwl.view.workflow.WorkflowRepository;
2929
import org.slf4j.Logger;
@@ -81,25 +81,10 @@ public void createWorkflowRO(Workflow workflow)
8181

8282
// Save the bundle to the storage location in properties
8383
Path bundleLocation = roBundleService.saveToFile(bundle);
84-
// The RoBundleService#saveToFile call above will delegate to Taverna's
85-
// Bundles.closeAndSaveBundle, which empties the bundle temporary
86-
// directory without deleting the directory itself. The following call is
87-
// just for cleaning it up.
88-
if (bundle != null) {
89-
try {
90-
BundleFileSystem fs = (BundleFileSystem) bundle.getFileSystem();
91-
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
92-
// The file system source will be something like /tmp/bundles_dir/hash/bundle.zip,
93-
// and we want /tmp/hash to be deleted. N.B. Taverna uses the temporary directory
94-
// for the temporary bundles' directory, not the bundles file specified by Spring.
95-
String bundleTmpDirName = fs.getSource().toAbsolutePath().getParent().getFileName().toString();
96-
File bundleTmpDir = new File(tmpDir, bundleTmpDirName);
97-
if (bundleTmpDir.exists() && bundleTmpDir.isDirectory()) {
98-
FileUtils.forceDelete(bundleTmpDir);
99-
}
100-
} catch (IOException e) {
101-
logger.warn(String.format("Failed to delete temporary directory for bundle [%s]: %s", bundle.getSource(), e.getMessage()), e);
102-
}
84+
try {
85+
FileUtils.deleteBundleTemporaryDirectory(bundle);
86+
} catch (IOException e) {
87+
logger.warn(String.format("Failed to delete temporary directory for bundle [%s]: %s", bundle.getSource(), e.getMessage()), e);
10388
}
10489

10590
// Add RO Bundle to associated workflow model

0 commit comments

Comments
 (0)