KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > OzoneTestCase


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package test;
10
11 import junit.framework.TestCase;
12 import org.apache.log4j.Category;
13 import org.apache.log4j.Logger;
14 import org.ozoneDB.ExternalDatabase;
15
16 /**
17  * Base class for the Ozone based TestCase. The following is an
18  * example of writting OzoneTestCase.
19  *
20  * <pre>
21  * packge com.foo;
22  *
23  * import junit.framework.*;
24  * import test.OzoneTestCase;
25  * import org.ozoneDB.test.simple.*;
26  *
27  * package FooTestCase extends OzoneTestCase {
28  * public static Test suite() {
29  * TestSuite suite = new TestSuite();
30  * suite.addTestSuite(FooTestCase.class);
31  * return suite;
32  * }
33  *
34  * public void testCreate() {
35  * // db() provide the access to database setup by TestRunner
36  * Auto auto = (Auto)db().createObject(AutoImpl.class.getName());
37  * assertNotNull(auto);
38  * // Test away!!!
39  * }
40  * }
41  *</pre>
42  *
43  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
44  * @author <a HREF="mailto:david@d11e.com">David Li</a>
45  * @version $Revision$Date$ */

46 public abstract class OzoneTestCase extends TestCase {
47
48     /**
49      * log4j logger
50      */

51     private static Logger fLog = Logger.getLogger(OzoneTestCase.class);
52
53     /**
54      * the database to be used for testing
55      */

56     private ExternalDatabase db;
57
58     /** the url used for the db, could be used to open other connections */
59     private String JavaDoc dbUrl;
60
61     /**
62      * Constructor.
63      */

64     protected OzoneTestCase(String JavaDoc name) {
65         super(name);
66     }
67
68     /**
69      * Return the database set up by OzoneTestRunner
70      * @return a instance of ExternalDatabase
71      */

72     public ExternalDatabase db() {
73         return db;
74     }
75
76     /**
77      * Set the database for this TestCase. This is typically used by
78      * the OzoneTestRunner. However, you can also use it in the
79      * setUp() method to connect to different database than the one
80      * specified by the OzoneTestRunner.
81      *
82      * @param db the database to be used for the TestCase
83      */

84     public void setDB(ExternalDatabase db) {
85         this.db = db;
86         fLog.debug("setDB(): set new database to " + db);
87     }
88
89     public void setDbUrl(String JavaDoc dbUrl) {
90         this.dbUrl = dbUrl;
91     }
92
93     public String JavaDoc getDbUrl() {
94         return dbUrl;
95     }
96 }
97
Popular Tags