Author: gnodet Date: Wed Sep 9 11:40:43 2009 New Revision: 812894 URL: http://svn.apache.org/viewvc?rev=812894&view=rev Log: FELIX-1574: fix junit tests
Modified: felix/trunk/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java felix/trunk/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java Modified: felix/trunk/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java?rev=812894&r1=812893&r2=812894&view=diff ============================================================================== --- felix/trunk/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java (original) +++ felix/trunk/karaf/gshell/gshell-admin/src/main/java/org/apache/felix/karaf/gshell/admin/main/Execute.java Wed Sep 9 11:40:43 2009 @@ -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); } Modified: felix/trunk/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java URL: http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java?rev=812894&r1=812893&r2=812894&view=diff ============================================================================== --- felix/trunk/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java (original) +++ felix/trunk/karaf/gshell/gshell-admin/src/test/java/org/apache/felix/karaf/gshell/admin/main/ExecuteTest.java Wed Sep 9 11:40:43 2009 @@ -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(); + } }