1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.rice.test; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.sql.DriverManager; |
20 |
|
|
21 |
|
import org.apache.log4j.Logger; |
22 |
|
import org.kuali.rice.core.api.config.ConfigurationException; |
23 |
|
import org.kuali.rice.core.api.config.property.Config; |
24 |
|
import org.kuali.rice.core.api.config.property.ConfigContext; |
25 |
|
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
26 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 13 |
Complexity Density: 0.48 |
|
27 |
|
public class DerbyDBCreationLifecycle implements Lifecycle { |
28 |
|
|
29 |
|
private static final Logger LOG = Logger.getLogger(DerbyDBCreationLifecycle.class); |
30 |
|
|
31 |
|
private String sqlFile; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
33 |
0
|
public DerbyDBCreationLifecycle(String sqlFile) {... |
34 |
0
|
this.setSqlFile(sqlFile); |
35 |
|
} |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
0
|
public boolean isStarted() {... |
38 |
0
|
return false; |
39 |
|
} |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
41 |
0
|
public void start() throws Exception {... |
42 |
0
|
if (! isDoingDerby()) { |
43 |
0
|
LOG.info("Not using the Derby database for testing or no ddl file found"); |
44 |
0
|
return; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
0
|
Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); |
49 |
0
|
DriverManager.getConnection(ConfigContext.getCurrentContextConfig().getProperty("datasource.url")).close(); |
50 |
|
|
51 |
0
|
String dbLocation = ConfigContext.getCurrentContextConfig().getProperty("db.location"); |
52 |
0
|
File db = new File(dbLocation); |
53 |
0
|
if (! db.exists()) { |
54 |
0
|
throw new ConfigurationException("Can't find db file " + dbLocation); |
55 |
|
} |
56 |
|
|
57 |
0
|
if (isDerbyDBReadyForTests()) { |
58 |
0
|
LOG.info("Derby ready for testing"); |
59 |
0
|
return; |
60 |
|
} |
61 |
|
|
62 |
0
|
LOG.info("Setting up Derby for testing"); |
63 |
0
|
LOG.info("Derby connection string: " + ConfigContext.getCurrentContextConfig().getProperty("datasource.url")); |
64 |
0
|
SQLDataLoader dataLoader = new SQLDataLoader(this.getSqlFile(), ";"); |
65 |
0
|
dataLoader.runSql(); |
66 |
|
} |
67 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
68 |
0
|
public void stop() throws Exception {... |
69 |
|
|
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0
|
private boolean isDerbyDBReadyForTests() {... |
73 |
0
|
return new ClearDatabaseLifecycle().isTestTableInSchema(TestHarnessServiceLocator.getDataSource()); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
76 |
0
|
protected boolean isDoingDerby() {... |
77 |
0
|
if (this.getSqlFile() == null) { |
78 |
0
|
return false; |
79 |
|
} |
80 |
0
|
String dbDriverName = ConfigContext.getCurrentContextConfig().getProperty(Config.DATASOURCE_DRIVER_NAME); |
81 |
0
|
if (dbDriverName == null) { |
82 |
0
|
throw new ConfigurationException("No property '" + Config.DATASOURCE_DRIVER_NAME + "' found"); |
83 |
|
} |
84 |
0
|
return dbDriverName.toLowerCase().contains("derby"); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0
|
public String getSqlFile() {... |
88 |
0
|
return sqlFile; |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0
|
public void setSqlFile(String sqlFile) {... |
92 |
0
|
this.sqlFile = sqlFile; |
93 |
|
} |
94 |
|
} |