View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/service/CommunityServiceTest.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.8 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityServiceTest.java,v $
9    *   Revision 1.8  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.7.8.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.7  2004/09/09 01:19:50  dave
17   *   Updated MIME type handling in MySpace.
18   *   Extended test coverage for MIME types in FileStore and MySpace.
19   *   Added VM memory data to community ServiceStatusData.
20   *
21   *   Revision 1.6.74.1  2004/09/07 04:01:47  dave
22   *   Added memory stats ...
23   *
24   *   Revision 1.6  2004/06/18 13:45:20  dave
25   *   Merged development branch, dave-dev-200406081614, into HEAD
26   *
27   *   Revision 1.5.32.2  2004/06/17 14:50:03  dave
28   *   Removed unused imports (PMD report).
29   *
30   *   Revision 1.5.32.1  2004/06/17 13:38:59  dave
31   *   Tidied up old CVS log entries
32   *
33   * </cvs:log>
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         // Set our CommunityService reference.
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         // Get the service status.
154         ServiceStatusData status = communityService.getServiceStatus() ;
155         //
156         // Log the available memory.
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         // Set our DatabaseManager reference.
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         // Use our manager to reset our tables.
205         databaseManager.resetDatabaseTables() ;
206         }
207 
208     }