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