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: 2009-02-23 11:29:07 -0800 (Mon, 23 Feb 2009) $'
11
 * '$Revision: 4816 $'
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.MCTestCase;
31
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
33
import edu.ucsb.nceas.metacat.service.PropertyService;
34
import edu.ucsb.nceas.metacat.util.MetacatUtil;
35

    
36
import java.util.Date;
37
import javax.xml.parsers.ParserConfigurationException;
38
import junit.framework.Test;
39
import junit.framework.TestSuite;
40

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

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

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

    
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
  protected void setUp() {
82
    String contactEmail = "jdoe@institution.edu";
83
    String dateLastHarvest = "2004-04-01 00:00:00.0";
84
    String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
85
    String dateNextHarvestPast = "2000-01-01 00:00:00.0";
86
    String documentListURL = 
87
                "http://www.lternet.edu/~dcosta/testHarvest/lnoHarvestList.xml";
88
    String errorMessage = "JUnit Testing";
89
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
90
    String ldapPwd = "secretpassword";
91
    int siteScheduleID = 1;
92
    boolean test = true;
93
    String unit = "months";
94
    int updateFrequency = 1;
95

    
96
    harvester = new Harvester();
97
    Harvester.loadProperties(test);
98
    harvester.getConnection();  // initializes the database connection
99
    harvester.initLogIDs();
100
    harvester.setHarvestStartTime(new Date());
101

    
102
    harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
103
                                                  siteScheduleID,
104
                                                  documentListURL,
105
                                                  ldapDN,
106
                                                  ldapPwd,
107
                                                  dateNextHarvestFuture,
108
                                                  dateLastHarvest,
109
                                                  updateFrequency,
110
                                                  unit,
111
                                                  contactEmail
112
                                                 );
113

    
114
    harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
115
                                                  siteScheduleID,
116
                                                  documentListURL,
117
                                                  ldapDN,
118
                                                  ldapPwd,
119
                                                  dateNextHarvestPast,
120
                                                  dateLastHarvest,
121
                                                  updateFrequency,
122
                                                  unit,
123
                                                  contactEmail
124
                                                 );
125

    
126
  }
127
  
128

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

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

    
149
  /**
150
   * Tests the dueForHarvest() method in the case where a site is due for
151
   * a harvest.
152
   */
153
  public void testDueForHarvestTrue() {
154
    boolean dueForHarvest;
155
    
156
    dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
157
    assertTrue(dueForHarvest == true);
158
  }
159

    
160

    
161
  /**
162
   * Tests the parseHarvestList() method.
163
   */
164
  public void testParseHarvestList() {
165
    boolean success = false;
166
    String schemaLocation =
167
         "eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
168
         
169
    harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
170
    
171
    try {
172
      success = harvestSiteScheduleFuture.parseHarvestList();
173
      assertTrue(success == true);
174
    }
175
    catch (ParserConfigurationException e) {
176
      fail("ParserConfigurationException: " + e.getMessage());
177
    }    
178
  }
179

    
180

    
181
  /**
182
   * Tests the printOutput() method.
183
   */
184
  public void testPrintOutput() {
185
    harvestSiteScheduleFuture.printOutput(System.out);
186
  }
187
  
188

    
189
  /**
190
   * Tests that the harvesterDocument object was created successfully.
191
   */
192
  public void testHarvestSiteScheduleObject() {
193
    assertTrue(harvestSiteScheduleFuture != null);
194
    assertTrue(harvestSiteSchedulePast != null);
195
  }
196
  
197
  
198
  /**
199
   * Returns the test suite. The test suite consists of all methods in this
200
   * class whose names start with "test".
201
   * 
202
   * @return  a TestSuite object
203
   */
204
  public static Test suite() {
205
    return new TestSuite(HarvestSiteScheduleTest.class);
206
  }
207
  
208

    
209
  /**
210
   * The main program. Runs the test suite.
211
   * 
212
   * @param args   command line argument array.
213
   */
214
  public static void main(String args[]) {
215
    junit.textui.TestRunner.run(suite());
216
  }
217

    
218
}
(4-4/5)