View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/security/manager/SecurityManagerTest.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.7 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: SecurityManagerTest.java,v $
9    *   Revision 1.7  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.6.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.6  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.5.32.2  2004/06/17 15:53:22  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.5.32.1  2004/06/17 13:38:59  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
26   *
27   */
28  package org.astrogrid.community.common.security.manager ;
29  
30  import org.apache.commons.logging.Log ;
31  import org.apache.commons.logging.LogFactory ;
32  
33  import org.astrogrid.community.common.policy.data.AccountData ;
34  import org.astrogrid.community.common.policy.manager.AccountManager ;
35  
36  import org.astrogrid.community.common.service.CommunityServiceTest ;
37  
38  /***
39   * A JUnit test case for our Securitymanager interface.
40   * This is designed to be extended by each set of tests, mock, client and server.
41   *
42   */
43  public class SecurityManagerTest
44      extends CommunityServiceTest
45      {
46      /***
47       * Our debug logger.
48       *
49       */
50      private static Log log = LogFactory.getLog(SecurityManagerTest.class);
51  
52      /***
53       * Our test Account ident.
54       *
55       */
56      public static String TEST_ACCOUNT = "test-account" ;
57  
58      /***
59       * Our test password.
60       *
61       */
62      public static String TEST_PASSWORD = "test-password" ;
63  
64      /***
65       * Public constructor.
66       *
67       */
68      public SecurityManagerTest()
69          {
70          }
71  
72      /***
73       * Our target AccountManager.
74       *
75       */
76      private AccountManager accountManager ;
77  
78      /***
79       * Get our target AccountManager.
80       *
81       */
82      public AccountManager getAccountManager()
83          {
84          return this.accountManager ;
85          }
86  
87      /***
88       * Set our target AccountManager.
89       *
90       */
91      public void setAccountManager(AccountManager manager)
92          {
93          log.debug("") ;
94          log.debug("----\"----") ;
95          log.debug("SecurityServiceTest.setAccountManager()") ;
96          log.debug("  Manager : " + manager.getClass()) ;
97          this.accountManager = manager ;
98          }
99  
100     /***
101      * Our target SecurityManager.
102      *
103      */
104     private SecurityManager securityManager ;
105 
106     /***
107      * Get our target SecurityManager.
108      *
109      */
110     public SecurityManager getSecurityManager()
111         {
112         return this.securityManager ;
113         }
114 
115     /***
116      * Set our target SecurityManager.
117      *
118      */
119     public void setSecurityManager(SecurityManager manager)
120         {
121         log.debug("") ;
122         log.debug("----\"----") ;
123         log.debug("SecurityManagerTest.setSecurityManager()") ;
124         log.debug("  Manager : " + manager.getClass()) ;
125         //
126         // Set our SecurityManager reference.
127         this.securityManager = manager ;
128         //
129         // Set our CommunityService reference.
130         this.setCommunityService(securityManager) ;
131         }
132 
133     /***
134      * Check we can set an account password.
135      *
136      */
137     public void testSetPassword()
138         throws Exception
139         {
140         log.debug("") ;
141         log.debug("----\"----") ;
142         log.debug("SecurityManagerTest.testSetPassword()") ;
143         //
144         // Setup our test account.
145         AccountData account = accountManager.addAccount(
146             createLocal(TEST_ACCOUNT).toString()
147             ) ;
148         assertNotNull(
149             "addAccount returned null",
150             account
151             ) ;
152         //
153         // Check that we can set a password.
154         assertTrue(
155             "setPassword returned false",
156             securityManager.setPassword(
157                 account.getIdent(),
158                 TEST_PASSWORD
159                 )
160             ) ;
161         }
162 
163     /***
164      * Check we can change an account password.
165      *
166      */
167     public void testChangePassword()
168         throws Exception
169         {
170         log.debug("") ;
171         log.debug("----\"----") ;
172         log.debug("SecurityManagerTest.testChangePassword()") ;
173         //
174         // Setup our test account.
175         AccountData account = accountManager.addAccount(
176             createLocal(TEST_ACCOUNT).toString()
177             ) ;
178         assertNotNull(
179             "addAccount returned null",
180             account
181             ) ;
182         //
183         // Check that we can set a password.
184         assertTrue(
185             "setPassword returned false",
186             securityManager.setPassword(
187                 account.getIdent(),
188                 TEST_PASSWORD
189                 )
190             ) ;
191         //
192         // Check that we can set the same password.
193         assertTrue(
194             "setPassword returned false",
195             securityManager.setPassword(
196                 account.getIdent(),
197                 TEST_PASSWORD
198                 )
199             ) ;
200         }
201     }
202