Project

General

Profile

1
/**  '$RCSfile$'
2
 *  Copyright: 2010 Regents of the University of California and the
3
 *              National Center for Ecological Analysis and Synthesis
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
package edu.ucsb.nceas.metacat.authentication;
20

    
21
import junit.framework.Test;
22
import junit.framework.TestSuite;
23
import edu.ucsb.nceas.MCTestCase;
24

    
25

    
26
public class AuthFileTest extends MCTestCase {
27
    private static final String PASSWORDFILEPATH = "build/password";
28
    private static final String GROUPNAME = "nceas-dev";
29
    private static final String USERNAME = "uid=tao,o=NCEAS,dc=ecoinformatics,dc=org";
30
    private static final String PASSWORD = "ecoinformatics";
31
    /**
32
     * consstructor for the test
33
     */
34
     public AuthFileTest(String name)
35
     {
36
         super(name);
37
     }
38
   
39
     /**
40
      * Establish a testing framework by initializing appropriate objects
41
      */
42
     public void setUp() throws Exception 
43
     {
44
         super.setUp();
45
     }
46

    
47
     /**
48
      * Release any objects after tests are complete
49
      */
50
     public void tearDown() 
51
     {
52
     }
53

    
54
     /**
55
      * Create a suite of tests to be run together
56
      */
57
     public static Test suite() 
58
     {
59
         TestSuite suite = new TestSuite();
60
         suite.addTest(new AuthFileTest("testAddGroup"));
61
         suite.addTest(new AuthFileTest("testAddUser"));
62
         return suite;
63
     }
64
     
65
     /**
66
      * Test the addGroup method
67
      * @throws Exception
68
      */
69
     public void testAddGroup() throws Exception{
70
         AuthFile authFile = AuthFile.getInstance(PASSWORDFILEPATH);
71
         authFile.addGroup(GROUPNAME);
72
         try {
73
             authFile.addGroup(GROUPNAME);
74
             assertTrue("We can't reach here since we can't add the group twice", false);
75
         } catch (AuthenticationException e) {
76
             
77
         }
78
         
79
     }
80
     
81
     /**
82
      * Test the addGroup method
83
      * @throws Exception
84
      */
85
     public void testAddUser() throws Exception{
86
         AuthFile authFile = AuthFile.getInstance(PASSWORDFILEPATH);
87
         String[]groups = {GROUPNAME};
88
         authFile.addUser(USERNAME, groups, PASSWORD);
89
         try {
90
             authFile.addUser(USERNAME, groups, PASSWORD);
91
             assertTrue("We can't reach here since we can't add the user twice", false);
92
         } catch (AuthenticationException e) {
93
             
94
         }
95
         
96
     }
97
}
    (1-1/1)