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.CreateDatabaseOperation;
017: import org.webdocwf.util.loader.test.DropDatabaseOperation;
018: import org.webdocwf.util.loader.test.LoaderOperation;
019: import org.webdocwf.util.loader.Loader;
020:
021: import junit.framework.TestCase;
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024: import junit.framework.TestResult;
025:
026: /**
027: * @author Sinisa Milosevic
028: * @version $Revision: 1.1 $
029: */
030: public class LoaderTest3 extends LoaderTestCase {
031:
032: public LoaderTest3(String name) {
033: super (name);
034: }
035:
036: /**
037: * Returns the test database connection.
038: * @throws Exception
039: * @return jdbc connection
040: */
041: public Connection getConnection() throws Exception {
042:
043: Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
044: Connection jdbcConnection = DriverManager.getConnection(
045: "jdbc:hsqldb:test/LoaderTest3/LoaderTest3", "sa", "");
046:
047: return jdbcConnection;
048: }
049:
050: /**
051: * Returns the name of test database.
052: * @throws Exception
053: * @return string
054: */
055:
056: public String getDatabaseName() throws Exception {
057: return "LoaderTest3";
058: }
059:
060: /**
061: * Returns the test Loader class (loaderjob).
062: * @throws Exception
063: * @return Loader object
064: */
065: public Loader getLoader() throws Exception {
066:
067: showHeader();
068: Loader loadJob = new Loader(
069: "modules/Octopus/src/testdata/ObjectLoader/CreateTables3.xml");
070: loadJob.setUserID("admin");
071: loadJob.setLogDirName("test");
072: loadJob.setLogFileName("LoaderTest3.txt");
073:
074: return loadJob;
075: }
076:
077: private static boolean isHeaderShown = false;
078:
079: private void showHeader() {
080: if (!this .isHeaderShown) {
081: System.out.println();
082: System.out
083: .println("******************************************************");
084: System.out.println(" Executing test: test3 - ");
085: System.out
086: .println("******************************************************");
087: this .isHeaderShown = true;
088: }
089: }
090:
091: /**
092: * Returns the database operations executed in test setup. First operation will be
093: * executed dbOperation[0], then dbOperation[1]...
094: * @throws Exception
095: * @return dbOperation parameter
096: */
097: public DatabaseOperation[] getSetUpOperation() throws Exception {
098: // Creating test database.....
099: DatabaseOperation[] dbOperation = new DatabaseOperation[3];
100: // dbOperation[0]=new CreateDatabaseOperation(getDatabaseName());
101:
102: // Creating tables.....
103: dbOperation[0] = new LoaderOperation(getLoader());
104:
105: // Inserting data.....
106: Loader loadJob1 = new Loader(
107: "modules/Octopus/src/testdata/ObjectLoader/InsertData.xml");
108: loadJob1.setUserID("admin");
109: loadJob1.setLogDirName("test");
110: loadJob1.setLogFileName("LoaderTest3.txt");
111: dbOperation[1] = new LoaderOperation(loadJob1);
112:
113: // Creating indexes, foreign keys.....
114: Loader loadJob2 = new Loader(
115: "modules/Octopus/src/testdata/ObjectLoader/CreateIndex.xml");
116: loadJob2.setLogDirName("test");
117: loadJob2.setLogFileName("LoaderTest3_CreateIndex.txt");
118: dbOperation[2] = new LoaderOperation(loadJob2);
119:
120: return dbOperation;
121: }
122:
123: /**
124: * Returns the database operation executed in test cleanup.
125: * First operation will be executed dbOperation[0], then dbOperation[1]...
126: * @throws Exception
127: * @return dbOperation parameter
128: */
129: public DatabaseOperation[] getTearDownOperation() throws Exception {
130: // Deleting test database.....
131: DatabaseOperation[] dbOperation = new DatabaseOperation[1];
132: dbOperation[0] = DatabaseOperation.DO_NOTHING;
133:
134: return dbOperation;
135: }
136:
137: public void testMe() throws Exception {
138:
139: }
140:
141: public static Test suite() {
142: return new TestSuite(LoaderTest3.class);
143: }
144:
145: public static void main(String args[]) {
146:
147: // junit.textui.TestRunner.run(suite());
148: TestResult result = (new LoaderTest3("testMe 3")).run();
149:
150: }
151:
152: }
|