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