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 2254 costa
 * Test 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
  public HarvestSiteScheduleTest(String name) {
52
    super(name);
53
  }
54
55
56
  protected void setUp() {
57 2143 costa
    String contactEmail = "jdoe@institution.edu";
58
    String dateLastHarvest = "2004-04-01 00:00:00.0";
59
    String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
60
    String dateNextHarvestPast = "2000-01-01 00:00:00.0";
61 2254 costa
    String documentListURL =
62
                            "http://www.lternet.edu/~dcosta/lnoHarvestList.xml";
63 2143 costa
    String errorMessage = "JUnit Testing";
64
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
65
    String ldapPwd = "secretpassword";
66
    int siteScheduleID = 1;
67 2158 costa
    boolean test = true;
68 2143 costa
    String unit = "months";
69
    int updateFrequency = 1;
70
71 2134 costa
    harvester = new Harvester();
72 2158 costa
    Harvester.loadOptions(test);
73 2143 costa
    harvester.getConnection();  // initializes the database connection
74
    harvester.initLogIDs();
75
    harvester.setHarvestStartTime(new Date());
76
77
    harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
78
                                                  siteScheduleID,
79
                                                  documentListURL,
80
                                                  ldapDN,
81
                                                  ldapPwd,
82
                                                  dateNextHarvestFuture,
83
                                                  dateLastHarvest,
84
                                                  updateFrequency,
85
                                                  unit,
86
                                                  contactEmail
87
                                                 );
88
89
    harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
90
                                                  siteScheduleID,
91
                                                  documentListURL,
92
                                                  ldapDN,
93
                                                  ldapPwd,
94
                                                  dateNextHarvestPast,
95
                                                  dateLastHarvest,
96
                                                  updateFrequency,
97
                                                  unit,
98
                                                  contactEmail
99
                                                 );
100
101 2134 costa
  }
102
103
104
  protected void tearDown() {
105 2143 costa
    harvester.closeConnection();
106 2134 costa
  }
107 2143 costa
108
109
  public void testDueForHarvestFalse() {
110
    boolean dueForHarvest;
111
112
    dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
113
    assertTrue(dueForHarvest == false);
114
  }
115
116
117
  public void testParseHarvestList() {
118
    boolean success = false;
119
    String schemaLocation =
120
         "eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
121
122
    harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
123
124
    try {
125
      success = harvestSiteScheduleFuture.parseHarvestList();
126
      assertTrue(success == true);
127
    }
128
    catch (ParserConfigurationException e) {
129
      fail("ParserConfigurationException: " + e.getMessage());
130
    }
131
  }
132 2134 costa
133
134
  /**
135 2143 costa
   * Tests the printOutput() method.
136 2134 costa
   */
137 2143 costa
  public void testPrintOutput() {
138
    harvestSiteScheduleFuture.printOutput(System.out);
139 2134 costa
  }
140
141
142 2143 costa
  public void testDueForHarvestTrue() {
143
    boolean dueForHarvest;
144
145
    dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
146
    assertTrue(dueForHarvest == true);
147
  }
148
149
150 2134 costa
  /**
151 2143 costa
   * Test that the harvesterDocument object was created successfully.
152
   */
153
  public void testHarvestSiteScheduleObject() {
154
    assertTrue(harvestSiteScheduleFuture != null);
155
    assertTrue(harvestSiteSchedulePast != null);
156
  }
157
158
159
  /**
160 2134 costa
   * Returns the test suite. The test suite consists of all methods in this
161
   * class whose names start with "test".
162
   *
163
   * @return  a TestSuite object
164
   */
165
  public static Test suite() {
166
    return new TestSuite(HarvestSiteScheduleTest.class);
167
  }
168
169
170
  /**
171
   * The main program. Runs the test suite.
172
   *
173
   * @param args   command line argument array.
174
   */
175
  public static void main(String args[]) {
176
    junit.textui.TestRunner.run(suite());
177
  }
178
179
}