[jboss-svn-commits] JBL Code SVN: r5744 - in labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb: listeners util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 11 07:24:54 EDT 2006


Author: tfennelly
Date: 2006-08-11 07:24:51 -0400 (Fri, 11 Aug 2006)
New Revision: 5744

Modified:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/DirectoryPollerTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/FileUtils.java
Log:
fixed test

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/DirectoryPollerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/DirectoryPollerTest.java	2006-08-11 11:01:16 UTC (rev 5743)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/DirectoryPollerTest.java	2006-08-11 11:24:51 UTC (rev 5744)
@@ -61,6 +61,11 @@
 		// Make sure the notifications appear in the "copiedTo" dir...
 		FileUtils.assertFileExists(new File(copiedTo, "infile1.inp.outFromFirst"), 10000);
 		FileUtils.assertFileExists(new File(copiedTo, "infile1.inp.outFromSecond"), 10000);
+
+		// Make sure there's no open fle handles on the files created/copied by the ESB...
+		FileUtils.assertCanDelete(new File(inputDoneDir, "infile1.inp.DONE"), 10000);
+		FileUtils.assertCanDelete(new File(copiedTo, "infile1.inp.outFromFirst"), 10000);
+		FileUtils.assertCanDelete(new File(copiedTo, "infile1.inp.outFromSecond"), 10000);
 		
 		// There should have been no exceptions...
 		listenersMgr.assertNotInException();

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/FileUtils.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/FileUtils.java	2006-08-11 11:01:16 UTC (rev 5743)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/FileUtils.java	2006-08-11 11:24:51 UTC (rev 5744)
@@ -126,17 +126,9 @@
 		}
 		
 		long endTime = System.currentTimeMillis() + maxWait;
-		FileFilter fileFilter = new FileFilter() {
-			public boolean accept(File file) {
-				if(!file.getParentFile().equals(dir)) {
-					return false;
-				}
-				return Pattern.matches(pattern, file.getName());
-			}
-		};
 		
 		while(System.currentTimeMillis() < endTime) {
-			if(dir.listFiles(fileFilter).length > 0) {
+			if(hasFiles(dir, pattern)) {
 				return;
 			}
 			try {
@@ -148,6 +140,25 @@
 		TestCaseUtils.logAndFail("Files matching the pattern [" + pattern + "] not found in directory [" 
 				+ dir.getAbsolutePath() + "].  Waited for " + maxWait + "ms.", logger, null);
 	}
+	
+	/**
+	 * Check for files matching the specified pattern appear in the specified directory.
+	 * @param dir Directory to check.
+	 * @param pattern Regexp pattern used to perform the matching.
+	 * @return True if files matching that pattern exist, otherwise false.
+	 */
+	public static boolean hasFiles(final File dir, final String pattern) {
+		FileFilter fileFilter = new FileFilter() {
+			public boolean accept(File file) {
+				if(!file.getParentFile().equals(dir)) {
+					return false;
+				}
+				return Pattern.matches(pattern, file.getName());
+			}
+		};
+		
+		return dir.listFiles(fileFilter).length > 0;
+	}
 
 	/**
 	 * Assert that the specified file doesn't exists.
@@ -187,6 +198,10 @@
 		file.delete();
 		long endTime = System.currentTimeMillis() + maxWait;
 		
+		if(file.isDirectory() && hasFiles(file, ".*")) {
+			TestCaseUtils.logAndFail("File [" + file.getAbsolutePath() + "] can't be deleted - it's a directory and isn't empty.", logger, null);
+		}
+		
 		while(System.currentTimeMillis() < endTime) {
 			file.delete();
 			if(!file.exists()) {




More information about the jboss-svn-commits mailing list