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 HarvestDetailLog class by using JUnit
|
8
|
*
|
9
|
* '$Author: daigle $'
|
10
|
* '$Date: 2008-07-15 10:16:18 -0700 (Tue, 15 Jul 2008) $'
|
11
|
* '$Revision: 4127 $'
|
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.Harvester;
|
31
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
|
32
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
|
33
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
34
|
import edu.ucsb.nceas.metacat.service.PropertyService;
|
35
|
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
|
36
|
|
37
|
import java.sql.Connection;
|
38
|
import junit.framework.Test;
|
39
|
import junit.framework.TestCase;
|
40
|
import junit.framework.TestSuite;
|
41
|
|
42
|
/**
|
43
|
* Tests HarvestDetailLog code using JUnit.
|
44
|
*
|
45
|
* @author costa
|
46
|
*/
|
47
|
public class HarvestDetailLogTest extends TestCase {
|
48
|
|
49
|
private Harvester harvester;
|
50
|
private HarvestDetailLog harvestDetailLog;
|
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("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 HarvestDetailLogTest(String name) {
|
74
|
super(name);
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
|
80
|
* and HarvestDetailLog objects.
|
81
|
*/
|
82
|
protected void setUp() {
|
83
|
Connection conn;
|
84
|
String contactEmail = "jdoe@institution.edu";
|
85
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
86
|
String dateNextHarvest = "2004-05-01 00:00:00.0";
|
87
|
int detailLogID;
|
88
|
String documentListURL =
|
89
|
"http://www.institution.edu/~jdoe/public_html/harvestList.xml";
|
90
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
91
|
String documentURL =
|
92
|
"http://www.institution.edu/~jdoe/public_html/document1.xml";
|
93
|
String errorMessage = "JUnit testing";
|
94
|
int harvestLogID;
|
95
|
int identifier = 1;
|
96
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
97
|
String ldapPwd = "secretpassword";
|
98
|
int revision = 1;
|
99
|
String scope = "docname";
|
100
|
int siteScheduleID = 1;
|
101
|
boolean test = true;
|
102
|
String unit = "months";
|
103
|
int updateFrequency = 1;
|
104
|
|
105
|
harvester = new Harvester();
|
106
|
Harvester.loadProperties(test);
|
107
|
conn = harvester.getConnection(); // initializes the database connection
|
108
|
harvester.initLogIDs();
|
109
|
harvestLogID = harvester.getHarvestLogID();
|
110
|
detailLogID = harvester.getDetailLogID();
|
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
|
harvestDetailLog = new HarvestDetailLog(harvester, conn, harvestLogID,
|
134
|
detailLogID, harvestDocument,
|
135
|
errorMessage);
|
136
|
}
|
137
|
|
138
|
|
139
|
/**
|
140
|
* Closes the database connection when the test completes.
|
141
|
*/
|
142
|
protected void tearDown() {
|
143
|
harvester.closeConnection();
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
* Tests that the harvestDetailLog object was constructed.
|
149
|
*/
|
150
|
public void testHarvestDetailLogObject() {
|
151
|
assertTrue(harvestDetailLog != null);
|
152
|
}
|
153
|
|
154
|
|
155
|
/**
|
156
|
* Tests the printOutput() method.
|
157
|
*/
|
158
|
public void testPrintOutput() {
|
159
|
harvestDetailLog.printOutput(System.out);
|
160
|
}
|
161
|
|
162
|
|
163
|
/**
|
164
|
* Returns the test suite. The test suite consists of all methods in this
|
165
|
* class whose names start with "test".
|
166
|
*
|
167
|
* @return a TestSuite object
|
168
|
*/
|
169
|
public static Test suite() {
|
170
|
return new TestSuite(HarvestDetailLogTest.class);
|
171
|
}
|
172
|
|
173
|
|
174
|
/**
|
175
|
* The main program. Runs the test suite.
|
176
|
*
|
177
|
* @param args command line argument array.
|
178
|
*/
|
179
|
public static void main(String args[]) {
|
180
|
junit.textui.TestRunner.run(suite());
|
181
|
}
|
182
|
|
183
|
}
|