KickJava   Java API By Example, From Geeks To Geeks.

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


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.Loader;
16 import org.webdocwf.util.loader.test.DatabaseOperation;
17 import org.webdocwf.util.loader.test.LoaderOperation;
18
19
20 import junit.framework.TestCase;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23 import junit.framework.TestResult;
24
25 /**
26  * @author Sinisa Milosevic
27  * @version $Revision: 1.1 $
28  */

29 public class LoaderTest extends LoaderTestCase
30 {
31   public static final String JavaDoc DATABASE_LOCATION_PROPERTY="database.location";
32
33   public LoaderTest(String JavaDoc name)
34   {
35     super(name);
36   }
37
38   /**
39    * Returns the test database connection.
40    * @throws Exception
41    * @return connection
42    */

43   public Connection JavaDoc getConnection() throws Exception JavaDoc
44   {
45
46     Class JavaDoc driverClass = Class.forName("org.hsqldb.jdbcDriver");
47     java.sql.Connection JavaDoc jdbcConnection = java.sql.DriverManager.getConnection("jdbc:hsqldb:test/LoaderTest/LoaderTest","sa","");
48
49     return jdbcConnection;
50   }
51
52   /**
53    * Returns the name of test database.
54    * @throws Exception
55    * @return string
56    */

57
58   public String JavaDoc getDatabaseName() throws Exception JavaDoc
59   {
60     return "LoaderTest";
61   }
62
63
64
65   /**
66    * Returns the database operations executed in test setup. First operation will be
67    * executed dbOperation[0], then dbOperation[1]...
68    * @throws Exception
69    * @return dbOperation parameter
70    */

71   public DatabaseOperation[] getSetUpOperation() throws Exception JavaDoc
72   {
73 // Creating test database.....
74
DatabaseOperation[] dbOperation = new DatabaseOperation[1];
75 // dbOperation[0]=new CreateDatabaseOperation(getDatabaseName());
76

77     dbOperation[0]=new LoaderOperation(getLoader());
78
79     return dbOperation;
80   }
81
82   /**
83    * Returns the test Loader class (loaderjob).
84    * @throws Exception
85    * @return Loader object
86    */

87   public Loader getLoader() throws Exception JavaDoc
88   {
89     showHeader();
90     Loader loadJob= new Loader("modules/Octopus/src/testdata/ObjectLoader/LoadTestExample.xml");
91     loadJob.setUserID("admin");
92     loadJob.setLogDirName("test");
93     loadJob.setLogFileName("LoaderTest.txt");
94
95     return loadJob;
96   }
97
98   private static boolean isHeaderShown = false;
99   private void showHeader() {
100     if( !this.isHeaderShown ) {
101     System.out.println();
102         System.out.println("**************************************************************************");
103         System.out.println(" Executing test: testMe 1 - Transfering data and creating integrity");
104         System.out.println("**************************************************************************");
105         this.isHeaderShown = true;
106     }
107   }
108
109   /**
110    * Returns the database operation executed in test cleanup.
111    * First operation will be executed dbOperation[0], then dbOperation[1]...
112    * @throws Exception
113    * @return dbOperation parameter
114    */

115   public DatabaseOperation[] getTearDownOperation() throws Exception JavaDoc
116   {
117 // Do nothing...
118
DatabaseOperation[] dbOperation = new DatabaseOperation[1];
119     dbOperation[0]=DatabaseOperation.DO_NOTHING;
120
121     return dbOperation;
122   }
123
124   public void testMe() throws Exception JavaDoc
125   {
126
127   }
128
129   public static Test suite() {
130     return new TestSuite(LoaderTest.class);
131   }
132
133
134   public static void main(String JavaDoc args[]) {
135
136 // junit.textui.TestRunner.run(suite());
137
TestResult result= (new LoaderTest("testMe 1")).run();
138
139   }
140
141
142
143 }
144
Popular Tags