Project

General

Profile

« Previous | Next » 

Revision 3748

Added by Jing Tao about 16 years ago

Add a junit test for test AuthLdap. Currently we have getPrincipals test.

View differences:

test/edu/ucsb/nceas/metacattest/AuthLdapTest.java
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$'
9
 *     '$Date$'
10
 * '$Revision$'
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
import java.io.File;
28

  
29
import edu.ucsb.nceas.metacat.AuthLdap;
30
import edu.ucsb.nceas.metacat.MetaCatUtil;
31
import edu.ucsb.nceas.utilities.Options;
32
import junit.framework.Test;
33
import junit.framework.TestCase;
34
import junit.framework.TestSuite;
35

  
36

  
37
/*
38
 * A junit test class to test public methods in AuthLdap class.
39
 */
40
public class AuthLdapTest extends TestCase
41
{
42
	// Constants
43
	private static final String USER = "uid=kepler,o=unaffiliated,dc=ecoinformatics,dc=org";
44
	private static final String PASS   = "kepler";
45
	
46
	
47
	private MetaCatUtil util;
48
    /* Initialize Options*/
49
    static
50
    {
51
  	  try
52
  	  {
53
  		  Options.initialize(new File("build/tests/metacat.properties"));
54
  	  }
55
  	  catch(Exception e)
56
  	  {
57
  		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
58
  	  }
59
    }
60
	
61
	/**
62
     * Constructor to build the test
63
     *
64
     * @param name the name of the test method
65
     */
66
    public AuthLdapTest(String name)
67
    {
68
        super(name);
69
        
70
    }
71
	
72
    /**
73
     * Create a suite of tests to be run together
74
     */
75
    public static Test suite()
76
    {
77
        TestSuite suite = new TestSuite();
78
        suite.addTest(new AuthLdapTest("initialize"));
79
        suite.addTest(new AuthLdapTest("getPrincipals"));
80
        return suite;
81
    }
82

  
83
    /**
84
     * Run an initial test that always passes to check that the test
85
     * harness is working.
86
     */
87
    public void initialize()
88
    {
89
    	//System.out.println("here");
90
        assertTrue(1 == 1);
91
    }
92
    
93
    public void getPrincipals()
94
    {
95
    	//System.out.println("before initilizing authldap object");
96
    	AuthLdap ldap = new AuthLdap();
97
    	//System.out.println("after initilizing authldap object");
98
    	try
99
    	{
100
    		//System.out.println("before calling the getPrincipals method");
101
    	    String response = ldap.getPrincipals(USER, PASS);
102
    	    //System.out.println("after calling the getPrincipals method \n"+response);
103
    	    if ( response != null)
104
    	    {
105
    	       assertTrue("Couldn't find user tao in nceas",response.indexOf("uid=tao,o=NCEAS") != -1);
106
    	       assertTrue("Couldn't find user tao in lter",response.indexOf("uid=MCM,o=LTER") != -1);
107
    	    }
108
    	    else
109
    	    {
110
    	    	fail("the response is null in getPrincipal method");
111
    	    }
112
    	}
113
    	catch (Exception e)
114
    	{
115
    		//System.out.println("Error to get principals "+e.getMessage());
116
    		fail("There is an exception in getPrincipals "+e.getMessage());
117
    	}
118
    	
119
    }
120
    
121
    /**
122
     * To Do: add more methods test
123
     */
124

  
125
}
0 126

  

Also available in: Unified diff