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: leinfelder $'
10
 *     '$Date: 2011-07-20 11:37:23 -0700 (Wed, 20 Jul 2011) $'
11
 * '$Revision: 6356 $'
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.properties.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
    boolean commandLineMode = true;
83
    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
    String documentListURL = 
88
                "https://code.ecoinformatics.org/code/metacat/branches/METACAT_1_9_4_BRANCH/test/harvester/sampleHarvestList.xml";
89
    String errorMessage = "JUnit Testing";
90
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
91
    String ldapPwd = "secretpassword";
92
    int siteScheduleID = 1;
93
    boolean test = true;
94
    String unit = "months";
95
    int updateFrequency = 1;
96

    
97
    harvester = new Harvester();
98
    Harvester.loadProperties(commandLineMode, test);
99
    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
  }
128
  
129

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

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

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

    
181

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

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