Revision 974
Added by Jing Tao over 22 years ago
junittests/edu/ucsb/nceas/metacatjunittests/MetaCatURLTest.java | ||
---|---|---|
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 |
* Release: @release@ |
|
8 |
* |
|
9 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
12 |
* |
|
13 |
* This program is free software; you can redistribute it and/or modify |
|
14 |
* it under the terms of the GNU General Public License as published by |
|
15 |
* the Free Software Foundation; either version 2 of the License, or |
|
16 |
* (at your option) any later version. |
|
17 |
* |
|
18 |
* This program is distributed in the hope that it will be useful, |
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
* GNU General Public License for more details. |
|
22 |
* |
|
23 |
* You should have received a copy of the GNU General Public License |
|
24 |
* along with this program; if not, write to the Free Software |
|
25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
*/ |
|
27 |
|
|
28 |
package edu.ucsb.nceas.metacatjunittests; |
|
29 |
|
|
30 |
import edu.ucsb.nceas.metacat.*; |
|
31 |
|
|
32 |
import junit.framework.Test; |
|
33 |
import junit.framework.TestCase; |
|
34 |
import junit.framework.TestResult; |
|
35 |
import junit.framework.TestSuite; |
|
36 |
|
|
37 |
/** |
|
38 |
* A JUnit test for testing Step class processing |
|
39 |
*/ |
|
40 |
public class MetaCatURLTest extends TestCase |
|
41 |
{ |
|
42 |
private MetacatURL withProtocol =null; |
|
43 |
private String withHttp="http://dev.nceas.ucsb.edu/tao/test.txt"; |
|
44 |
/** |
|
45 |
* Constructor to build the test |
|
46 |
* |
|
47 |
* @param name the name of the test method |
|
48 |
*/ |
|
49 |
public MetaCatURLTest(String name) |
|
50 |
{ |
|
51 |
super(name); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Establish a testing framework by initializing appropriate objects |
|
56 |
*/ |
|
57 |
public void setUp() |
|
58 |
{ |
|
59 |
try |
|
60 |
{ |
|
61 |
|
|
62 |
withProtocol=new MetacatURL(withHttp); |
|
63 |
|
|
64 |
} |
|
65 |
catch (Exception e) |
|
66 |
{ |
|
67 |
fail("Caught exception while setting up MetaCatURL test."); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Release any objects after tests are complete |
|
73 |
*/ |
|
74 |
public void tearDown() |
|
75 |
{ |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Create a suite of tests to be run together |
|
80 |
*/ |
|
81 |
public static Test suite() |
|
82 |
{ |
|
83 |
TestSuite suite = new TestSuite(); |
|
84 |
suite.addTest(new MetaCatURLTest("initialize")); |
|
85 |
suite.addTest(new MetaCatURLTest("testGetProtocol")); |
|
86 |
suite.addTest(new MetaCatURLTest("testToString")); |
|
87 |
suite.addTest(new MetaCatURLTest("testGetParameter")); |
|
88 |
return suite; |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Run an initial test that always passes to check that the test |
|
93 |
* harness is working. |
|
94 |
*/ |
|
95 |
public void initialize() |
|
96 |
{ |
|
97 |
assert(1 == 1); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Test if the getProtocol() function works given a url |
|
102 |
*/ |
|
103 |
public void testGetProtocol() |
|
104 |
{ |
|
105 |
assert( withProtocol.getProtocol().equals("http")); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Test if the toString() function works given a url |
|
110 |
*/ |
|
111 |
public void testToString() |
|
112 |
{ |
|
113 |
assert((withProtocol.toString()).equals(withHttp)); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Test if the getParam() function works given a url |
|
118 |
*/ |
|
119 |
public void testGetParameter() |
|
120 |
{ |
|
121 |
String [] str= new String[2]; |
|
122 |
str=withProtocol.getParam(0); |
|
123 |
assert(str[0].equals("httpurl")); |
|
124 |
assert(str[1].equals("http://dev.nceas.ucsb.edu/tao/test.txt")); |
|
125 |
str=withProtocol.getParam(1); |
|
126 |
assert(str[0].equals("filename")); |
|
127 |
assert(str[1].equals("test.txt")); |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
} |
|
0 | 132 |
Also available in: Unified diff
This is sample JUnit test file for MetacatURL class. In this file, getProtocol, toString and getParam methods are tested.