01: package com.sun.portal.app.filesharing.util;
02:
03: import com.sun.portal.app.filesharing.repo.FileRepositoryTest;
04: import junit.framework.TestCase;
05:
06: import java.io.File;
07: import java.util.Properties;
08:
09: /**
10: * @author Alejandro Abdelnur
11: */
12: public class JdbcTestCase extends TestCase {
13: private static boolean USE_EMBEDDED;
14:
15: private static final String EMBEDDED_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
16: private static final String NETWORK_DRIVER = "org.apache.derby.jdbc.ClientDriver";
17:
18: private static final String EMBEDDED_URL_PREFIX = "jdbc:derby:";
19: private static final String NETWORK_URL_PREFIX = "jdbc:derby://localhost/";
20:
21: private static final Properties JDBC_PROPS = new Properties();
22:
23: static {
24: new LogUtilsSetter();
25:
26: USE_EMBEDDED = false;//(System.getProperty("testdb.mode")==null) ? true : !System.getProperty("testdb.mode").equals("network");
27: //NEED THIS FOR MAC ENV
28: System.getProperties().setProperty(
29: "derby.storage.fileSyncTransactionLog", "true");
30: }
31:
32: private String _dbName;
33:
34: protected JdbcTestCase(String dbName) {
35: _dbName = dbName;
36: JDBC_PROPS.setProperty("user", "test");
37: JDBC_PROPS.setProperty("password", "test");
38: try {
39: File derbyRoot = new File(dbName);
40: if (derbyRoot.exists()) {
41: FileRepositoryTest.deleteDir(derbyRoot);
42: }
43: } catch (Exception ex) {
44: throw new RuntimeException(ex);
45: }
46: SQLExecutor.setJdbcForTest(getDriver(), getJdbcUrl(),
47: getJdbcProperties());
48: File derbyRoot = new File(_dbName);
49: System.out.println("DerbyRepository root at ["
50: + derbyRoot.getAbsolutePath() + "]");
51: }
52:
53: private String getJdbcUrl() {
54: if (USE_EMBEDDED) {
55: return EMBEDDED_URL_PREFIX
56: + (new File("build/" + _dbName)).getAbsolutePath()
57: + ";create=true";
58: } else {
59: return NETWORK_URL_PREFIX + _dbName + ";create=true";
60: }
61: }
62:
63: private String getDriver() {
64: return (USE_EMBEDDED) ? EMBEDDED_DRIVER : NETWORK_DRIVER;
65: }
66:
67: private Properties getJdbcProperties() {
68: return JDBC_PROPS;
69: }
70:
71: protected SQLExecutor getSQLExecutor() {
72: return new SQLExecutor(null);
73: }
74:
75: }
|