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