Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the MetaCatURL class by JUnit
6
 *    Authors: Jing Tao
7
 *
8
 *   '$Author: tao $'
9
 *     '$Date: 2014-03-04 09:48:15 -0800 (Tue, 04 Mar 2014) $'
10
 * '$Revision: 8695 $'
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.metacat.AuthLdap;
29
import edu.ucsb.nceas.metacat.properties.PropertyService;
30
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
31
import junit.framework.Test;
32
import junit.framework.TestSuite;
33

    
34

    
35
/**
36
 * The reason to add this specific test for a LTER account is LTET ldap server is not working right
37
 * now. We centralize all tests of LTER acounts here in order to simplify the management
38
 * @author tao
39
 *
40
 */
41
public class LTERAccountTest extends MetaCatServletTest{
42
    /**
43
     * Constructor to build the test
44
     * 
45
     * @param name
46
     *            the name of the test method
47
     */
48
    public LTERAccountTest(String name) {
49
        super(name);
50
       
51
    }
52

    
53
    /**
54
     * Establish a testing framework by initializing appropriate objects
55
     */
56
    public void setUp() {
57
       super.setUp();
58
    }
59

    
60
    /**
61
     * Release any objects after tests are complete
62
     */
63
    public void tearDown() {
64
    }
65

    
66
    /**
67
     * Create a suite of tests to be run together
68
     */
69
    public static Test suite() {
70
        double number = 0;
71
       
72
        TestSuite suite = new TestSuite();
73
        suite.addTest(new LTERAccountTest("testGetPrincipals"));
74
        suite.addTest(new LTERAccountTest("testLterReferralLogin"));
75
        suite.addTest(new LTERAccountTest("testLterReferralLoginFail"));
76
        return suite;
77
    }
78
    
79
    public void testGetPrincipals()
80
    {
81
        try
82
        {
83
            String lterUser = PropertyService.getProperty("test.lterUser");
84
            //System.out.println("before initilizing authldap object");
85
            AuthLdap ldap = new AuthLdap();
86
            //System.out.println("after initilizing authldap object");
87
            
88
            //System.out.println("before calling the getPrincipals method");
89
            String response = ldap.getPrincipals(username, password);
90
            //System.out.println("after calling the getPrincipals method \n"+response);
91
            if ( response != null)
92
            {
93
               //assertTrue("Couldn't find user "+anotheruser,response.indexOf(anotheruser) != -1);
94
               assertTrue("Couldn't find user "+lterUser,response.indexOf(lterUser) != -1);
95
            }
96
            else
97
            {
98
                fail("the response is null in getPrincipal method");
99
            }
100
        }
101
        catch (Exception e)
102
        {
103
            //System.out.println("Error to get principals "+e.getMessage());
104
            fail("There is an exception in getPrincipals "+e.getMessage());
105
        }
106
        
107
    }
108
    
109
    /**
110
     * Test the login to lter succesfully
111
     */
112
    public void testLterReferralLogin() {
113
        debug("\nRunning: testLterReferralLogin test");
114
        String user = null;
115
        String passwd = null;
116
        try {
117
            user = PropertyService.getProperty("test.lterUser");
118
            passwd = PropertyService.getProperty("test.lterPassword");
119
        } catch (PropertyNotFoundException pnfe) {
120
            fail("Could not find property: " + pnfe.getMessage());
121
        }
122

    
123
        debug("Logging into lter: " + user + " : " + passwd);
124
        assertTrue(logIn(user, passwd));
125
        this.testLogOut();
126

    
127

    
128
    }
129

    
130
    /**
131
     * Test the login to lter failed
132
     */
133
    public void testLterReferralLoginFail() {
134
        debug("\nRunning: testLterReferralLoginFail test");
135
        String user = null;
136
    String passwd = "wrong";
137
    try {
138
      user = PropertyService.getProperty("test.lterUser");
139
    } catch (PropertyNotFoundException pnfe) {
140
      fail("Could not find property: " + pnfe.getMessage());
141
    }
142
        assertTrue(!logIn(user, passwd));
143
        // assertTrue( withProtocol.getProtocol().equals("http"));
144
        this.testLogOut();
145

    
146
    }
147
}
(11-11/30)