/*
 * Copyright 2010-2012 Luca Garulli (l.garulli--at--orientechnologies.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.orientechnologies.orient.test.database.base;

import java.io.File;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

@Test
public class DeleteDirectory {
	@Parameters(value = "path")
	public DeleteDirectory(String iPath) {
		final File f = new File(iPath);

		if (f.exists())
			deleteDirectory(f);
		else
			System.err.println("Directory: " + f.getAbsolutePath() + " not found");
	}

	private void deleteDirectory(File iDirectory) {
		if (iDirectory.isDirectory())
			for (File f : iDirectory.listFiles()) {
				if (f.isDirectory())
					deleteDirectory(f);
				else
					f.delete();
			}

	}
}

@@ -814,16 +814,95 @@
 est;%0D%0A%0D%0A
+import com.orientechnologies.orient.core.exception.OConfigurationException;%0D%0A%0D%0A
 @Test%0D%0Ap
@@ -932,17 +932,18 @@
 tory %7B%0D%0A
-%09
+  
 @Paramet
@@ -963,17 +963,18 @@
 path%22)%0D%0A
-%09
+  
 public D
@@ -1005,18 +1005,20 @@
 ath) %7B%0D%0A
-%09%09
+    
 final Fi
@@ -1044,18 +1044,20 @@
 th);%0D%0A%0D%0A
-%09%09
+    
 if (f.ex
@@ -1065,19 +1065,22 @@
 sts())%0D%0A
-%09%09%09
+      
 deleteDi
@@ -1092,27 +1092,32 @@
 ry(f);%0D%0A
-%09%09
+    
 else%0D%0A
-%09%09%09
+      
 System.e
@@ -1181,23 +1181,25 @@
 und%22);%0D%0A
-%09
+  
 %7D%0D%0A%0D%0A
-%09
+  
 private 
@@ -1239,18 +1239,20 @@
 ory) %7B%0D%0A
-%09%09
+    
 if (iDir
@@ -1274,19 +1274,22 @@
 ory())%0D%0A
-%09%09%09
+      
 for (Fil
@@ -1321,20 +1321,24 @@
 s()) %7B%0D%0A
-%09%09%09%09
+        
 if (f.is
@@ -1351,21 +1351,26 @@
 ory())%0D%0A
-%09%09%09%09%09
+          
 deleteDi
@@ -1386,45 +1386,129 @@
 );%0D%0A
-%09%09%09%09else%0D%0A%09%09%09%09%09f.delete();%0D%0A%09%09%09
+        else if (!f.delete())%0D%0A          throw new OConfigurationException(%22Can't delete the file: %22 + f);%0D%0A      
 %7D%0D%0A%0D%0A
-%09
+  
 %7D%0D%0A%7D

Delete database of tests now stops if a file can't be deleted