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 HarvestLog class by using JUnit
|
8
|
*
|
9
|
* '$Author: leinfelder $'
|
10
|
* '$Date: 2013-07-31 23:34:34 -0700 (Wed, 31 Jul 2013) $'
|
11
|
* '$Revision: 8099 $'
|
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.HarvestSiteSchedule;
|
31
|
import java.sql.Connection;
|
32
|
import java.util.Date;
|
33
|
|
34
|
import edu.ucsb.nceas.MCTestCase;
|
35
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
36
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
|
37
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestLog;
|
38
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
39
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
40
|
|
41
|
import junit.framework.Test;
|
42
|
import junit.framework.TestSuite;
|
43
|
|
44
|
/**
|
45
|
* Tests HarvestLog code using JUnit.
|
46
|
*
|
47
|
* @author costa
|
48
|
*/
|
49
|
public class HarvestLogTest extends MCTestCase {
|
50
|
|
51
|
private Connection conn;
|
52
|
private Harvester harvester;
|
53
|
private HarvestLog harvestLogShallow;
|
54
|
private HarvestLog harvestLogDeep;
|
55
|
private HarvestSiteSchedule harvestSiteSchedule;
|
56
|
/* Initialize Properties*/
|
57
|
static
|
58
|
{
|
59
|
try
|
60
|
{
|
61
|
PropertyService.getInstance();
|
62
|
}
|
63
|
catch(Exception e)
|
64
|
{
|
65
|
System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
|
66
|
}
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Constructor for this test.
|
71
|
*
|
72
|
* @param name name of the test case
|
73
|
*/
|
74
|
public HarvestLogTest(String name) {
|
75
|
super(name);
|
76
|
}
|
77
|
|
78
|
|
79
|
/**
|
80
|
* Sets up the test by instantiating a HarvestSiteSchedule, HarvestDocument,
|
81
|
* and two HarvestLog objects. The harvestLogShallow is a HarvestLog that
|
82
|
* does not have an associated HarvestDetailLog. The harvestLogDeep is a
|
83
|
* HarvestLog that does have an associated HarvestDetailLog.
|
84
|
*/
|
85
|
protected void setUp() {
|
86
|
boolean commandLineMode = true;
|
87
|
String contactEmail = "jdoe@institution.edu";
|
88
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
89
|
String dateNextHarvest = "2004-05-01 00:00:00.0";
|
90
|
int detailLogID;
|
91
|
String documentListURL =
|
92
|
"http://www.institution.edu/~jdoe/public_html/harvestList.xml";
|
93
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
94
|
String documentURL =
|
95
|
"http://www.institution.edu/~jdoe/public_html/document1.xml";
|
96
|
String errorMessage = "JUnit Testing";
|
97
|
HarvestDocument harvestDocument = null;
|
98
|
int harvestLogID;
|
99
|
String harvestOperationCode = "harvester.HarvesterStartup";
|
100
|
Date harvestStartTime = new Date();
|
101
|
int identifier = 1;
|
102
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
103
|
String ldapPwd = "secretpassword";
|
104
|
String message = "JUnit Testing";
|
105
|
int revision = 1;
|
106
|
String scope = "docname";
|
107
|
int siteScheduleID = 1;
|
108
|
int status = 0;
|
109
|
boolean test = true;
|
110
|
String unit = "months";
|
111
|
int updateFrequency = 1;
|
112
|
|
113
|
harvester = new Harvester();
|
114
|
Harvester.loadProperties(metacatContextDir);
|
115
|
conn = harvester.getConnection(); // initializes the database connection
|
116
|
harvester.initLogIDs();
|
117
|
harvestLogID = harvester.getHarvestLogID();
|
118
|
harvestLogShallow = new HarvestLog(harvester, conn, harvestLogID,
|
119
|
harvestStartTime, status,
|
120
|
message, harvestOperationCode,
|
121
|
siteScheduleID);
|
122
|
|
123
|
harvestLogID = harvester.getHarvestLogID();
|
124
|
detailLogID = harvester.getDetailLogID();
|
125
|
harvestSiteSchedule = new HarvestSiteSchedule(harvester,
|
126
|
siteScheduleID,
|
127
|
documentListURL,
|
128
|
ldapDN,
|
129
|
ldapPwd,
|
130
|
dateNextHarvest,
|
131
|
dateLastHarvest,
|
132
|
updateFrequency,
|
133
|
unit,
|
134
|
contactEmail
|
135
|
);
|
136
|
|
137
|
harvestDocument = new HarvestDocument(harvester,
|
138
|
harvestSiteSchedule,
|
139
|
scope,
|
140
|
identifier,
|
141
|
revision,
|
142
|
documentType,
|
143
|
documentURL
|
144
|
);
|
145
|
|
146
|
|
147
|
harvestLogDeep = new HarvestLog(harvester, conn, harvestLogID, detailLogID,
|
148
|
harvestStartTime, status, message,
|
149
|
harvestOperationCode, siteScheduleID,
|
150
|
harvestDocument, errorMessage);
|
151
|
}
|
152
|
|
153
|
|
154
|
/**
|
155
|
* Closes the database connection after the test completes.
|
156
|
*/
|
157
|
protected void tearDown() {
|
158
|
harvester.closeConnection();
|
159
|
}
|
160
|
|
161
|
|
162
|
/**
|
163
|
* Tests the getCodeLevelValue() method by comparing the value returned for
|
164
|
* "error" (lowest level) to the value returned for "debug" (highest level).
|
165
|
*/
|
166
|
public void testGetCodeLevelValue() {
|
167
|
int lowLevel = harvestLogShallow.getCodeLevelValue("error");
|
168
|
int highLevel = harvestLogShallow.getCodeLevelValue("debug");
|
169
|
|
170
|
assertTrue(lowLevel < highLevel);
|
171
|
}
|
172
|
|
173
|
|
174
|
/**
|
175
|
* Tests the getExplanation() method. Check that a harvest operation code is
|
176
|
* associated with an appropriate explanation string.
|
177
|
*/
|
178
|
public void testGetExplanation() {
|
179
|
String harvestOperationCode = "harvester.HarvesterStartup";
|
180
|
String explanation;
|
181
|
|
182
|
explanation = harvestLogShallow.getExplanation(harvestOperationCode);
|
183
|
assertTrue(explanation.equals("Harvester start up"));
|
184
|
}
|
185
|
|
186
|
|
187
|
/**
|
188
|
* Tests the getHarvestOperationCodeLevel() method. Check that the method
|
189
|
* returns an appropriate code level for a given harvest operation code.
|
190
|
*/
|
191
|
public void testGetHarvestOperationCodeLevel() {
|
192
|
String harvestOperationCode = "harvester.HarvesterStartup";
|
193
|
String harvestOperationCodeLevel;
|
194
|
|
195
|
harvestOperationCodeLevel =
|
196
|
harvestLogShallow.getHarvestOperationCodeLevel(harvestOperationCode);
|
197
|
assertTrue(harvestOperationCodeLevel.equalsIgnoreCase("Info"));
|
198
|
}
|
199
|
|
200
|
|
201
|
/**
|
202
|
* Tests the construction of HarvestLog object, and a HarvestLog object
|
203
|
* that contains a HarvestDetailLog object.
|
204
|
*/
|
205
|
public void testHarvestLogObject() {
|
206
|
assertTrue(harvestLogShallow != null);
|
207
|
assertTrue(harvestLogDeep != null);
|
208
|
}
|
209
|
|
210
|
|
211
|
/**
|
212
|
* Tests the printOutput() method when the code level of this operation is
|
213
|
* greater than the maximum level we wish to print. This means that the output
|
214
|
* should not be printed.
|
215
|
*/
|
216
|
public void testPrintOutputExceedsMax() {
|
217
|
System.out.println("No output should be printed:");
|
218
|
harvestLogDeep.printOutput(System.out, "Error");
|
219
|
}
|
220
|
|
221
|
|
222
|
/**
|
223
|
* Tests the printOutput() method when the code level of this operation is
|
224
|
* less than the maximum level we wish to print. This means that the output
|
225
|
* should be printed.
|
226
|
*/
|
227
|
public void testPrintOutputWithinMax() {
|
228
|
System.out.println("The log output should be printed:");
|
229
|
harvestLogDeep.printOutput(System.out, "Debug");
|
230
|
}
|
231
|
|
232
|
|
233
|
/**
|
234
|
* Returns the test suite. The test suite consists of all methods in this
|
235
|
* class whose names start with "test".
|
236
|
*
|
237
|
* @return a TestSuite object
|
238
|
*/
|
239
|
public static Test suite() {
|
240
|
return new TestSuite(HarvestLogTest.class);
|
241
|
}
|
242
|
|
243
|
|
244
|
/**
|
245
|
* The main program. Runs the test suite.
|
246
|
*
|
247
|
* @param args command line argument array.
|
248
|
*/
|
249
|
public static void main(String args[]) {
|
250
|
junit.textui.TestRunner.run(suite());
|
251
|
}
|
252
|
|
253
|
}
|