View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/database/manager/DatabaseManagerTest.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.6 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: DatabaseManagerTest.java,v $
9    *   Revision 1.6  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.5.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.5  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.4.38.1  2004/06/17 13:38:58  dave
20   *   Tidied up old CVS log entries
21   *
22   * </cvs:log>
23   *
24   */
25  package org.astrogrid.community.common.database.manager ;
26  
27  import org.apache.commons.logging.Log ;
28  import org.apache.commons.logging.LogFactory ;
29  
30  import org.astrogrid.community.common.service.CommunityServiceTest ;
31  
32  /***
33   * A JUnit test case for our DatabaseManager.
34   * This is designed to be extended by each set of tests, mock, client and server.
35   *
36   */
37  public class DatabaseManagerTest
38      extends CommunityServiceTest
39      {
40      /***
41       * Our debug logger.
42       *
43       */
44  	private static Log log = LogFactory.getLog(DatabaseManagerTest.class);
45  
46      /***
47       * Public constructor.
48       *
49       */
50      public DatabaseManagerTest()
51          {
52          }
53  
54      /***
55       * Public constructor, with reference to target manager.
56       *
57       */
58      public DatabaseManagerTest(DatabaseManager manager)
59          {
60          this.setDatabaseManager(manager) ;
61          }
62  
63      /***
64       * Our target DatabaseManager.
65       *
66       */
67      private DatabaseManager manager ;
68  
69      /***
70       * Set our target DatabaseManager.
71       *
72       */
73      public void setDatabaseManager(DatabaseManager manager)
74          {
75          log.debug("") ;
76          log.debug("----\"----") ;
77          log.debug("DatabaseManagerTest.setDatabaseManager()") ;
78          log.debug("  Manager : " + manager.getClass()) ;
79          //
80          // Set our target DatabaseManager.
81          this.manager = manager ;
82          //
83          // Set our base class DatabaseManager.
84          super.setDatabaseManager(manager) ;
85          //
86          // Set our CommunityService reference.
87          this.setCommunityService(manager) ;
88          }
89  
90      /***
91       * Test the current database name.
92       *
93       */
94      public void testGetDatabaseName()
95          throws Exception
96          {
97          log.debug("") ;
98          log.debug("----\"----") ;
99          log.debug("DatabaseManagerTest.testGetDatabaseName()") ;
100         log.debug("  Manager : " + manager.getClass()) ;
101         assertNotNull(
102             "getDatabaseName returned NULL",
103             manager.getDatabaseName()
104             ) ;
105         }
106 
107     /***
108      * Test the JDO configuration resource name.
109      *
110      */
111     public void testDatabaseConfigResource()
112         throws Exception
113         {
114         log.debug("") ;
115         log.debug("----\"----") ;
116         log.debug("DatabaseManagerTest.testDatabaseConfigResource()") ;
117         log.debug("  Manager : " + manager.getClass()) ;
118         assertNotNull(
119             "getDatabaseConfigResource returned NULL",
120             manager.getDatabaseConfigResource()
121             ) ;
122         }
123 
124     /***
125      * Get the database SQL script name.
126      *
127      */
128     public void testGetDatabaseScriptResource()
129         throws Exception
130         {
131         log.debug("") ;
132         log.debug("----\"----") ;
133         log.debug("DatabaseManagerTest.testGetDatabaseScriptResource()") ;
134         log.debug("  Manager : " + manager.getClass()) ;
135         assertNotNull(
136             "getDatabaseScriptResource returned NULL",
137             manager.getDatabaseScriptResource()
138             ) ;
139         }
140 
141     /***
142      * Get the database configuration URL.
143      *
144      */
145     public void testGetDatabaseConfigUrl()
146         throws Exception
147         {
148         log.debug("") ;
149         log.debug("----\"----") ;
150         log.debug("DatabaseManagerTest.testGetDatabaseConfigUrl()") ;
151         log.debug("  Manager : " + manager.getClass()) ;
152         assertNotNull(
153             "getDatabaseConfigUrl returned NULL",
154             manager.getDatabaseConfigUrl()
155             ) ;
156         }
157 
158     /***
159      * Get the database engine description.
160      *
161      */
162     public void testGetDatabaseDescription()
163         throws Exception
164         {
165         log.debug("") ;
166         log.debug("----\"----") ;
167         log.debug("DatabaseManagerTest.testGetDatabaseDescription()") ;
168         log.debug("  Manager : " + manager.getClass()) ;
169         assertNotNull(
170             "getDatabaseDescription returned NULL",
171             manager.getDatabaseDescription()
172             ) ;
173         }
174 
175     /***
176      * Create our database tables.
177      * This calls resetDatabaseTables() to create the tables,
178      * and then calls checkDatabaseTables() to check that they are healthy.
179      *
180      */
181     public void testResetDatabaseTables()
182         throws Exception
183         {
184         log.debug("") ;
185         log.debug("----\"----") ;
186         log.debug("DatabaseManagerTest.testResetDatabaseTables()") ;
187         log.debug("  Manager : " + manager.getClass()) ;
188         //
189         // Create the database tables.
190         manager.resetDatabaseTables() ;
191         //
192         // Check the tables were created.
193         assertTrue(
194             "checkDatabaseTables returned false",
195             manager.checkDatabaseTables()
196             ) ;
197         }
198 
199     }