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
26
27
28
29
30
31
32
33
34
35
36 package org.astrogrid.community.common.service ;
37
38 import org.apache.commons.logging.Log ;
39 import org.apache.commons.logging.LogFactory ;
40
41 import org.astrogrid.store.Ivorn ;
42
43 import org.astrogrid.community.common.junit.JUnitTestBase ;
44
45 import org.astrogrid.community.common.service.data.ServiceStatusData ;
46 import org.astrogrid.community.common.database.manager.DatabaseManager ;
47
48 import org.astrogrid.community.common.ivorn.CommunityAccountIvornFactory ;
49
50 import org.astrogrid.community.common.exception.CommunityServiceException ;
51 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
52
53 /***
54 * A JUnit test case for our common CommunityService interface.
55 * This is designed to be extended by each set of tests, mock, client and server.
56 *
57 */
58 public class CommunityServiceTest
59 extends JUnitTestBase
60 {
61 /***
62 * Our debug logger.
63 *
64 */
65 private static Log log = LogFactory.getLog(CommunityServiceTest.class);
66
67 /***
68 * Public constructor.
69 *
70 */
71 public CommunityServiceTest()
72 {
73 }
74
75 /***
76 * Public constructor, with reference to target service.
77 *
78 */
79 public CommunityServiceTest(CommunityService service)
80 {
81 this.setCommunityService(service) ;
82 }
83
84 /***
85 * Create a local Ivorn.
86 *
87 */
88 public Ivorn createLocal(String ident)
89 throws CommunityServiceException, CommunityIdentifierException
90 {
91 return CommunityAccountIvornFactory.createLocal(ident) ;
92 }
93
94 /***
95 * Our target CommunityService.
96 *
97 */
98 private CommunityService communityService ;
99
100 /***
101 * Get our target CommunityService.
102 *
103 */
104 public CommunityService getCommunityService()
105 {
106 return this.communityService ;
107 }
108
109 /***
110 * Set our target CommunityService.
111 *
112 */
113 public void setCommunityService(CommunityService service)
114 {
115 log.debug("") ;
116 log.debug("----\"----") ;
117 log.debug("CommunityServiceTest.setCommunityService()") ;
118 log.debug(" Service : " + service.getClass()) ;
119
120
121 this.communityService = service ;
122 }
123
124 /***
125 * Test the service status.
126 * Just checks that the return is not null.
127 *
128 */
129 public void testServiceStatus()
130 throws Exception
131 {
132 log.debug("") ;
133 log.debug("----\"----") ;
134 log.debug("CommunityServiceTest.testServiceStatus()") ;
135 log.debug(" Service : " + communityService.getClass()) ;
136 assertNotNull(
137 communityService.getServiceStatus()
138 ) ;
139 }
140
141 /***
142 * Test the service memory.
143 *
144 */
145 public void testServiceMemory()
146 throws Exception
147 {
148 log.debug("") ;
149 log.debug("----\"----") ;
150 log.debug("CommunityServiceTest.testServiceMemory()") ;
151 log.debug(" Service : " + communityService.getClass()) ;
152
153
154 ServiceStatusData status = communityService.getServiceStatus() ;
155
156
157 log.info("Free memory : " + status.getFreeMemory()) ;
158 log.info("Total memory : " + status.getTotalMemory()) ;
159 }
160
161
162 /***
163 * Our target DatabaseManager.
164 *
165 */
166 private DatabaseManager databaseManager ;
167
168 /***
169 * Get our target DatabaseManager.
170 *
171 */
172 public DatabaseManager getDatabaseManager()
173 {
174 return this.databaseManager ;
175 }
176
177 /***
178 * Set our target DatabaseManager.
179 *
180 */
181 public void setDatabaseManager(DatabaseManager manager)
182 {
183 log.debug("") ;
184 log.debug("----\"----") ;
185 log.debug("CommunityServiceTest.setDatabaseManager()") ;
186 log.debug(" Manager : " + manager.getClass()) ;
187
188
189 this.databaseManager = manager ;
190 }
191
192 /***
193 * Setup our test.
194 * Use our DatabaseManager to reset our database tables.
195 *
196 */
197 public void resetDatabase()
198 throws Exception
199 {
200 log.debug("") ;
201 log.debug("----\"----") ;
202 log.debug("CommunityServiceTest:resetDatabase()") ;
203
204
205 databaseManager.resetDatabaseTables() ;
206 }
207
208 }