KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > org > webdocwf > util > loader > LoaderTest2


1 /*
2 * LoaderTest.java Sept 01, 2002
3 *
4 * Sample JUnit test using Loader for creating test database and
5 * inserting data into it.
6 *
7  */

8
9 package test.org.webdocwf.util.loader;
10
11 import java.sql.Connection JavaDoc;
12 import java.sql.DriverManager JavaDoc;
13
14 import org.webdocwf.util.loader.test.LoaderTestCase;
15 import org.webdocwf.util.loader.test.DatabaseOperation;
16 import org.webdocwf.util.loader.test.LoaderOperation;
17 import org.webdocwf.util.loader.Loader;
18
19 import junit.framework.TestCase;
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22 import junit.framework.TestResult;
23
24 /**
25  * @author Sinisa Milosevic
26  * @version $Revision: 1.1 $
27  */

28 public class LoaderTest2 extends LoaderTestCase
29 {
30
31   public LoaderTest2(String JavaDoc name)
32   {
33     super(name);
34   }
35
36   /**
37    * Returns the test database connection.
38    * @throws Exception
39    * @return jdbcConnection
40    */

41   public Connection JavaDoc getConnection() throws Exception JavaDoc
42   {
43
44     Class JavaDoc driverClass = Class.forName("org.hsqldb.jdbcDriver");
45     Connection JavaDoc jdbcConnection = DriverManager.getConnection(
46         "jdbc:hsqldb:test/LoaderTest2/LoaderTest2","sa","");
47
48     return jdbcConnection;
49   }
50
51   /**
52    * Returns the test Loader class (loaderjob).
53    * @throws Exception
54    * @return Loader object
55    */

56   public Loader getLoader() throws Exception JavaDoc
57   {
58     showHeader();
59     Loader loadJob= new Loader("modules/Octopus/src/testdata/ObjectLoader/LoaderExample1.xml");
60     loadJob.setUserID("admin");
61     loadJob.setLogDirName("test");
62     loadJob.setLogFileName("LoaderTest2.txt");
63
64
65     return loadJob;
66   }
67   
68   private static boolean isHeaderShown = false;
69   private void showHeader() {
70     if( !this.isHeaderShown ) {
71     System.out.println();
72         System.out.println("****************************************************************");
73         System.out.println(" Executing test: testMe 2 - SQL Statements as a source data");
74         System.out.println("****************************************************************");
75         this.isHeaderShown = true;
76     }
77   }
78
79   /**
80    * Returns the database operations executed in test setup. First operation will be
81    * executed dbOperation[0], then dbOperation[1]...
82    * @throws Exception
83    * @return dbOperation parameter
84    */

85   public DatabaseOperation[] getSetUpOperation() throws Exception JavaDoc
86   {
87 // Executing loaderJob defined in xml file.
88
DatabaseOperation[] dbOperation = new DatabaseOperation[1];
89     dbOperation[0]=new LoaderOperation(getLoader());
90
91     return dbOperation;
92   }
93
94   /**
95    * Returns the database operation executed in test cleanup.
96    * First operation will be executed dbOperation[0], then dbOperation[1]...
97    * @throws Exception
98    * @return dbOperation parameter
99    */

100   public DatabaseOperation[] getTearDownOperation() throws Exception JavaDoc
101   {
102 // Do nothing...
103
DatabaseOperation[] dbOperation = new DatabaseOperation[1];
104     dbOperation[0]=DatabaseOperation.DO_NOTHING;
105
106     return dbOperation;
107   }
108
109
110   public void testMe() throws Exception JavaDoc
111   {
112     
113   }
114
115   public static Test suite() {
116     
117     return new TestSuite(LoaderTest2.class);
118   }
119
120
121   public static void main(String JavaDoc args[]) {
122 // junit.textui.TestRunner.run(suite());
123
TestResult result= (new LoaderTest2("testMe 2")).run();
124
125   }
126
127
128
129 }
130
131
132
133
134
Popular Tags