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 HarvestSiteSchedule 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 |
2143
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
33 |
4080
|
daigle
|
import edu.ucsb.nceas.metacat.service.PropertyService;
|
34 |
4701
|
daigle
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
35 |
3566
|
tao
|
|
36 |
2143
|
costa
|
import java.util.Date;
|
37 |
|
|
import javax.xml.parsers.ParserConfigurationException;
|
38 |
2134
|
costa
|
import junit.framework.Test;
|
39 |
|
|
import junit.framework.TestSuite;
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
2255
|
costa
|
* Tests HarvestSiteSchedule code using JUnit.
|
43 |
2134
|
costa
|
*
|
44 |
|
|
* @author costa
|
45 |
|
|
*/
|
46 |
4385
|
daigle
|
public class HarvestSiteScheduleTest extends MCTestCase {
|
47 |
2134
|
costa
|
|
48 |
|
|
private Harvester harvester;
|
49 |
2143
|
costa
|
private HarvestSiteSchedule harvestSiteScheduleFuture; // future date next har
|
50 |
|
|
private HarvestSiteSchedule harvestSiteSchedulePast; // past date next harvest
|
51 |
4127
|
daigle
|
/* Initialize Properties*/
|
52 |
3566
|
tao
|
static
|
53 |
|
|
{
|
54 |
|
|
try
|
55 |
|
|
{
|
56 |
4816
|
daigle
|
PropertyService.getInstance();
|
57 |
3566
|
tao
|
}
|
58 |
|
|
catch(Exception e)
|
59 |
|
|
{
|
60 |
|
|
System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
2134
|
costa
|
|
64 |
2255
|
costa
|
/**
|
65 |
|
|
* Constructor for this test.
|
66 |
|
|
*
|
67 |
|
|
* @param name name of the test case
|
68 |
|
|
*/
|
69 |
2134
|
costa
|
public HarvestSiteScheduleTest(String name) {
|
70 |
|
|
super(name);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
2255
|
costa
|
|
74 |
|
|
/**
|
75 |
|
|
* Sets up the HarvestSiteScheduleTest by creating a pair of
|
76 |
|
|
* HarvestSiteSchedule objects. The harvestSiteScheduleFuture object
|
77 |
|
|
* is used for a site with a future date of next harvest (not due for
|
78 |
|
|
* harvest now), while the harvestSiteSchedulePast object is used for a site
|
79 |
|
|
* with a past date of next harvest (is due for harvest now).
|
80 |
|
|
*/
|
81 |
2134
|
costa
|
protected void setUp() {
|
82 |
2143
|
costa
|
String contactEmail = "jdoe@institution.edu";
|
83 |
|
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
84 |
|
|
String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
|
85 |
|
|
String dateNextHarvestPast = "2000-01-01 00:00:00.0";
|
86 |
2254
|
costa
|
String documentListURL =
|
87 |
2382
|
costa
|
"http://www.lternet.edu/~dcosta/testHarvest/lnoHarvestList.xml";
|
88 |
2143
|
costa
|
String errorMessage = "JUnit Testing";
|
89 |
|
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
90 |
|
|
String ldapPwd = "secretpassword";
|
91 |
|
|
int siteScheduleID = 1;
|
92 |
2158
|
costa
|
boolean test = true;
|
93 |
2143
|
costa
|
String unit = "months";
|
94 |
|
|
int updateFrequency = 1;
|
95 |
|
|
|
96 |
2134
|
costa
|
harvester = new Harvester();
|
97 |
4127
|
daigle
|
Harvester.loadProperties(test);
|
98 |
2143
|
costa
|
harvester.getConnection(); // initializes the database connection
|
99 |
|
|
harvester.initLogIDs();
|
100 |
|
|
harvester.setHarvestStartTime(new Date());
|
101 |
|
|
|
102 |
|
|
harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
|
103 |
|
|
siteScheduleID,
|
104 |
|
|
documentListURL,
|
105 |
|
|
ldapDN,
|
106 |
|
|
ldapPwd,
|
107 |
|
|
dateNextHarvestFuture,
|
108 |
|
|
dateLastHarvest,
|
109 |
|
|
updateFrequency,
|
110 |
|
|
unit,
|
111 |
|
|
contactEmail
|
112 |
|
|
);
|
113 |
|
|
|
114 |
|
|
harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
|
115 |
|
|
siteScheduleID,
|
116 |
|
|
documentListURL,
|
117 |
|
|
ldapDN,
|
118 |
|
|
ldapPwd,
|
119 |
|
|
dateNextHarvestPast,
|
120 |
|
|
dateLastHarvest,
|
121 |
|
|
updateFrequency,
|
122 |
|
|
unit,
|
123 |
|
|
contactEmail
|
124 |
|
|
);
|
125 |
|
|
|
126 |
2134
|
costa
|
}
|
127 |
|
|
|
128 |
2255
|
costa
|
|
129 |
|
|
/**
|
130 |
|
|
* Closes the database connection after the test completes.
|
131 |
|
|
*/
|
132 |
2134
|
costa
|
protected void tearDown() {
|
133 |
2143
|
costa
|
harvester.closeConnection();
|
134 |
2134
|
costa
|
}
|
135 |
2143
|
costa
|
|
136 |
2255
|
costa
|
|
137 |
|
|
/**
|
138 |
|
|
* Tests the dueForHarvest() method in the case where a site is not due for
|
139 |
|
|
* a harvest.
|
140 |
|
|
*/
|
141 |
2143
|
costa
|
public void testDueForHarvestFalse() {
|
142 |
|
|
boolean dueForHarvest;
|
143 |
|
|
|
144 |
|
|
dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
|
145 |
|
|
assertTrue(dueForHarvest == false);
|
146 |
|
|
}
|
147 |
|
|
|
148 |
2255
|
costa
|
|
149 |
|
|
/**
|
150 |
|
|
* Tests the dueForHarvest() method in the case where a site is due for
|
151 |
|
|
* a harvest.
|
152 |
|
|
*/
|
153 |
|
|
public void testDueForHarvestTrue() {
|
154 |
|
|
boolean dueForHarvest;
|
155 |
|
|
|
156 |
|
|
dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
|
157 |
|
|
assertTrue(dueForHarvest == true);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
/**
|
162 |
|
|
* Tests the parseHarvestList() method.
|
163 |
|
|
*/
|
164 |
2143
|
costa
|
public void testParseHarvestList() {
|
165 |
|
|
boolean success = false;
|
166 |
|
|
String schemaLocation =
|
167 |
|
|
"eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
|
168 |
|
|
|
169 |
|
|
harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
|
170 |
|
|
|
171 |
|
|
try {
|
172 |
|
|
success = harvestSiteScheduleFuture.parseHarvestList();
|
173 |
|
|
assertTrue(success == true);
|
174 |
|
|
}
|
175 |
|
|
catch (ParserConfigurationException e) {
|
176 |
|
|
fail("ParserConfigurationException: " + e.getMessage());
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
2134
|
costa
|
|
180 |
|
|
|
181 |
|
|
/**
|
182 |
2143
|
costa
|
* Tests the printOutput() method.
|
183 |
2134
|
costa
|
*/
|
184 |
2143
|
costa
|
public void testPrintOutput() {
|
185 |
|
|
harvestSiteScheduleFuture.printOutput(System.out);
|
186 |
2134
|
costa
|
}
|
187 |
|
|
|
188 |
2143
|
costa
|
|
189 |
2134
|
costa
|
/**
|
190 |
2255
|
costa
|
* Tests that the harvesterDocument object was created successfully.
|
191 |
2143
|
costa
|
*/
|
192 |
|
|
public void testHarvestSiteScheduleObject() {
|
193 |
|
|
assertTrue(harvestSiteScheduleFuture != null);
|
194 |
|
|
assertTrue(harvestSiteSchedulePast != null);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
/**
|
199 |
2134
|
costa
|
* Returns the test suite. The test suite consists of all methods in this
|
200 |
|
|
* class whose names start with "test".
|
201 |
|
|
*
|
202 |
|
|
* @return a TestSuite object
|
203 |
|
|
*/
|
204 |
|
|
public static Test suite() {
|
205 |
|
|
return new TestSuite(HarvestSiteScheduleTest.class);
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
/**
|
210 |
|
|
* The main program. Runs the test suite.
|
211 |
|
|
*
|
212 |
|
|
* @param args command line argument array.
|
213 |
|
|
*/
|
214 |
|
|
public static void main(String args[]) {
|
215 |
|
|
junit.textui.TestRunner.run(suite());
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
}
|