From: <aft...@us...> - 2008-08-06 14:11:31
|
Revision: 6901 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=6901&view=rev Author: aftereight Date: 2008-08-06 14:11:27 +0000 (Wed, 06 Aug 2008) Log Message: ----------- SFOS-941 Added test, closing issue Modified Paths: -------------- trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/MkdirTest.java Added Paths: ----------- trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/mkdirCleanOnStartup.sf Modified: trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/MkdirTest.java =================================================================== --- trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/MkdirTest.java 2008-08-06 13:06:34 UTC (rev 6900) +++ trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/MkdirTest.java 2008-08-06 14:11:27 UTC (rev 6901) @@ -49,15 +49,49 @@ true); file = new File(filename); //now verify we clean up - assertTrue("Directory not found: "+filename,file.exists()); - assertTrue("Not a directory: " + filename,file.isDirectory()); + assertIsDirectory(file, filename); } finally { //cleanup - if(file!=null) { + if (file!=null) { file.delete(); - assertFalse(file.exists()); + assertFalse("Should be able to clean up after test. Directory remaining: " + file, + file.exists()); } } } + + private void assertIsDirectory(File file, String filename) { + assertTrue("Directory should exist: " + filename, file.exists()); + assertTrue("Should be a directory: " + filename, file.isDirectory()); + } + + public void testCleanOnStartup() throws Throwable { + String dirname = System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + "directory-to-be-cleaned"; + File dir = new File(dirname); + + try { + assertFalse("Temp directory should not exist yet", dir.exists()); + assertTrue("Should be able to create a new temporary directory: " + dirname, + dir.mkdir()); + File dirInsideDir = new File(dir, "testDir"); + assertTrue("Should be able to create a new directory: " + dirInsideDir, + dirInsideDir.mkdir()); + File fileInsideDir = new File(dir, "testFile.txt"); + assertTrue("Should be able to create a new file inside directory: " + fileInsideDir, + fileInsideDir.createNewFile()); + + application = deployExpectingSuccess + (FILES + "mkdirCleanOnStartup.sf", "mkdirCleanOnStartupTest"); + + assertIsDirectory(dir, dirname); + assertEquals("The directory should be cleaned up and not contain anything", + 0, dir.listFiles().length); + } finally { + dir.delete(); + assertFalse("Should be able to clean up after test. Directory remaining: " + dir, + dir.exists()); + } + } } Added: trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/mkdirCleanOnStartup.sf =================================================================== --- trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/mkdirCleanOnStartup.sf (rev 0) +++ trunk/core/testharness/testcases/org/smartfrog/test/system/filesystem/mkdirCleanOnStartup.sf 2008-08-06 14:11:27 UTC (rev 6901) @@ -0,0 +1,27 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" + +sfConfig extends Mkdir { + cleanOnStartup true; + parentDir LAZY PROPERTY java.io.tmpdir; + dir (LAZY PROPERTY file.separator ++ "directory-to-be-cleaned"); +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |