FELIX-1574: fix junit tests
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@812894 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java b/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java
index 90e26e9..e68e686 100644
--- a/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java
+++ b/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java
@@ -75,7 +75,7 @@
String storage = System.getProperty("storage.location");
if (storage == null) {
- System.err.println("System property 'storage.file' is not set. \n" +
+ System.err.println("System property 'storage.location' is not set. \n" +
"This property needs to be set to the full path of the instance.properties file.");
exit(-1);
}
diff --git a/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java b/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java
index 5b96fba..2d0e122 100644
--- a/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java
+++ b/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -92,7 +93,7 @@
assertEquals("-1", re.getMessage());
String s = new String(baos.toByteArray());
- assertTrue(s.contains("storage.file"));
+ assertTrue(s.contains("storage.location"));
assertTrue(s.contains("instance.properties"));
} finally {
System.setErr(oldErr);
@@ -101,26 +102,26 @@
public void testSetDir() throws Exception {
Properties oldProps = (Properties) System.getProperties().clone();
- File tempFile = File.createTempFile(getName(), ".tmp");
+ final File tempFile = createTempDir(getName());
assertFalse("Precondition failed",
tempFile.getParentFile().getParentFile().getCanonicalPath().equals(System.getProperty("user.dir")));
- System.setProperty("storage.file", tempFile.getCanonicalPath());
+ System.setProperty("storage.location", tempFile.getCanonicalPath());
try {
Execute.main(new String [] {"list"});
assertTrue(tempFile.getParentFile().getParentFile().getCanonicalPath().equals(System.getProperty("user.dir")));
} finally {
System.setProperties(oldProps);
- assertNull("Postcondition failed", System.getProperty("storage.file"));
- tempFile.delete();
+ assertNull("Postcondition failed", System.getProperty("storage.location"));
+ delete(tempFile);
}
}
public void testExecute() throws Exception {
- final File tempFile = File.createTempFile(getName(), ".properties");
+ final File tempFile = createTempDir(getName());
Properties p = new Properties();
p.setProperty("port", "1302");
- FileOutputStream fos = new FileOutputStream(tempFile);
+ FileOutputStream fos = new FileOutputStream(new File(tempFile, AdminServiceImpl.STORAGE_FILE));
p.store(fos, "");
fos.close();
@@ -154,7 +155,23 @@
EasyMock.verify(mockCommand);
} finally {
- tempFile.delete();
+ delete(tempFile);
}
}
+
+ private static File createTempDir(String name) throws IOException {
+ final File tempFile = File.createTempFile(name, null);
+ tempFile.delete();
+ tempFile.mkdirs();
+ return tempFile;
+ }
+
+ private static void delete(File tmp) {
+ if (tmp.isDirectory()) {
+ for (File f : tmp.listFiles()) {
+ delete(f);
+ }
+ }
+ tmp.delete();
+ }
}