1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
81 this.manager = manager ;
82
83
84 super.setDatabaseManager(manager) ;
85
86
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
190 manager.resetDatabaseTables() ;
191
192
193 assertTrue(
194 "checkDatabaseTables returned false",
195 manager.checkDatabaseTables()
196 ) ;
197 }
198
199 }