Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that implements a metadata catalog as a java Servlet
4
 *  Copyright: 2006 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley, Matthew Perry
7
 *
8
 *   '$Author: jones $'
9
 *     '$Date: 2011-05-19 17:05:19 -0700 (Thu, 19 May 2011) $'
10
 * '$Revision: 6093 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
package edu.ucsb.nceas.metacattest;
27

    
28
import edu.ucsb.nceas.MCTestCase;
29
import edu.ucsb.nceas.metacat.AuthLdap;
30
import junit.framework.Test;
31
import junit.framework.TestSuite;
32

    
33

    
34
/*
35
 * A junit test class to test public methods in AuthLdap class.
36
 */
37
public class AuthLdapTest extends MCTestCase
38
{
39
	// Constants
40
	private static final String USER = "uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org";
41
	private static final String PASS   = "kepler";
42
	
43
	/**
44
     * Constructor to build the test
45
     *
46
     * @param name the name of the test method
47
     */
48
    public AuthLdapTest(String name)
49
    {
50
        super(name);
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 AuthLdapTest("initialize"));
61
        suite.addTest(new AuthLdapTest("getPrincipals"));
62
        return suite;
63
    }
64

    
65
    /**
66
     * Run an initial test that always passes to check that the test
67
     * harness is working.
68
     */
69
    public void initialize()
70
    {
71
        assertTrue(true);
72
    }
73
    
74
    public void getPrincipals()
75
    {
76
    	try
77
    	{
78
        	//System.out.println("before initilizing authldap object");
79
        	AuthLdap ldap = new AuthLdap();
80
        	//System.out.println("after initilizing authldap object");
81
    		
82
    		//System.out.println("before calling the getPrincipals method");
83
    	    String response = ldap.getPrincipals(USER, PASS);
84
    	    //System.out.println("after calling the getPrincipals method \n"+response);
85
    	    if ( response != null)
86
    	    {
87
    	       assertTrue("Couldn't find user from NCEAS",response.indexOf("uid=test,o=NCEAS") != -1);
88
    	       assertTrue("Couldn't find user from LTER",response.indexOf("uid=tmonkey,o=LTER") != -1);
89
    	    }
90
    	    else
91
    	    {
92
    	    	fail("the response is null in getPrincipal method");
93
    	    }
94
    	}
95
    	catch (Exception e)
96
    	{
97
    		//System.out.println("Error to get principals "+e.getMessage());
98
    		fail("There is an exception in getPrincipals "+e.getMessage());
99
    	}
100
    	
101
    }
102
    
103
    /**
104
     * To Do: add more methods test
105
     */
106

    
107
}
(3-3/24)