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