1 |
2134
|
costa
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2004 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis,
|
5 |
|
|
* and the University of New Mexico
|
6 |
|
|
*
|
7 |
|
|
* Purpose: To test the Harvester class by using JUnit
|
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.metacattest.harvesterClient;
|
29 |
|
|
|
30 |
4385
|
daigle
|
import edu.ucsb.nceas.MCTestCase;
|
31 |
2134
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
32 |
4080
|
daigle
|
import edu.ucsb.nceas.metacat.service.PropertyService;
|
33 |
4701
|
daigle
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
34 |
4127
|
daigle
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
35 |
4385
|
daigle
|
|
36 |
2134
|
costa
|
import junit.framework.Test;
|
37 |
|
|
import junit.framework.TestSuite;
|
38 |
|
|
|
39 |
|
|
/**
|
40 |
2255
|
costa
|
* Tests Harvester code using JUnit.
|
41 |
2134
|
costa
|
*
|
42 |
|
|
* @author costa
|
43 |
|
|
*/
|
44 |
4385
|
daigle
|
public class HarvesterTest extends MCTestCase {
|
45 |
2134
|
costa
|
|
46 |
|
|
private Harvester harvester;
|
47 |
4127
|
daigle
|
/* Initialize Properties */
|
48 |
|
|
static {
|
49 |
|
|
try {
|
50 |
4701
|
daigle
|
MetacatUtil.pathsForIndexing = MetacatUtil.getOptionList(
|
51 |
4213
|
daigle
|
PropertyService.getProperty("xml.indexPaths"));
|
52 |
4127
|
daigle
|
} catch (Exception e) {
|
53 |
|
|
System.err.println("Exception in initialize option in MetacatServletNetTest "
|
54 |
|
|
+ e.getMessage());
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
2134
|
costa
|
|
58 |
2255
|
costa
|
/**
|
59 |
4127
|
daigle
|
* Constructor for this test.
|
60 |
|
|
*
|
61 |
|
|
* @param name
|
62 |
|
|
* name of the test case
|
63 |
|
|
*/
|
64 |
2134
|
costa
|
public HarvesterTest(String name) {
|
65 |
|
|
super(name);
|
66 |
|
|
}
|
67 |
|
|
|
68 |
2255
|
costa
|
|
69 |
|
|
/**
|
70 |
|
|
* Sets up the test by instantiating a Harvester object.
|
71 |
|
|
*/
|
72 |
2134
|
costa
|
protected void setUp() {
|
73 |
|
|
harvester = new Harvester();
|
74 |
|
|
}
|
75 |
|
|
|
76 |
2255
|
costa
|
|
77 |
|
|
/**
|
78 |
|
|
* No clean-up actions necessary for these tests.
|
79 |
|
|
*/
|
80 |
2134
|
costa
|
protected void tearDown() {
|
81 |
|
|
}
|
82 |
|
|
|
83 |
2255
|
costa
|
|
84 |
|
|
/**
|
85 |
|
|
* Tests the dequoteText() string function. It converts single quotes to
|
86 |
|
|
* double quotes.
|
87 |
|
|
*/
|
88 |
2143
|
costa
|
public void testDequoteText() {
|
89 |
|
|
String singleQuoteString = "I can't see how it's done!\n";
|
90 |
|
|
String compareString = "I can\"t see how it\"s done!";
|
91 |
|
|
String dequotedString = "";
|
92 |
|
|
|
93 |
|
|
dequotedString = harvester.dequoteText(singleQuoteString);
|
94 |
|
|
assertTrue(dequotedString.equals(compareString));
|
95 |
|
|
System.out.println("Dequoted string: " + dequotedString);
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
|
99 |
2134
|
costa
|
/**
|
100 |
2255
|
costa
|
* Tests that the Harvester object was created successfully.
|
101 |
2143
|
costa
|
*/
|
102 |
|
|
public void testHarvesterObject() {
|
103 |
|
|
assertTrue(harvester != null);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
|
107 |
4127
|
daigle
|
/**
|
108 |
|
|
* Tests loading of Harvester properties from a configuration file.
|
109 |
|
|
*/
|
110 |
|
|
public void testLoadProperties() {
|
111 |
|
|
String ctm = null;
|
112 |
|
|
boolean test = true;
|
113 |
|
|
|
114 |
|
|
Harvester.loadProperties(test);
|
115 |
|
|
try {
|
116 |
4172
|
daigle
|
ctm = PropertyService.getProperty("harvester.connectToMetacat");
|
117 |
4127
|
daigle
|
} catch (PropertyNotFoundException pnfe) {
|
118 |
|
|
fail("Could not get connectToMetacat property: "+ pnfe.getMessage());
|
119 |
|
|
}
|
120 |
|
|
assertTrue(ctm.equals("true") || ctm.equals("false"));
|
121 |
|
|
}
|
122 |
2134
|
costa
|
|
123 |
|
|
|
124 |
|
|
/**
|
125 |
4127
|
daigle
|
* Prints the files in the current working directory. This may be useful for
|
126 |
|
|
* determining which directory all other tests are running in.
|
127 |
|
|
*/
|
128 |
2143
|
costa
|
public void testWorkingDirectory() {
|
129 |
|
|
String[] dir = new java.io.File(".").list(); // Get files in current dir
|
130 |
|
|
|
131 |
|
|
java.util.Arrays.sort(dir); // Sort the directory listing
|
132 |
|
|
|
133 |
|
|
for (int i=0; i<dir.length; i++)
|
134 |
|
|
System.out.println(dir[i]); // Print the list
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
/**
|
139 |
2134
|
costa
|
* Returns the test suite. The test suite consists of all methods in this
|
140 |
|
|
* class whose names start with "test".
|
141 |
|
|
*
|
142 |
|
|
* @return a TestSuite object
|
143 |
|
|
*/
|
144 |
|
|
public static Test suite() {
|
145 |
|
|
return new TestSuite(HarvesterTest.class);
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
/**
|
150 |
|
|
* The main program. Runs the test suite.
|
151 |
|
|
*
|
152 |
|
|
* @param args command line argument array.
|
153 |
|
|
*/
|
154 |
|
|
public static void main(String args[]) {
|
155 |
|
|
junit.textui.TestRunner.run(suite());
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
}
|