Project

General

Profile

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 HarvestSiteSchedule 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 3566 tao
import edu.ucsb.nceas.metacat.MetaCatUtil;
31 2134 costa
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32 2143 costa
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
33 3566 tao
import edu.ucsb.nceas.utilities.Options;
34
35 2143 costa
import java.io.File;
36
import java.util.Date;
37
import javax.xml.parsers.ParserConfigurationException;
38 2134 costa
import junit.framework.Test;
39
import junit.framework.TestCase;
40
import junit.framework.TestSuite;
41
42
/**
43 2255 costa
 * Tests HarvestSiteSchedule code using JUnit.
44 2134 costa
 *
45
 * @author  costa
46
 */
47
public class HarvestSiteScheduleTest extends TestCase {
48
49
  private Harvester harvester;
50 2143 costa
  private HarvestSiteSchedule harvestSiteScheduleFuture; // future date next har
51
  private HarvestSiteSchedule harvestSiteSchedulePast; // past date next harvest
52 3566 tao
  /* Initialize Options*/
53
  static
54
  {
55
	  try
56
	  {
57
		  Options.initialize(new File("build/tests/metacat.properties"));
58
		  MetaCatUtil.pathsForIndexing
59
		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
60
	  }
61
	  catch(Exception e)
62
	  {
63
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
64
	  }
65
  }
66 2134 costa
67 2255 costa
  /**
68
   * Constructor for this test.
69
   *
70
   * @param name     name of the test case
71
   */
72 2134 costa
  public HarvestSiteScheduleTest(String name) {
73
    super(name);
74
  }
75
76 2255 costa
77
  /**
78
   * Sets up the HarvestSiteScheduleTest by creating a pair of
79
   * HarvestSiteSchedule objects. The harvestSiteScheduleFuture object
80
   * is used for a site with a future date of next harvest (not due for
81
   * harvest now), while the harvestSiteSchedulePast object is used for a site
82
   * with a past date of next harvest (is due for harvest now).
83
   */
84 2134 costa
  protected void setUp() {
85 2143 costa
    String contactEmail = "jdoe@institution.edu";
86
    String dateLastHarvest = "2004-04-01 00:00:00.0";
87
    String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
88
    String dateNextHarvestPast = "2000-01-01 00:00:00.0";
89 2254 costa
    String documentListURL =
90 2382 costa
                "http://www.lternet.edu/~dcosta/testHarvest/lnoHarvestList.xml";
91 2143 costa
    String errorMessage = "JUnit Testing";
92
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
93
    String ldapPwd = "secretpassword";
94
    int siteScheduleID = 1;
95 2158 costa
    boolean test = true;
96 2143 costa
    String unit = "months";
97
    int updateFrequency = 1;
98
99 2134 costa
    harvester = new Harvester();
100 2158 costa
    Harvester.loadOptions(test);
101 2143 costa
    harvester.getConnection();  // initializes the database connection
102
    harvester.initLogIDs();
103
    harvester.setHarvestStartTime(new Date());
104
105
    harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
106
                                                  siteScheduleID,
107
                                                  documentListURL,
108
                                                  ldapDN,
109
                                                  ldapPwd,
110
                                                  dateNextHarvestFuture,
111
                                                  dateLastHarvest,
112
                                                  updateFrequency,
113
                                                  unit,
114
                                                  contactEmail
115
                                                 );
116
117
    harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
118
                                                  siteScheduleID,
119
                                                  documentListURL,
120
                                                  ldapDN,
121
                                                  ldapPwd,
122
                                                  dateNextHarvestPast,
123
                                                  dateLastHarvest,
124
                                                  updateFrequency,
125
                                                  unit,
126
                                                  contactEmail
127
                                                 );
128
129 2134 costa
  }
130
131 2255 costa
132
  /**
133
   * Closes the database connection after the test completes.
134
   */
135 2134 costa
  protected void tearDown() {
136 2143 costa
    harvester.closeConnection();
137 2134 costa
  }
138 2143 costa
139 2255 costa
140
  /**
141
   * Tests the dueForHarvest() method in the case where a site is not due for
142
   * a harvest.
143
   */
144 2143 costa
  public void testDueForHarvestFalse() {
145
    boolean dueForHarvest;
146
147
    dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
148
    assertTrue(dueForHarvest == false);
149
  }
150
151 2255 costa
152
  /**
153
   * Tests the dueForHarvest() method in the case where a site is due for
154
   * a harvest.
155
   */
156
  public void testDueForHarvestTrue() {
157
    boolean dueForHarvest;
158
159
    dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
160
    assertTrue(dueForHarvest == true);
161
  }
162
163
164
  /**
165
   * Tests the parseHarvestList() method.
166
   */
167 2143 costa
  public void testParseHarvestList() {
168
    boolean success = false;
169
    String schemaLocation =
170
         "eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
171
172
    harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
173
174
    try {
175
      success = harvestSiteScheduleFuture.parseHarvestList();
176
      assertTrue(success == true);
177
    }
178
    catch (ParserConfigurationException e) {
179
      fail("ParserConfigurationException: " + e.getMessage());
180
    }
181
  }
182 2134 costa
183
184
  /**
185 2143 costa
   * Tests the printOutput() method.
186 2134 costa
   */
187 2143 costa
  public void testPrintOutput() {
188
    harvestSiteScheduleFuture.printOutput(System.out);
189 2134 costa
  }
190
191 2143 costa
192 2134 costa
  /**
193 2255 costa
   * Tests that the harvesterDocument object was created successfully.
194 2143 costa
   */
195
  public void testHarvestSiteScheduleObject() {
196
    assertTrue(harvestSiteScheduleFuture != null);
197
    assertTrue(harvestSiteSchedulePast != null);
198
  }
199
200
201
  /**
202 2134 costa
   * Returns the test suite. The test suite consists of all methods in this
203
   * class whose names start with "test".
204
   *
205
   * @return  a TestSuite object
206
   */
207
  public static Test suite() {
208
    return new TestSuite(HarvestSiteScheduleTest.class);
209
  }
210
211
212
  /**
213
   * The main program. Runs the test suite.
214
   *
215
   * @param args   command line argument array.
216
   */
217
  public static void main(String args[]) {
218
    junit.textui.TestRunner.run(suite());
219
  }
220
221
}