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 HarvestLog 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 |
2143
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
|
31 |
|
|
import java.io.File;
|
32 |
|
|
import java.sql.Connection;
|
33 |
|
|
import java.sql.DriverManager;
|
34 |
|
|
import java.sql.SQLException;
|
35 |
|
|
import java.sql.SQLWarning;
|
36 |
|
|
import java.util.Date;
|
37 |
2134
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
|
38 |
2143
|
costa
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDetailLog;
|
39 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
|
40 |
|
|
import edu.ucsb.nceas.metacat.harvesterClient.HarvestLog;
|
41 |
2134
|
costa
|
import junit.framework.Test;
|
42 |
|
|
import junit.framework.TestCase;
|
43 |
|
|
import junit.framework.TestSuite;
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Test HarvestLog code using JUnit. Not yet implemented. The test
|
47 |
|
|
* contained herein is just a placeholder for the actual tests to be
|
48 |
|
|
* added.
|
49 |
|
|
*
|
50 |
|
|
* @author costa
|
51 |
|
|
*/
|
52 |
|
|
public class HarvestLogTest extends TestCase {
|
53 |
|
|
|
54 |
2143
|
costa
|
private Connection conn;
|
55 |
2134
|
costa
|
private Harvester harvester;
|
56 |
2143
|
costa
|
private HarvestLog harvestLogShallow;
|
57 |
|
|
private HarvestLog harvestLogDeep;
|
58 |
|
|
private HarvestDocument harvestDocument;
|
59 |
|
|
private HarvestSiteSchedule harvestSiteSchedule;
|
60 |
2134
|
costa
|
|
61 |
|
|
|
62 |
|
|
public HarvestLogTest(String name) {
|
63 |
|
|
super(name);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
protected void setUp() {
|
68 |
2143
|
costa
|
String contactEmail = "jdoe@institution.edu";
|
69 |
|
|
String dateLastHarvest = "2004-04-01 00:00:00.0";
|
70 |
|
|
String dateNextHarvest = "2004-05-01 00:00:00.0";
|
71 |
|
|
int detailLogID;
|
72 |
|
|
String documentListURL =
|
73 |
|
|
"http://www.institution.edu/~jdoe/public_html/harvestList.xml";
|
74 |
|
|
String documentType = "eml://ecoinformatics.org/eml-2.0.0";
|
75 |
|
|
String documentURL =
|
76 |
|
|
"http://www.institution.edu/~jdoe/public_html/document1.xml";
|
77 |
|
|
String errorMessage = "JUnit Testing";
|
78 |
|
|
HarvestDocument harvestDocument = null;
|
79 |
|
|
int harvestLogID;
|
80 |
|
|
String harvestOperationCode = "HarvesterStartup";
|
81 |
|
|
Date harvestStartTime = new Date();
|
82 |
|
|
int identifier = 1;
|
83 |
|
|
String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
|
84 |
|
|
String ldapPwd = "secretpassword";
|
85 |
|
|
String message = "JUnit Testing";
|
86 |
|
|
int revision = 1;
|
87 |
|
|
String scope = "docname";
|
88 |
|
|
int siteScheduleID = 1;
|
89 |
|
|
int status = 0;
|
90 |
2158
|
costa
|
boolean test = true;
|
91 |
2143
|
costa
|
String unit = "months";
|
92 |
|
|
int updateFrequency = 1;
|
93 |
|
|
|
94 |
2134
|
costa
|
harvester = new Harvester();
|
95 |
2158
|
costa
|
Harvester.loadOptions(test);
|
96 |
2143
|
costa
|
conn = harvester.getConnection(); // initializes the database connection
|
97 |
|
|
harvester.initLogIDs();
|
98 |
|
|
harvestLogID = harvester.getHarvestLogID();
|
99 |
|
|
harvestLogShallow = new HarvestLog(harvester, conn, harvestLogID,
|
100 |
|
|
harvestStartTime, status,
|
101 |
|
|
message, harvestOperationCode,
|
102 |
|
|
siteScheduleID);
|
103 |
|
|
|
104 |
|
|
harvestLogID = harvester.getHarvestLogID();
|
105 |
|
|
detailLogID = harvester.getDetailLogID();
|
106 |
|
|
harvestSiteSchedule = new HarvestSiteSchedule(harvester,
|
107 |
|
|
siteScheduleID,
|
108 |
|
|
documentListURL,
|
109 |
|
|
ldapDN,
|
110 |
|
|
ldapPwd,
|
111 |
|
|
dateNextHarvest,
|
112 |
|
|
dateLastHarvest,
|
113 |
|
|
updateFrequency,
|
114 |
|
|
unit,
|
115 |
|
|
contactEmail
|
116 |
|
|
);
|
117 |
|
|
|
118 |
|
|
harvestDocument = new HarvestDocument(harvester,
|
119 |
|
|
harvestSiteSchedule,
|
120 |
|
|
scope,
|
121 |
|
|
identifier,
|
122 |
|
|
revision,
|
123 |
|
|
documentType,
|
124 |
|
|
documentURL
|
125 |
|
|
);
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
harvestLogDeep = new HarvestLog(harvester, conn, harvestLogID, detailLogID,
|
129 |
|
|
harvestStartTime, status, message,
|
130 |
|
|
harvestOperationCode, siteScheduleID,
|
131 |
|
|
harvestDocument, errorMessage);
|
132 |
2134
|
costa
|
}
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
protected void tearDown() {
|
136 |
2143
|
costa
|
harvester.closeConnection();
|
137 |
2134
|
costa
|
}
|
138 |
2143
|
costa
|
|
139 |
|
|
|
140 |
|
|
public void testGetCodeLevelValue() {
|
141 |
|
|
int lowLevel = harvestLogShallow.getCodeLevelValue("error");
|
142 |
|
|
int highLevel = harvestLogShallow.getCodeLevelValue("debug");
|
143 |
|
|
|
144 |
|
|
assertTrue(lowLevel < highLevel);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
public void testGetExplanation() {
|
149 |
|
|
String harvestOperationCode = "HarvesterStartup";
|
150 |
|
|
String explanation;
|
151 |
2134
|
costa
|
|
152 |
2143
|
costa
|
explanation = harvestLogShallow.getExplanation(harvestOperationCode);
|
153 |
|
|
assertTrue(explanation.equals("Harvester start up"));
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
public void testGetHarvestOperationCodeLevel() {
|
158 |
|
|
String harvestOperationCode = "HarvesterStartup";
|
159 |
|
|
String harvestOperationCodeLevel;
|
160 |
2134
|
costa
|
|
161 |
2143
|
costa
|
harvestOperationCodeLevel =
|
162 |
|
|
harvestLogShallow.getHarvestOperationCodeLevel(harvestOperationCode);
|
163 |
|
|
assertTrue(harvestOperationCodeLevel.equalsIgnoreCase("Info"));
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
|
167 |
2134
|
costa
|
/**
|
168 |
2143
|
costa
|
* Test the construction of HarvestLog object, and a HarvestLog object
|
169 |
|
|
* that contains a HarvestDetailLog object.
|
170 |
2134
|
costa
|
*/
|
171 |
2143
|
costa
|
public void testHarvestLogObject() {
|
172 |
|
|
assertTrue(harvestLogShallow != null);
|
173 |
|
|
assertTrue(harvestLogDeep != null);
|
174 |
2134
|
costa
|
}
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
/**
|
178 |
2143
|
costa
|
* Tests the printOutput() method when the code level of this operation is
|
179 |
|
|
* greater than the maximum level we wish to print. This means that the output
|
180 |
|
|
* should not be printed.
|
181 |
|
|
*/
|
182 |
|
|
public void testPrintOutputExceedsMax() {
|
183 |
|
|
System.out.println("No output should be printed:");
|
184 |
|
|
harvestLogDeep.printOutput(System.out, "Error");
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
/**
|
189 |
|
|
* Tests the printOutput() method when the code level of this operation is
|
190 |
|
|
* less than the maximum level we wish to print. This means that the output
|
191 |
|
|
* should be printed.
|
192 |
|
|
*/
|
193 |
|
|
public void testPrintOutputWithinMax() {
|
194 |
|
|
System.out.println("The log output should be printed:");
|
195 |
|
|
harvestLogDeep.printOutput(System.out, "Debug");
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
/**
|
200 |
2134
|
costa
|
* Returns the test suite. The test suite consists of all methods in this
|
201 |
|
|
* class whose names start with "test".
|
202 |
|
|
*
|
203 |
|
|
* @return a TestSuite object
|
204 |
|
|
*/
|
205 |
|
|
public static Test suite() {
|
206 |
|
|
return new TestSuite(HarvestLogTest.class);
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
/**
|
211 |
|
|
* The main program. Runs the test suite.
|
212 |
|
|
*
|
213 |
|
|
* @param args command line argument array.
|
214 |
|
|
*/
|
215 |
|
|
public static void main(String args[]) {
|
216 |
|
|
junit.textui.TestRunner.run(suite());
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
}
|