1 |
2134
|
costa
|
/**
|
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$'
|
10 |
|
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
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 |
4385
|
daigle
|
import edu.ucsb.nceas.MCTestCase;
|
31 |
2143
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
|
32 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
33 |
2134
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
34 |
5035
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
35 |
4701
|
daigle
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
36 |
3566
|
tao
|
|
37 |
2143
|
costa
|
import java.io.StringReader;
|
38 |
|
|
import java.util.Date;
|
39 |
2134
|
costa
|
import junit.framework.Test;
|
40 |
|
|
import junit.framework.TestSuite;
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
2255
|
costa
|
* Tests HarvestDocument code using JUnit.
|
44 |
2134
|
costa
|
*
|
45 |
|
|
* @author costa
|
46 |
|
|
*/
|
47 |
4385
|
daigle
|
public class HarvestDocumentTest extends MCTestCase {
|
48 |
2134
|
costa
|
|
49 |
|
|
private Harvester harvester;
|
50 |
2143
|
costa
|
private HarvestDocument harvestDocument;
|
51 |
|
|
private HarvestSiteSchedule harvestSiteSchedule;
|
52 |
4127
|
daigle
|
/* Initialize Properties*/
|
53 |
3566
|
tao
|
static
|
54 |
|
|
{
|
55 |
|
|
try
|
56 |
|
|
{
|
57 |
4816
|
daigle
|
PropertyService.getInstance();
|
58 |
3566
|
tao
|
}
|
59 |
|
|
catch(Exception e)
|
60 |
|
|
{
|
61 |
|
|
System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
2134
|
costa
|
|
65 |
2255
|
costa
|
/**
|
66 |
|
|
* Constructor for this test.
|
67 |
|
|
*
|
68 |
|
|
* @param name name of the test case
|
69 |
|
|
*/
|
70 |
2134
|
costa
|
public HarvestDocumentTest(String name) {
|
71 |
|
|
super(name);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
2255
|
costa
|
|
75 |
|
|
/**
|
76 |
|
|
* Sets up the test by instantiating HarvestSiteSchedule and HarvestDocument
|
77 |
|
|
* objects.
|
78 |
|
|
*/
|
79 |
2134
|
costa
|
protected void setUp() {
|
80 |
4999
|
costa
|
boolean commandLineMode = true;
|
81 |
2143
|
costa
|
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 |
6356
|
leinfelder
|
"https://code.ecoinformatics.org/code/metacat/branches/METACAT_1_9_4_BRANCH/test/harvester/sampleHarvestList.xml";
|
87 |
2143
|
costa
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
88 |
2382
|
costa
|
String documentURL =
|
89 |
6356
|
leinfelder
|
"https://code.ecoinformatics.org/code/metacat/branches/METACAT_1_9_4_BRANCH/test/eml-sample.xml";
|
90 |
2143
|
costa
|
String errorMessage = "JUnit Testing";
|
91 |
|
|
int harvestLogID;
|
92 |
4172
|
daigle
|
String harvestOperationCode = "harvester.HarvesterStartup";
|
93 |
2143
|
costa
|
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 |
2158
|
costa
|
boolean test = true;
|
103 |
2143
|
costa
|
String unit = "months";
|
104 |
|
|
int updateFrequency = 1;
|
105 |
|
|
|
106 |
2134
|
costa
|
harvester = new Harvester();
|
107 |
4999
|
costa
|
Harvester.loadProperties(commandLineMode, test);
|
108 |
2143
|
costa
|
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 |
2134
|
costa
|
}
|
133 |
|
|
|
134 |
2255
|
costa
|
|
135 |
|
|
/**
|
136 |
|
|
* Closes the database connection after the test completes.
|
137 |
|
|
*/
|
138 |
2134
|
costa
|
protected void tearDown() {
|
139 |
2143
|
costa
|
harvester.closeConnection();
|
140 |
2134
|
costa
|
}
|
141 |
2143
|
costa
|
|
142 |
2255
|
costa
|
|
143 |
|
|
/**
|
144 |
|
|
* Tests the getSiteDocument() method. The test succeeds if a non-null
|
145 |
|
|
* StringReader is returned.
|
146 |
|
|
*/
|
147 |
2143
|
costa
|
public void testGetSiteDocument() {
|
148 |
|
|
StringReader stringReader = null;
|
149 |
|
|
stringReader = harvestDocument.getSiteDocument();
|
150 |
|
|
assertTrue(stringReader != null);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
/**
|
155 |
2255
|
costa
|
* Tests that the harvesterDocument object was created successfully.
|
156 |
2143
|
costa
|
*/
|
157 |
|
|
public void testHarvestDocumentObject() {
|
158 |
|
|
assertTrue(harvestDocument != null);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
2255
|
costa
|
|
162 |
|
|
/**
|
163 |
|
|
* Tests the metacatHighestRevision() method. This test ensures that -1
|
164 |
|
|
* is returned for a non-existent document.
|
165 |
|
|
*/
|
166 |
2143
|
costa
|
public void testMetacatHighestRevision() {
|
167 |
|
|
int highestRevision;
|
168 |
|
|
|
169 |
|
|
highestRevision = harvestDocument.metacatHighestRevision();
|
170 |
|
|
assertTrue(highestRevision == -1);
|
171 |
|
|
}
|
172 |
2134
|
costa
|
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
2143
|
costa
|
* Tests the printOutput() method.
|
176 |
2134
|
costa
|
*/
|
177 |
2143
|
costa
|
public void testPrintOutput() {
|
178 |
|
|
harvestDocument.printOutput(System.out);
|
179 |
2134
|
costa
|
}
|
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 |
|
|
}
|