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 HarvestDocument class by using JUnit
|
8
|
*
|
9
|
* '$Author: costa $'
|
10
|
* '$Date: 2005-01-20 14:22:28 -0800 (Thu, 20 Jan 2005) $'
|
11
|
* '$Revision: 2382 $'
|
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.HarvestDocument;
|
31
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
32
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
33
|
import java.io.File;
|
34
|
import java.io.StringReader;
|
35
|
import java.util.Date;
|
36
|
import junit.framework.Test;
|
37
|
import junit.framework.TestCase;
|
38
|
import junit.framework.TestSuite;
|
39
|
|
40
|
/**
|
41
|
* Tests HarvestDocument code using JUnit.
|
42
|
*
|
43
|
* @author costa
|
44
|
*/
|
45
|
public class HarvestDocumentTest extends TestCase {
|
46
|
|
47
|
private Harvester harvester;
|
48
|
private HarvestDocument harvestDocument;
|
49
|
private HarvestSiteSchedule harvestSiteSchedule;
|
50
|
|
51
|
|
52
|
/**
|
53
|
* Constructor for this test.
|
54
|
*
|
55
|
* @param name name of the test case
|
56
|
*/
|
57
|
public HarvestDocumentTest(String name) {
|
58
|
super(name);
|
59
|
}
|
60
|
|
61
|
|
62
|
/**
|
63
|
* Sets up the test by instantiating HarvestSiteSchedule and HarvestDocument
|
64
|
* objects.
|
65
|
*/
|
66
|
protected void setUp() {
|
67
|
String contactEmail = "jdoe@institution.edu";
|
68
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
69
|
String dateNextHarvest = "2004-05-01 00:00:00.0";
|
70
|
int detailLogID;
|
71
|
String documentListURL =
|
72
|
"http://www.institution.edu/~jdoe/public_html/harvestList.xml";
|
73
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
74
|
String documentURL =
|
75
|
"http://www.lternet.edu/~dcosta/testHarvest/document1.xml";
|
76
|
String errorMessage = "JUnit Testing";
|
77
|
int harvestLogID;
|
78
|
String harvestOperationCode = "HarvesterStartup";
|
79
|
Date harvestStartTime = new Date();
|
80
|
int identifier = 1;
|
81
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
82
|
String ldapPwd = "secretpassword";
|
83
|
String message = "JUnit Testing";
|
84
|
int revision = 1;
|
85
|
String scope = "docname";
|
86
|
int siteScheduleID = 1;
|
87
|
int status = 0;
|
88
|
boolean test = true;
|
89
|
String unit = "months";
|
90
|
int updateFrequency = 1;
|
91
|
|
92
|
harvester = new Harvester();
|
93
|
Harvester.loadOptions(test);
|
94
|
harvester.getConnection(); // initializes the database connection
|
95
|
harvester.initLogIDs();
|
96
|
harvester.setHarvestStartTime(new Date());
|
97
|
|
98
|
harvestSiteSchedule = new HarvestSiteSchedule(harvester,
|
99
|
siteScheduleID,
|
100
|
documentListURL,
|
101
|
ldapDN,
|
102
|
ldapPwd,
|
103
|
dateNextHarvest,
|
104
|
dateLastHarvest,
|
105
|
updateFrequency,
|
106
|
unit,
|
107
|
contactEmail
|
108
|
);
|
109
|
|
110
|
harvestDocument = new HarvestDocument(harvester,
|
111
|
harvestSiteSchedule,
|
112
|
scope,
|
113
|
identifier,
|
114
|
revision,
|
115
|
documentType,
|
116
|
documentURL
|
117
|
);
|
118
|
}
|
119
|
|
120
|
|
121
|
/**
|
122
|
* Closes the database connection after the test completes.
|
123
|
*/
|
124
|
protected void tearDown() {
|
125
|
harvester.closeConnection();
|
126
|
}
|
127
|
|
128
|
|
129
|
/**
|
130
|
* Tests the getSiteDocument() method. The test succeeds if a non-null
|
131
|
* StringReader is returned.
|
132
|
*/
|
133
|
public void testGetSiteDocument() {
|
134
|
StringReader stringReader = null;
|
135
|
stringReader = harvestDocument.getSiteDocument();
|
136
|
assertTrue(stringReader != null);
|
137
|
}
|
138
|
|
139
|
|
140
|
/**
|
141
|
* Tests that the harvesterDocument object was created successfully.
|
142
|
*/
|
143
|
public void testHarvestDocumentObject() {
|
144
|
assertTrue(harvestDocument != null);
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* Tests the metacatHighestRevision() method. This test ensures that -1
|
150
|
* is returned for a non-existent document.
|
151
|
*/
|
152
|
public void testMetacatHighestRevision() {
|
153
|
int highestRevision;
|
154
|
|
155
|
highestRevision = harvestDocument.metacatHighestRevision();
|
156
|
assertTrue(highestRevision == -1);
|
157
|
}
|
158
|
|
159
|
|
160
|
/**
|
161
|
* Tests the printOutput() method.
|
162
|
*/
|
163
|
public void testPrintOutput() {
|
164
|
harvestDocument.printOutput(System.out);
|
165
|
}
|
166
|
|
167
|
|
168
|
/**
|
169
|
* Returns the test suite. The test suite consists of all methods in this
|
170
|
* class whose names start with "test".
|
171
|
*
|
172
|
* @return a TestSuite object
|
173
|
*/
|
174
|
public static Test suite() {
|
175
|
return new TestSuite(HarvestDocumentTest.class);
|
176
|
}
|
177
|
|
178
|
|
179
|
/**
|
180
|
* The main program. Runs the test suite.
|
181
|
*
|
182
|
* @param args command line argument array.
|
183
|
*/
|
184
|
public static void main(String args[]) {
|
185
|
junit.textui.TestRunner.run(suite());
|
186
|
}
|
187
|
|
188
|
}
|