| 1 10 package org.mmbase.tests; 11 import junit.framework.TestCase; 12 13 import java.io.File ; 14 import java.sql.*; 15 import org.hsqldb.Server; 16 import org.mmbase.util.ResourceLoader; 17 import org.mmbase.util.logging.Logging; 18 import org.mmbase.module.Module; 19 import org.mmbase.module.core.*; 20 import org.mmbase.module.tools.MMAdmin; 21 22 27 public abstract class MMBaseTest extends TestCase { 28 29 static MMBase mmb; 30 31 public MMBaseTest() { 32 super(); 33 } 34 public MMBaseTest(String name) { 35 super(name); 36 } 37 38 static public void startMMBase() throws Exception { 39 if (System.getProperty("nostartmmbase") == null) { 40 startMMBase(System.getProperty("nostartdb") == null); 41 } 42 } 43 46 static public void startMMBase(boolean startDatabase) throws Exception { 47 if (startDatabase) startDatabase(); 48 MMBaseContext.init(); 49 mmb = MMBase.getMMBase(); 50 51 MMAdmin mmadmin = (MMAdmin) Module.getModule("mmadmin", true); 52 while (! mmadmin.getState()) { 53 Thread.sleep(1000); 54 } 55 System.out.println("================================================================================"); 56 System.out.println("Starting test"); 57 } 58 59 static public void startDatabase() { 60 try { 62 Thread.sleep(5000); 63 Class.forName("org.hsqldb.jdbcDriver" ); 64 } catch (Exception e) { 65 System.err.println("ERROR: failed to load HSQLDB JDBC driver." + e.getMessage()); 66 return; 67 } 68 while(true) { 69 String database = System.getProperty("test.database"); 70 if (database == null) database = "test"; 71 try { 72 Connection c = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/" + database, "sa", ""); 73 return; 75 } catch (SQLException sqe) { 76 Server server = new Server(); 77 server.setSilent(true); 78 String dbDir = System.getProperty("test.database.dir"); 79 if (dbDir == null) dbDir = System.getProperty("user.dir") + File.separator + "data"; 80 server.setDatabasePath(0, dbDir + File.separator + database); 81 server.setDatabaseName(0, database); 82 server.start(); 83 try { 84 Thread.sleep(10000); 85 } catch (Exception e) { 86 } 88 } 89 } 90 } 91 92 95 static public void startLogging() throws Exception { 96 startLogging("log.xml"); 97 } 98 101 static public void startLogging(String configure) throws Exception { 102 Logging.configure(ResourceLoader.getConfigurationRoot().getChildResourceLoader("log"), configure); 103 } 104 105 108 public static void main(String [] args) { 109 try { 110 startMMBase(); 111 while(!mmb.isShutdown()) { 112 113 } 114 } catch (Exception e) { 115 } 116 } 117 118 } 119 | Popular Tags |