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: daigle $'
10
 *     '$Date: 2008-08-05 17:50:14 -0700 (Tue, 05 Aug 2008) $'
11
 * '$Revision: 4213 $'
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 edu.ucsb.nceas.metacat.service.PropertyService;
33
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
34

    
35
import java.io.File;
36
import java.util.Date;
37
import javax.xml.parsers.ParserConfigurationException;
38
import junit.framework.Test;
39
import junit.framework.TestCase;
40
import junit.framework.TestSuite;
41

    
42
/**
43
 * Tests HarvestSiteSchedule code using JUnit.
44
 *
45
 * @author  costa
46
 */
47
public class HarvestSiteScheduleTest extends TestCase {
48

    
49
  private Harvester harvester;
50
  private HarvestSiteSchedule harvestSiteScheduleFuture; // future date next har
51
  private HarvestSiteSchedule harvestSiteSchedulePast; // past date next harvest
52
  /* Initialize Properties*/
53
  static
54
  {
55
	  try
56
	  {
57
		  PropertyService.getInstance("build/tests");
58
		  MetaCatUtil.pathsForIndexing 
59
		         = MetaCatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
60
	  }
61
	  catch(Exception e)
62
	  {
63
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
64
	  }
65
  }
66

    
67
  /**
68
   * Constructor for this test.
69
   * 
70
   * @param name     name of the test case
71
   */
72
  public HarvestSiteScheduleTest(String name) {
73
    super(name);
74
  }
75
  
76

    
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
  protected void setUp() {
85
    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
    String documentListURL = 
90
                "http://www.lternet.edu/~dcosta/testHarvest/lnoHarvestList.xml";
91
    String errorMessage = "JUnit Testing";
92
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
93
    String ldapPwd = "secretpassword";
94
    int siteScheduleID = 1;
95
    boolean test = true;
96
    String unit = "months";
97
    int updateFrequency = 1;
98

    
99
    harvester = new Harvester();
100
    Harvester.loadProperties(test);
101
    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
  }
130
  
131

    
132
  /**
133
   * Closes the database connection after the test completes.
134
   */
135
  protected void tearDown() {
136
    harvester.closeConnection();
137
  }
138
  
139

    
140
  /**
141
   * Tests the dueForHarvest() method in the case where a site is not due for
142
   * a harvest.
143
   */
144
  public void testDueForHarvestFalse() {
145
    boolean dueForHarvest;
146
    
147
    dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
148
    assertTrue(dueForHarvest == false);
149
  }
150
  
151

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

    
183

    
184
  /**
185
   * Tests the printOutput() method.
186
   */
187
  public void testPrintOutput() {
188
    harvestSiteScheduleFuture.printOutput(System.out);
189
  }
190
  
191

    
192
  /**
193
   * Tests that the harvesterDocument object was created successfully.
194
   */
195
  public void testHarvestSiteScheduleObject() {
196
    assertTrue(harvestSiteScheduleFuture != null);
197
    assertTrue(harvestSiteSchedulePast != null);
198
  }
199
  
200
  
201
  /**
202
   * 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
}
(4-4/5)