Project

General

Profile

1
/**
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: costa $'
10
 *     '$Date: 2004-08-26 14:56:11 -0700 (Thu, 26 Aug 2004) $'
11
 * '$Revision: 2255 $'
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
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
32
import java.io.File;
33
import java.util.Date;
34
import javax.xml.parsers.ParserConfigurationException;
35
import junit.framework.Test;
36
import junit.framework.TestCase;
37
import junit.framework.TestSuite;
38

    
39
/**
40
 * Tests HarvestSiteSchedule code using JUnit.
41
 *
42
 * @author  costa
43
 */
44
public class HarvestSiteScheduleTest extends TestCase {
45

    
46
  private Harvester harvester;
47
  private HarvestSiteSchedule harvestSiteScheduleFuture; // future date next har
48
  private HarvestSiteSchedule harvestSiteSchedulePast; // past date next harvest
49
  
50

    
51
  /**
52
   * Constructor for this test.
53
   * 
54
   * @param name     name of the test case
55
   */
56
  public HarvestSiteScheduleTest(String name) {
57
    super(name);
58
  }
59
  
60

    
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
  protected void setUp() {
69
    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
    String documentListURL = 
74
                            "http://www.lternet.edu/~dcosta/lnoHarvestList.xml";
75
    String errorMessage = "JUnit Testing";
76
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
77
    String ldapPwd = "secretpassword";
78
    int siteScheduleID = 1;
79
    boolean test = true;
80
    String unit = "months";
81
    int updateFrequency = 1;
82

    
83
    harvester = new Harvester();
84
    Harvester.loadOptions(test);
85
    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
  }
114
  
115

    
116
  /**
117
   * Closes the database connection after the test completes.
118
   */
119
  protected void tearDown() {
120
    harvester.closeConnection();
121
  }
122
  
123

    
124
  /**
125
   * Tests the dueForHarvest() method in the case where a site is not due for
126
   * a harvest.
127
   */
128
  public void testDueForHarvestFalse() {
129
    boolean dueForHarvest;
130
    
131
    dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
132
    assertTrue(dueForHarvest == false);
133
  }
134
  
135

    
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
  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

    
167

    
168
  /**
169
   * Tests the printOutput() method.
170
   */
171
  public void testPrintOutput() {
172
    harvestSiteScheduleFuture.printOutput(System.out);
173
  }
174
  
175

    
176
  /**
177
   * Tests that the harvesterDocument object was created successfully.
178
   */
179
  public void testHarvestSiteScheduleObject() {
180
    assertTrue(harvestSiteScheduleFuture != null);
181
    assertTrue(harvestSiteSchedulePast != null);
182
  }
183
  
184
  
185
  /**
186
   * 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
}
(4-4/5)