1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2003 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
|
*
|
7
|
* '$Author: jones $'
|
8
|
* '$Date: 2003-08-11 12:19:04 -0700 (Mon, 11 Aug 2003) $'
|
9
|
* '$Revision: 1783 $'
|
10
|
*
|
11
|
* This program is free software; you can redistribute it and/or modify
|
12
|
* it under the terms of the GNU General Public License as published by
|
13
|
* the Free Software Foundation; either version 2 of the License, or
|
14
|
* (at your option) any later version.
|
15
|
*
|
16
|
* This program is distributed in the hope that it will be useful,
|
17
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
* GNU General Public License for more details.
|
20
|
*
|
21
|
* You should have received a copy of the GNU General Public License
|
22
|
* along with this program; if not, write to the Free Software
|
23
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24
|
*/
|
25
|
|
26
|
package edu.ucsb.nceas.metacattest.client;
|
27
|
|
28
|
import edu.ucsb.nceas.metacat.client.*;
|
29
|
|
30
|
import junit.framework.Test;
|
31
|
import junit.framework.TestCase;
|
32
|
import junit.framework.TestResult;
|
33
|
import junit.framework.TestSuite;
|
34
|
|
35
|
/**
|
36
|
* A JUnit test for testing Step class processing
|
37
|
*/
|
38
|
public class MetacatClientTest extends TestCase
|
39
|
{
|
40
|
private String metacatUrl =
|
41
|
"http://knb.ecoinformatics.org/knb/servlet/metacat";
|
42
|
private String username = "@mcuser@";
|
43
|
private String password = "@mcpassword@";
|
44
|
private String failpass = "uidfnkj43987yfdn";
|
45
|
|
46
|
private Metacat m;
|
47
|
|
48
|
/**
|
49
|
* Constructor to build the test
|
50
|
*
|
51
|
* @param name the name of the test method
|
52
|
*/
|
53
|
public MetacatClientTest(String name)
|
54
|
{
|
55
|
super(name);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Establish a testing framework by initializing appropriate objects
|
60
|
*/
|
61
|
public void setUp()
|
62
|
{
|
63
|
try {
|
64
|
m = MetacatFactory.createMetacatConnection(metacatUrl);
|
65
|
} catch (MetacatInaccessibleException mie) {
|
66
|
fail("Metacat connection failed." + mie.getMessage());
|
67
|
}
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Release any objects after tests are complete
|
72
|
*/
|
73
|
public void tearDown()
|
74
|
{
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Create a suite of tests to be run together
|
79
|
*/
|
80
|
public static Test suite()
|
81
|
{
|
82
|
TestSuite suite = new TestSuite();
|
83
|
suite.addTest(new MetacatClientTest("initialize"));
|
84
|
suite.addTest(new MetacatClientTest("invalidLogin"));
|
85
|
suite.addTest(new MetacatClientTest("login"));
|
86
|
return suite;
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Run an initial test that always passes to check that the test
|
91
|
* harness is working.
|
92
|
*/
|
93
|
public void initialize()
|
94
|
{
|
95
|
assertTrue(1 == 1);
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Test the login() function with valid credentials
|
100
|
*/
|
101
|
public void login()
|
102
|
{
|
103
|
// Try a valid login
|
104
|
try {
|
105
|
m.login(username, password);
|
106
|
} catch (MetacatAuthException mae) {
|
107
|
fail("Authorization failed:\n" + mae.getMessage());
|
108
|
} catch (MetacatInaccessibleException mie) {
|
109
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
110
|
}
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Test the login() function with INVALID credentials
|
115
|
*/
|
116
|
public void invalidLogin()
|
117
|
{
|
118
|
// Try an invalid login
|
119
|
try {
|
120
|
System.err.println("Username: " + username);
|
121
|
m.login(username, failpass);
|
122
|
fail("Authorization should have failed.");
|
123
|
} catch (MetacatAuthException mae) {
|
124
|
assertTrue(1 == 1);
|
125
|
} catch (MetacatInaccessibleException mie) {
|
126
|
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
127
|
}
|
128
|
}
|
129
|
}
|