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