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 HarvestDetailLog 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 |
2134
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
32 |
2143
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
|
33 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
|
34 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
35 |
5035
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
36 |
4701
|
daigle
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
37 |
3566
|
tao
|
|
38 |
2143
|
costa
|
import java.sql.Connection;
|
39 |
2134
|
costa
|
import junit.framework.Test;
|
40 |
|
|
import junit.framework.TestSuite;
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
2255
|
costa
|
* Tests HarvestDetailLog code using JUnit.
|
44 |
2134
|
costa
|
*
|
45 |
|
|
* @author costa
|
46 |
|
|
*/
|
47 |
4385
|
daigle
|
public class HarvestDetailLogTest extends MCTestCase {
|
48 |
2134
|
costa
|
|
49 |
|
|
private Harvester harvester;
|
50 |
2143
|
costa
|
private HarvestDetailLog harvestDetailLog;
|
51 |
|
|
private HarvestDocument harvestDocument;
|
52 |
|
|
private HarvestSiteSchedule harvestSiteSchedule;
|
53 |
4127
|
daigle
|
/* Initialize Properties*/
|
54 |
3566
|
tao
|
static
|
55 |
|
|
{
|
56 |
|
|
try
|
57 |
|
|
{
|
58 |
4816
|
daigle
|
PropertyService.getInstance();
|
59 |
3566
|
tao
|
}
|
60 |
|
|
catch(Exception e)
|
61 |
|
|
{
|
62 |
|
|
System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
2134
|
costa
|
|
66 |
2255
|
costa
|
/**
|
67 |
|
|
* Constructor for this test.
|
68 |
|
|
*
|
69 |
|
|
* @param name name of the test case
|
70 |
|
|
*/
|
71 |
2134
|
costa
|
public HarvestDetailLogTest(String name) {
|
72 |
|
|
super(name);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
2255
|
costa
|
|
76 |
|
|
/**
|
77 |
|
|
* Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
|
78 |
|
|
* and HarvestDetailLog objects.
|
79 |
|
|
*/
|
80 |
2134
|
costa
|
protected void setUp() {
|
81 |
2143
|
costa
|
Connection conn;
|
82 |
4999
|
costa
|
boolean commandLineMode = true;
|
83 |
2143
|
costa
|
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.institution.edu/~jdoe/public_html/document1.xml";
|
92 |
|
|
String errorMessage = "JUnit testing";
|
93 |
|
|
int harvestLogID;
|
94 |
|
|
int identifier = 1;
|
95 |
|
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
96 |
|
|
String ldapPwd = "secretpassword";
|
97 |
|
|
int revision = 1;
|
98 |
|
|
String scope = "docname";
|
99 |
|
|
int siteScheduleID = 1;
|
100 |
2158
|
costa
|
boolean test = true;
|
101 |
2143
|
costa
|
String unit = "months";
|
102 |
|
|
int updateFrequency = 1;
|
103 |
|
|
|
104 |
2134
|
costa
|
harvester = new Harvester();
|
105 |
8099
|
leinfelder
|
Harvester.loadProperties(metacatContextDir);
|
106 |
2143
|
costa
|
conn = harvester.getConnection(); // initializes the database connection
|
107 |
|
|
harvester.initLogIDs();
|
108 |
|
|
harvestLogID = harvester.getHarvestLogID();
|
109 |
|
|
detailLogID = harvester.getDetailLogID();
|
110 |
|
|
|
111 |
|
|
harvestSiteSchedule = new HarvestSiteSchedule(harvester,
|
112 |
|
|
siteScheduleID,
|
113 |
|
|
documentListURL,
|
114 |
|
|
ldapDN,
|
115 |
|
|
ldapPwd,
|
116 |
|
|
dateNextHarvest,
|
117 |
|
|
dateLastHarvest,
|
118 |
|
|
updateFrequency,
|
119 |
|
|
unit,
|
120 |
|
|
contactEmail
|
121 |
|
|
);
|
122 |
|
|
|
123 |
|
|
harvestDocument = new HarvestDocument(harvester,
|
124 |
|
|
harvestSiteSchedule,
|
125 |
|
|
scope,
|
126 |
|
|
identifier,
|
127 |
|
|
revision,
|
128 |
|
|
documentType,
|
129 |
|
|
documentURL
|
130 |
|
|
);
|
131 |
|
|
|
132 |
|
|
harvestDetailLog = new HarvestDetailLog(harvester, conn, harvestLogID,
|
133 |
|
|
detailLogID, harvestDocument,
|
134 |
|
|
errorMessage);
|
135 |
2134
|
costa
|
}
|
136 |
|
|
|
137 |
2255
|
costa
|
|
138 |
|
|
/**
|
139 |
|
|
* Closes the database connection when the test completes.
|
140 |
|
|
*/
|
141 |
2134
|
costa
|
protected void tearDown() {
|
142 |
2143
|
costa
|
harvester.closeConnection();
|
143 |
2134
|
costa
|
}
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
/**
|
147 |
2143
|
costa
|
* Tests that the harvestDetailLog object was constructed.
|
148 |
2134
|
costa
|
*/
|
149 |
2143
|
costa
|
public void testHarvestDetailLogObject() {
|
150 |
|
|
assertTrue(harvestDetailLog != null);
|
151 |
2134
|
costa
|
}
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
/**
|
155 |
2143
|
costa
|
* Tests the printOutput() method.
|
156 |
|
|
*/
|
157 |
|
|
public void testPrintOutput() {
|
158 |
|
|
harvestDetailLog.printOutput(System.out);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
/**
|
163 |
2134
|
costa
|
* Returns the test suite. The test suite consists of all methods in this
|
164 |
|
|
* class whose names start with "test".
|
165 |
|
|
*
|
166 |
|
|
* @return a TestSuite object
|
167 |
|
|
*/
|
168 |
|
|
public static Test suite() {
|
169 |
|
|
return new TestSuite(HarvestDetailLogTest.class);
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
/**
|
174 |
|
|
* The main program. Runs the test suite.
|
175 |
|
|
*
|
176 |
|
|
* @param args command line argument array.
|
177 |
|
|
*/
|
178 |
|
|
public static void main(String args[]) {
|
179 |
|
|
junit.textui.TestRunner.run(suite());
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
}
|