001: /*
002: * LoaderTest.java Sept 01, 2002
003: *
004: * Sample JUnit test using Loader for creating test database and
005: * inserting data into it.
006: *
007: */
008:
009: package test.org.webdocwf.util.loader;
010:
011: import java.sql.Connection;
012: import java.sql.DriverManager;
013:
014: import org.webdocwf.util.loader.test.LoaderTestCase;
015: import org.webdocwf.util.loader.Loader;
016: import org.webdocwf.util.loader.test.DatabaseOperation;
017: import org.webdocwf.util.loader.test.LoaderOperation;
018:
019: import junit.framework.TestCase;
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022: import junit.framework.TestResult;
023:
024: /**
025: * @author Sinisa Milosevic
026: * @version $Revision: 1.1 $
027: */
028: public class LoaderTest extends LoaderTestCase {
029: public static final String DATABASE_LOCATION_PROPERTY = "database.location";
030:
031: public LoaderTest(String name) {
032: super (name);
033: }
034:
035: /**
036: * Returns the test database connection.
037: * @throws Exception
038: * @return connection
039: */
040: public Connection getConnection() throws Exception {
041:
042: Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
043: java.sql.Connection jdbcConnection = java.sql.DriverManager
044: .getConnection(
045: "jdbc:hsqldb:test/LoaderTest/LoaderTest", "sa",
046: "");
047:
048: return jdbcConnection;
049: }
050:
051: /**
052: * Returns the name of test database.
053: * @throws Exception
054: * @return string
055: */
056:
057: public String getDatabaseName() throws Exception {
058: return "LoaderTest";
059: }
060:
061: /**
062: * Returns the database operations executed in test setup. First operation will be
063: * executed dbOperation[0], then dbOperation[1]...
064: * @throws Exception
065: * @return dbOperation parameter
066: */
067: public DatabaseOperation[] getSetUpOperation() throws Exception {
068: // Creating test database.....
069: DatabaseOperation[] dbOperation = new DatabaseOperation[1];
070: // dbOperation[0]=new CreateDatabaseOperation(getDatabaseName());
071:
072: dbOperation[0] = new LoaderOperation(getLoader());
073:
074: return dbOperation;
075: }
076:
077: /**
078: * Returns the test Loader class (loaderjob).
079: * @throws Exception
080: * @return Loader object
081: */
082: public Loader getLoader() throws Exception {
083: showHeader();
084: Loader loadJob = new Loader(
085: "modules/Octopus/src/testdata/ObjectLoader/LoadTestExample.xml");
086: loadJob.setUserID("admin");
087: loadJob.setLogDirName("test");
088: loadJob.setLogFileName("LoaderTest.txt");
089:
090: return loadJob;
091: }
092:
093: private static boolean isHeaderShown = false;
094:
095: private void showHeader() {
096: if (!this .isHeaderShown) {
097: System.out.println();
098: System.out
099: .println("**************************************************************************");
100: System.out
101: .println(" Executing test: testMe 1 - Transfering data and creating integrity");
102: System.out
103: .println("**************************************************************************");
104: this .isHeaderShown = true;
105: }
106: }
107:
108: /**
109: * Returns the database operation executed in test cleanup.
110: * First operation will be executed dbOperation[0], then dbOperation[1]...
111: * @throws Exception
112: * @return dbOperation parameter
113: */
114: public DatabaseOperation[] getTearDownOperation() throws Exception {
115: // Do nothing...
116: DatabaseOperation[] dbOperation = new DatabaseOperation[1];
117: dbOperation[0] = DatabaseOperation.DO_NOTHING;
118:
119: return dbOperation;
120: }
121:
122: public void testMe() throws Exception {
123:
124: }
125:
126: public static Test suite() {
127: return new TestSuite(LoaderTest.class);
128: }
129:
130: public static void main(String args[]) {
131:
132: // junit.textui.TestRunner.run(suite());
133: TestResult result = (new LoaderTest("testMe 1")).run();
134:
135: }
136:
137: }
|