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: costa $'
|
10
|
* '$Date: 2004-08-26 13:45:59 -0700 (Thu, 26 Aug 2004) $'
|
11
|
* '$Revision: 2254 $'
|
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 java.io.File;
|
33
|
import java.util.Date;
|
34
|
import javax.xml.parsers.ParserConfigurationException;
|
35
|
import junit.framework.Test;
|
36
|
import junit.framework.TestCase;
|
37
|
import junit.framework.TestSuite;
|
38
|
|
39
|
/**
|
40
|
* Test HarvestSiteSchedule code using JUnit.
|
41
|
*
|
42
|
* @author costa
|
43
|
*/
|
44
|
public class HarvestSiteScheduleTest extends TestCase {
|
45
|
|
46
|
private Harvester harvester;
|
47
|
private HarvestSiteSchedule harvestSiteScheduleFuture; // future date next har
|
48
|
private HarvestSiteSchedule harvestSiteSchedulePast; // past date next harvest
|
49
|
|
50
|
|
51
|
public HarvestSiteScheduleTest(String name) {
|
52
|
super(name);
|
53
|
}
|
54
|
|
55
|
|
56
|
protected void setUp() {
|
57
|
String contactEmail = "jdoe@institution.edu";
|
58
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
59
|
String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
|
60
|
String dateNextHarvestPast = "2000-01-01 00:00:00.0";
|
61
|
String documentListURL =
|
62
|
"http://www.lternet.edu/~dcosta/lnoHarvestList.xml";
|
63
|
String errorMessage = "JUnit Testing";
|
64
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
65
|
String ldapPwd = "secretpassword";
|
66
|
int siteScheduleID = 1;
|
67
|
boolean test = true;
|
68
|
String unit = "months";
|
69
|
int updateFrequency = 1;
|
70
|
|
71
|
harvester = new Harvester();
|
72
|
Harvester.loadOptions(test);
|
73
|
harvester.getConnection(); // initializes the database connection
|
74
|
harvester.initLogIDs();
|
75
|
harvester.setHarvestStartTime(new Date());
|
76
|
|
77
|
harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
|
78
|
siteScheduleID,
|
79
|
documentListURL,
|
80
|
ldapDN,
|
81
|
ldapPwd,
|
82
|
dateNextHarvestFuture,
|
83
|
dateLastHarvest,
|
84
|
updateFrequency,
|
85
|
unit,
|
86
|
contactEmail
|
87
|
);
|
88
|
|
89
|
harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
|
90
|
siteScheduleID,
|
91
|
documentListURL,
|
92
|
ldapDN,
|
93
|
ldapPwd,
|
94
|
dateNextHarvestPast,
|
95
|
dateLastHarvest,
|
96
|
updateFrequency,
|
97
|
unit,
|
98
|
contactEmail
|
99
|
);
|
100
|
|
101
|
}
|
102
|
|
103
|
|
104
|
protected void tearDown() {
|
105
|
harvester.closeConnection();
|
106
|
}
|
107
|
|
108
|
|
109
|
public void testDueForHarvestFalse() {
|
110
|
boolean dueForHarvest;
|
111
|
|
112
|
dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
|
113
|
assertTrue(dueForHarvest == false);
|
114
|
}
|
115
|
|
116
|
|
117
|
public void testParseHarvestList() {
|
118
|
boolean success = false;
|
119
|
String schemaLocation =
|
120
|
"eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
|
121
|
|
122
|
harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
|
123
|
|
124
|
try {
|
125
|
success = harvestSiteScheduleFuture.parseHarvestList();
|
126
|
assertTrue(success == true);
|
127
|
}
|
128
|
catch (ParserConfigurationException e) {
|
129
|
fail("ParserConfigurationException: " + e.getMessage());
|
130
|
}
|
131
|
}
|
132
|
|
133
|
|
134
|
/**
|
135
|
* Tests the printOutput() method.
|
136
|
*/
|
137
|
public void testPrintOutput() {
|
138
|
harvestSiteScheduleFuture.printOutput(System.out);
|
139
|
}
|
140
|
|
141
|
|
142
|
public void testDueForHarvestTrue() {
|
143
|
boolean dueForHarvest;
|
144
|
|
145
|
dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
|
146
|
assertTrue(dueForHarvest == true);
|
147
|
}
|
148
|
|
149
|
|
150
|
/**
|
151
|
* Test that the harvesterDocument object was created successfully.
|
152
|
*/
|
153
|
public void testHarvestSiteScheduleObject() {
|
154
|
assertTrue(harvestSiteScheduleFuture != null);
|
155
|
assertTrue(harvestSiteSchedulePast != null);
|
156
|
}
|
157
|
|
158
|
|
159
|
/**
|
160
|
* Returns the test suite. The test suite consists of all methods in this
|
161
|
* class whose names start with "test".
|
162
|
*
|
163
|
* @return a TestSuite object
|
164
|
*/
|
165
|
public static Test suite() {
|
166
|
return new TestSuite(HarvestSiteScheduleTest.class);
|
167
|
}
|
168
|
|
169
|
|
170
|
/**
|
171
|
* The main program. Runs the test suite.
|
172
|
*
|
173
|
* @param args command line argument array.
|
174
|
*/
|
175
|
public static void main(String args[]) {
|
176
|
junit.textui.TestRunner.run(suite());
|
177
|
}
|
178
|
|
179
|
}
|