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.test.DatabaseOperation;
016: import org.webdocwf.util.loader.test.LoaderOperation;
017: import org.webdocwf.util.loader.Loader;
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 LoaderTest2 extends LoaderTestCase {
029:
030: public LoaderTest2(String name) {
031: super (name);
032: }
033:
034: /**
035: * Returns the test database connection.
036: * @throws Exception
037: * @return jdbcConnection
038: */
039: public Connection getConnection() throws Exception {
040:
041: Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
042: Connection jdbcConnection = DriverManager.getConnection(
043: "jdbc:hsqldb:test/LoaderTest2/LoaderTest2", "sa", "");
044:
045: return jdbcConnection;
046: }
047:
048: /**
049: * Returns the test Loader class (loaderjob).
050: * @throws Exception
051: * @return Loader object
052: */
053: public Loader getLoader() throws Exception {
054: showHeader();
055: Loader loadJob = new Loader(
056: "modules/Octopus/src/testdata/ObjectLoader/LoaderExample1.xml");
057: loadJob.setUserID("admin");
058: loadJob.setLogDirName("test");
059: loadJob.setLogFileName("LoaderTest2.txt");
060:
061: return loadJob;
062: }
063:
064: private static boolean isHeaderShown = false;
065:
066: private void showHeader() {
067: if (!this .isHeaderShown) {
068: System.out.println();
069: System.out
070: .println("****************************************************************");
071: System.out
072: .println(" Executing test: testMe 2 - SQL Statements as a source data");
073: System.out
074: .println("****************************************************************");
075: this .isHeaderShown = true;
076: }
077: }
078:
079: /**
080: * Returns the database operations executed in test setup. First operation will be
081: * executed dbOperation[0], then dbOperation[1]...
082: * @throws Exception
083: * @return dbOperation parameter
084: */
085: public DatabaseOperation[] getSetUpOperation() throws Exception {
086: // Executing loaderJob defined in xml file.
087: DatabaseOperation[] dbOperation = new DatabaseOperation[1];
088: dbOperation[0] = new LoaderOperation(getLoader());
089:
090: return dbOperation;
091: }
092:
093: /**
094: * Returns the database operation executed in test cleanup.
095: * First operation will be executed dbOperation[0], then dbOperation[1]...
096: * @throws Exception
097: * @return dbOperation parameter
098: */
099: public DatabaseOperation[] getTearDownOperation() throws Exception {
100: // Do nothing...
101: DatabaseOperation[] dbOperation = new DatabaseOperation[1];
102: dbOperation[0] = DatabaseOperation.DO_NOTHING;
103:
104: return dbOperation;
105: }
106:
107: public void testMe() throws Exception {
108:
109: }
110:
111: public static Test suite() {
112:
113: return new TestSuite(LoaderTest2.class);
114: }
115:
116: public static void main(String args[]) {
117: // junit.textui.TestRunner.run(suite());
118: TestResult result = (new LoaderTest2("testMe 2")).run();
119:
120: }
121:
122: }
|