Project

General

Profile

« Previous | Next » 

Revision 8506

Added by Jing Tao almost 11 years ago

Add users which are needed in the junit tests when the metacat is file-based authentication.
If users have been added, it just print out the exception.

View differences:

test/edu/ucsb/nceas/MCTestCase.java
45 45
import org.apache.http.client.HttpClient;
46 46
import org.apache.http.impl.client.DefaultHttpClient;
47 47

  
48
import edu.ucsb.nceas.metacat.authentication.AuthFile;
48 49
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
49 50
import edu.ucsb.nceas.metacat.client.Metacat;
50 51
import edu.ucsb.nceas.metacat.client.MetacatException;
......
72 73
	protected static String EML2_0_1 = "EML2_0_1";
73 74
	protected static String EML2_1_0 = "EML2_1_0";
74 75
	protected static String EML2_1_1 = "EML2_1_1";
76
	protected static final String AUTHFILECLASSNAME = "edu.ucsb.nceas.metacat.authentication.AuthFile";
75 77

  
76 78
	
77 79
	protected boolean SUCCESS = true;
......
94 96
	protected static String password;
95 97
	protected static String anotheruser;
96 98
	protected static String anotherpassword;
99
	private static String lteruser;
100
	private static String lterpassword;
101
	protected static String referraluser;
102
	protected static String referralpassword;
97 103
	
98 104
	protected static String metacatContextDir;
99 105
	
......
113 119
			password = PropertyService.getProperty("test.mcPassword");
114 120
			anotheruser = PropertyService.getProperty("test.mcAnotherUser");
115 121
			anotherpassword = PropertyService.getProperty("test.mcAnotherPassword");
122
			lteruser = PropertyService.getProperty("test.lterUser");
123
			lterpassword = PropertyService.getProperty("test.lterPassword");
124
			referraluser = PropertyService.getProperty("test.referralUser");
125
            referralpassword = PropertyService.getProperty("test.referralPassword");
126
			String authenClass = PropertyService.getProperty("auth.class");
127
			if(authenClass != null && authenClass.equals(AUTHFILECLASSNAME)) {
128
			    //add those test users to the authentication file
129
			    AuthFile authFile = new AuthFile();
130
			    String[] groups = null;
131
			    try {
132
			        authFile.addUser(username, groups, password, null, null, null, null, null);
133
			    } catch (Exception e) {
134
			        System.out.println("Couldn't add the user "+username+" to the password file since "+e.getMessage());
135
			    }
136
			    
137
			    try {
138
                    authFile.addUser(anotheruser, groups, anotherpassword, null, null, null, null, null);
139
                } catch (Exception e) {
140
                    System.out.println("Couldn't add the user "+anotheruser+" to the password file since "+e.getMessage());
141
                }
142
			    try {
143
                    authFile.addUser(lteruser, groups, lterpassword, null, null, null, null, null);
144
                } catch (Exception e) {
145
                    System.out.println("Couldn't add the user "+lteruser+" to the password file since "+e.getMessage());
146
                }
147
			    try {
148
                    authFile.addUser(referraluser, groups, referralpassword, null, null, null, null, null);
149
                } catch (Exception e) {
150
                    System.out.println("Couldn't add the user "+referraluser+" to the password file since "+e.getMessage());
151
                }
152
			}
116 153
		} catch (IOException ioe) {
117 154
			System.err.println("Could not read property file in static block: " 
118 155
					+ ioe.getMessage());

Also available in: Unified diff