1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.DriverManager ; 36 37 import org.hsqldb.Server; 38 39 import junit.framework.TestCase; 40 41 import java.sql.SQLException ; 42 43 50 public abstract class TestBase extends TestCase { 51 52 String serverProps; 54 String url; 55 String user = "sa"; 56 String password = ""; 57 Server server; 58 boolean isNetwork = true; 59 60 public TestBase(String name) { 61 super(name); 62 } 63 64 public TestBase(String name, String url, boolean network) { 65 66 super(name); 67 68 this.isNetwork = isNetwork; 69 this.url = url; 70 } 71 72 protected void setUp() { 73 74 if (isNetwork) { 75 if (url == null) { 76 url = "jdbc:hsqldb:hsql://localhost/test"; 77 } 78 79 server = new Server(); 80 81 server.setDatabaseName(0, "test"); 82 server.setDatabasePath( 83 0, "mem:test;sql.enforce_strict_size=true"); 84 server.setLogWriter(null); 85 server.setErrWriter(null); 86 server.start(); 87 } else { 88 if (url == null) { 89 url = "jdbc:hsqldb:file:test;sql.enforce_strict_size=true"; 90 } 91 } 92 93 try { 94 Class.forName("org.hsqldb.jdbcDriver"); 95 } catch (Exception e) { 96 e.printStackTrace(); 97 System.out.println(this + ".setUp() error: " + e.getMessage()); 98 } 99 } 100 101 protected void tearDown() { 102 103 if (isNetwork) { 104 server.stop(); 105 106 server = null; 107 } 108 } 109 110 Connection newConnection() throws SQLException { 111 return DriverManager.getConnection(url, user, password); 112 } 113 } 114 | Popular Tags |