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-05-04 09:29:51 -0700 (Tue, 04 May 2004) $'
11
 * '$Revision: 2158 $'
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
 * Test HarvestSiteSchedule code using JUnit. Not yet implemented. The test
41
 * contained herein is just a placeholder for the actual tests to be
42
 * added.
43
 *
44
 * @author  costa
45
 */
46
public class HarvestSiteScheduleTest extends TestCase {
47

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

    
53
  public HarvestSiteScheduleTest(String name) {
54
    super(name);
55
  }
56
  
57
  
58
  protected void setUp() {
59
    String contactEmail = "jdoe@institution.edu";
60
    String dateLastHarvest = "2004-04-01 00:00:00.0";
61
    String dateNextHarvestFuture = "2056-01-01 00:00:00.0";
62
    String dateNextHarvestPast = "2000-01-01 00:00:00.0";
63
    String documentListURL = "http://www.lternet.edu/~dcosta/harvestList.xml";
64
    String errorMessage = "JUnit Testing";
65
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
66
    String ldapPwd = "secretpassword";
67
    int siteScheduleID = 1;
68
    boolean test = true;
69
    String unit = "months";
70
    int updateFrequency = 1;
71

    
72
    harvester = new Harvester();
73
    Harvester.loadOptions(test);
74
    harvester.getConnection();  // initializes the database connection
75
    harvester.initLogIDs();
76
    harvester.setHarvestStartTime(new Date());
77

    
78
    harvestSiteScheduleFuture = new HarvestSiteSchedule(harvester,
79
                                                  siteScheduleID,
80
                                                  documentListURL,
81
                                                  ldapDN,
82
                                                  ldapPwd,
83
                                                  dateNextHarvestFuture,
84
                                                  dateLastHarvest,
85
                                                  updateFrequency,
86
                                                  unit,
87
                                                  contactEmail
88
                                                 );
89

    
90
    harvestSiteSchedulePast = new HarvestSiteSchedule(harvester,
91
                                                  siteScheduleID,
92
                                                  documentListURL,
93
                                                  ldapDN,
94
                                                  ldapPwd,
95
                                                  dateNextHarvestPast,
96
                                                  dateLastHarvest,
97
                                                  updateFrequency,
98
                                                  unit,
99
                                                  contactEmail
100
                                                 );
101

    
102
  }
103
  
104
  
105
  protected void tearDown() {
106
    harvester.closeConnection();
107
  }
108
  
109
  
110
  public void testDueForHarvestFalse() {
111
    boolean dueForHarvest;
112
    
113
    dueForHarvest = harvestSiteScheduleFuture.dueForHarvest();
114
    assertTrue(dueForHarvest == false);
115
  }
116
  
117
  
118
  public void testParseHarvestList() {
119
    boolean success = false;
120
    String schemaLocation =
121
         "eml://ecoinformatics.org/harvestList ./lib/harvester/harvestList.xsd";
122
         
123
    harvestSiteScheduleFuture.setSchemaLocation(schemaLocation);
124
    
125
    try {
126
      success = harvestSiteScheduleFuture.parseHarvestList();
127
      assertTrue(success == true);
128
    }
129
    catch (ParserConfigurationException e) {
130
      fail("ParserConfigurationException: " + e.getMessage());
131
    }    
132
  }
133

    
134

    
135
  /**
136
   * Tests the printOutput() method.
137
   */
138
  public void testPrintOutput() {
139
    harvestSiteScheduleFuture.printOutput(System.out);
140
  }
141
  
142
  
143
  public void testDueForHarvestTrue() {
144
    boolean dueForHarvest;
145
    
146
    dueForHarvest = harvestSiteSchedulePast.dueForHarvest();
147
    assertTrue(dueForHarvest == true);
148
  }
149

    
150

    
151
  /**
152
   * Test that the harvesterDocument object was created successfully.
153
   */
154
  public void testHarvestSiteScheduleObject() {
155
    assertTrue(harvestSiteScheduleFuture != null);
156
    assertTrue(harvestSiteSchedulePast != null);
157
  }
158
  
159
  
160
  /**
161
   * Returns the test suite. The test suite consists of all methods in this
162
   * class whose names start with "test".
163
   * 
164
   * @return  a TestSuite object
165
   */
166
  public static Test suite() {
167
    return new TestSuite(HarvestSiteScheduleTest.class);
168
  }
169
  
170

    
171
  /**
172
   * The main program. Runs the test suite.
173
   * 
174
   * @param args   command line argument array.
175
   */
176
  public static void main(String args[]) {
177
    junit.textui.TestRunner.run(suite());
178
  }
179

    
180
}
(4-4/5)