View Javadoc

1   package ar.com.jiji.kaya.tests;
2   
3   import java.io.File;
4   import java.io.FilenameFilter;
5   import java.sql.Connection;
6   import java.sql.DriverManager;
7   import java.sql.SQLException;
8   import java.sql.Statement;
9   
10  import junit.framework.TestCase;
11  import ar.com.jiji.kaya.app.Application;
12  import ar.com.jiji.kaya.app.ProjectBeanFactory;
13  import ar.com.jiji.kaya.app.ProjectService;
14  
15  /**
16   * Clase base para los tests. Crea una instancia de ProjectService para que sea
17   * usada por las subclases que implementan los tests.
18   * 
19   * @author lparra
20   * @version $Revision$ $Date$
21   */
22  public class AbstractTestCase extends TestCase {
23  	protected ProjectService service;
24  
25  	protected void setUp() throws Exception {
26  		service = Application.getService();
27  	}
28  
29  	protected void tearDown() throws Exception {
30  		ProjectBeanFactory.reset();
31  		// resetDB();
32  		service = null;
33  	}
34  
35  	/**
36  	 * Deja la base como recien creada.
37  	 * 
38  	 */
39  	protected void resetDB() {
40  		// TODO: buscar una forma de resetear la base y no hacer esta chanchada.
41  
42  		try {
43  			Connection drv = DriverManager.getConnection(
44  					"jdbc:hsqldb:file:testDB", "sa", "");
45  			Statement stmt = drv.createStatement();
46  			stmt.execute("SHUTDOWN");
47  			stmt.close();
48  			drv.close();
49  		} catch (SQLException e) {
50  			throw new RuntimeTestException(e);
51  		}
52  
53  		File curDir = new File(".");
54  		File[] dbFiles = curDir.listFiles(new FilenameFilter() {
55  			public boolean accept(File dir, String name) {
56  				return (name.startsWith("telcosDB."));
57  			}
58  		});
59  
60  		for (File f : dbFiles) {
61  			if (!f.delete())
62  				throw new RuntimeTestException("no se puede borrar "
63  						+ f.getName());
64  		}
65  	}
66  }