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 HarvestDocument 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.HarvestDocument;
31
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
32
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
33
import java.io.File;
34
import java.io.StringReader;
35
import java.util.Date;
36
import junit.framework.Test;
37
import junit.framework.TestCase;
38
import junit.framework.TestSuite;
39

    
40
/**
41
 * Tests HarvestDocument code using JUnit.
42
 *
43
 * @author  costa
44
 */
45
public class HarvestDocumentTest extends TestCase {
46

    
47
  private Harvester harvester;
48
  private HarvestDocument harvestDocument;
49
  private HarvestSiteSchedule harvestSiteSchedule;
50
  
51

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

    
62
  /**
63
   * Sets up the test by instantiating HarvestSiteSchedule and HarvestDocument
64
   * objects.
65
   */
66
  protected void setUp() {
67
    String contactEmail = "jdoe@institution.edu";
68
    String dateLastHarvest = "2004-04-01 00:00:00.0";
69
    String dateNextHarvest = "2004-05-01 00:00:00.0";
70
    int detailLogID;
71
    String documentListURL = 
72
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
73
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
74
    String documentURL = "http://www.lternet.edu/~dcosta/document1.xml";
75
    String errorMessage = "JUnit Testing";
76
    int harvestLogID;
77
    String harvestOperationCode = "HarvesterStartup";
78
    Date harvestStartTime = new Date();
79
    int identifier = 1;
80
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
81
    String ldapPwd = "secretpassword";
82
    String message = "JUnit Testing";
83
    int revision = 1;
84
    String scope = "docname";
85
    int siteScheduleID = 1;
86
    int status = 0;
87
    boolean test = true;
88
    String unit = "months";
89
    int updateFrequency = 1;
90

    
91
    harvester = new Harvester();
92
    Harvester.loadOptions(test);
93
    harvester.getConnection();  // initializes the database connection
94
    harvester.initLogIDs();
95
    harvester.setHarvestStartTime(new Date());
96

    
97
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
98
                                                  siteScheduleID,
99
                                                  documentListURL,
100
                                                  ldapDN,
101
                                                  ldapPwd,
102
                                                  dateNextHarvest,
103
                                                  dateLastHarvest,
104
                                                  updateFrequency,
105
                                                  unit,
106
                                                  contactEmail
107
                                                 );
108

    
109
    harvestDocument = new HarvestDocument(harvester,
110
                                          harvestSiteSchedule,
111
                                          scope,
112
                                          identifier,
113
                                          revision,
114
                                          documentType,
115
                                          documentURL
116
                                        );
117
  }
118
  
119

    
120
  /**
121
   * Closes the database connection after the test completes.
122
   */
123
  protected void tearDown() {
124
    harvester.closeConnection();
125
  }
126
  
127

    
128
  /**
129
   * Tests the getSiteDocument() method. The test succeeds if a non-null
130
   * StringReader is returned.
131
   */
132
  public void testGetSiteDocument() {
133
    StringReader stringReader = null;
134
    stringReader = harvestDocument.getSiteDocument();
135
    assertTrue(stringReader != null);
136
  }
137
  
138
  
139
  /**
140
   * Tests that the harvesterDocument object was created successfully.
141
   */
142
  public void testHarvestDocumentObject() {
143
    assertTrue(harvestDocument != null);
144
  }
145
  
146

    
147
  /**
148
   * Tests the metacatHighestRevision() method. This test ensures that -1
149
   * is returned for a non-existent document.
150
   */
151
  public void testMetacatHighestRevision() {
152
    int highestRevision;
153
    
154
    highestRevision = harvestDocument.metacatHighestRevision();
155
    assertTrue(highestRevision == -1);
156
  }
157

    
158

    
159
  /**
160
   * Tests the printOutput() method.
161
   */
162
  public void testPrintOutput() {
163
    harvestDocument.printOutput(System.out);
164
  }
165
  
166
  
167
  /**
168
   * Returns the test suite. The test suite consists of all methods in this
169
   * class whose names start with "test".
170
   * 
171
   * @return  a TestSuite object
172
   */
173
  public static Test suite() {
174
    return new TestSuite(HarvestDocumentTest.class);
175
  }
176
  
177

    
178
  /**
179
   * The main program. Runs the test suite.
180
   * 
181
   * @param args   command line argument array.
182
   */
183
  public static void main(String args[]) {
184
    junit.textui.TestRunner.run(suite());
185
  }
186

    
187
}
(2-2/5)