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 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
31 |
2143
|
costa
|
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 java.io.File;
|
35 |
|
|
import java.sql.Connection;
|
36 |
2134
|
costa
|
import junit.framework.Test;
|
37 |
|
|
import junit.framework.TestCase;
|
38 |
|
|
import junit.framework.TestSuite;
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
2255
|
costa
|
* Tests HarvestDetailLog code using JUnit.
|
42 |
2134
|
costa
|
*
|
43 |
|
|
* @author costa
|
44 |
|
|
*/
|
45 |
|
|
public class HarvestDetailLogTest extends TestCase {
|
46 |
|
|
|
47 |
|
|
private Harvester harvester;
|
48 |
2143
|
costa
|
private HarvestDetailLog harvestDetailLog;
|
49 |
|
|
private HarvestDocument harvestDocument;
|
50 |
|
|
private HarvestSiteSchedule harvestSiteSchedule;
|
51 |
2134
|
costa
|
|
52 |
|
|
|
53 |
2255
|
costa
|
/**
|
54 |
|
|
* Constructor for this test.
|
55 |
|
|
*
|
56 |
|
|
* @param name name of the test case
|
57 |
|
|
*/
|
58 |
2134
|
costa
|
public HarvestDetailLogTest(String name) {
|
59 |
|
|
super(name);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
2255
|
costa
|
|
63 |
|
|
/**
|
64 |
|
|
* Sets up the test by instantiating HarvestSiteSchedule, HarvestDocument,
|
65 |
|
|
* and HarvestDetailLog objects.
|
66 |
|
|
*/
|
67 |
2134
|
costa
|
protected void setUp() {
|
68 |
2143
|
costa
|
Connection conn;
|
69 |
|
|
String contactEmail = "jdoe@institution.edu";
|
70 |
|
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
71 |
|
|
String dateNextHarvest = "2004-05-01 00:00:00.0";
|
72 |
|
|
int detailLogID;
|
73 |
|
|
String documentListURL =
|
74 |
|
|
"http://www.institution.edu/~jdoe/public_html/harvestList.xml";
|
75 |
|
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
76 |
|
|
String documentURL =
|
77 |
|
|
"http://www.institution.edu/~jdoe/public_html/document1.xml";
|
78 |
|
|
String errorMessage = "JUnit testing";
|
79 |
|
|
int harvestLogID;
|
80 |
|
|
int identifier = 1;
|
81 |
|
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
82 |
|
|
String ldapPwd = "secretpassword";
|
83 |
|
|
int revision = 1;
|
84 |
|
|
String scope = "docname";
|
85 |
|
|
int siteScheduleID = 1;
|
86 |
2158
|
costa
|
boolean test = true;
|
87 |
2143
|
costa
|
String unit = "months";
|
88 |
|
|
int updateFrequency = 1;
|
89 |
|
|
|
90 |
2134
|
costa
|
harvester = new Harvester();
|
91 |
2158
|
costa
|
Harvester.loadOptions(test);
|
92 |
2143
|
costa
|
conn = harvester.getConnection(); // initializes the database connection
|
93 |
|
|
harvester.initLogIDs();
|
94 |
|
|
harvestLogID = harvester.getHarvestLogID();
|
95 |
|
|
detailLogID = harvester.getDetailLogID();
|
96 |
|
|
|
97 |
|
|
harvestSiteSchedule = new HarvestSiteSchedule(harvester,
|
98 |
|
|
siteScheduleID,
|
99 |
|
|
documentListURL,
|
100 |
|
|
ldapDN,
|
101 |
|
|
ldapPwd,
|
102 |
|
|
dateNextHarvest,
|
103 |
|
|
dateLastHarvest,
|
104 |
|
|
updateFrequency,
|
105 |
|
|
unit,
|
106 |
|
|
contactEmail
|
107 |
|
|
);
|
108 |
|
|
|
109 |
|
|
harvestDocument = new HarvestDocument(harvester,
|
110 |
|
|
harvestSiteSchedule,
|
111 |
|
|
scope,
|
112 |
|
|
identifier,
|
113 |
|
|
revision,
|
114 |
|
|
documentType,
|
115 |
|
|
documentURL
|
116 |
|
|
);
|
117 |
|
|
|
118 |
|
|
harvestDetailLog = new HarvestDetailLog(harvester, conn, harvestLogID,
|
119 |
|
|
detailLogID, harvestDocument,
|
120 |
|
|
errorMessage);
|
121 |
2134
|
costa
|
}
|
122 |
|
|
|
123 |
2255
|
costa
|
|
124 |
|
|
/**
|
125 |
|
|
* Closes the database connection when the test completes.
|
126 |
|
|
*/
|
127 |
2134
|
costa
|
protected void tearDown() {
|
128 |
2143
|
costa
|
harvester.closeConnection();
|
129 |
2134
|
costa
|
}
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
/**
|
133 |
2143
|
costa
|
* Tests that the harvestDetailLog object was constructed.
|
134 |
2134
|
costa
|
*/
|
135 |
2143
|
costa
|
public void testHarvestDetailLogObject() {
|
136 |
|
|
assertTrue(harvestDetailLog != null);
|
137 |
2134
|
costa
|
}
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
/**
|
141 |
2143
|
costa
|
* Tests the printOutput() method.
|
142 |
|
|
*/
|
143 |
|
|
public void testPrintOutput() {
|
144 |
|
|
harvestDetailLog.printOutput(System.out);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
/**
|
149 |
2134
|
costa
|
* Returns the test suite. The test suite consists of all methods in this
|
150 |
|
|
* class whose names start with "test".
|
151 |
|
|
*
|
152 |
|
|
* @return a TestSuite object
|
153 |
|
|
*/
|
154 |
|
|
public static Test suite() {
|
155 |
|
|
return new TestSuite(HarvestDetailLogTest.class);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
/**
|
160 |
|
|
* The main program. Runs the test suite.
|
161 |
|
|
*
|
162 |
|
|
* @param args command line argument array.
|
163 |
|
|
*/
|
164 |
|
|
public static void main(String args[]) {
|
165 |
|
|
junit.textui.TestRunner.run(suite());
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
}
|