Project

General

Profile

1 2134 costa
/**
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$'
10
 *     '$Date$'
11
 * '$Revision$'
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 2143 costa
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
31
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
32 2134 costa
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
33 2143 costa
import java.io.File;
34
import java.io.StringReader;
35
import java.util.Date;
36 2134 costa
import junit.framework.Test;
37
import junit.framework.TestCase;
38
import junit.framework.TestSuite;
39
40
/**
41 2255 costa
 * Tests HarvestDocument code using JUnit.
42 2134 costa
 *
43
 * @author  costa
44
 */
45
public class HarvestDocumentTest extends TestCase {
46
47
  private Harvester harvester;
48 2143 costa
  private HarvestDocument harvestDocument;
49
  private HarvestSiteSchedule harvestSiteSchedule;
50 2134 costa
51
52 2255 costa
  /**
53
   * Constructor for this test.
54
   *
55
   * @param name     name of the test case
56
   */
57 2134 costa
  public HarvestDocumentTest(String name) {
58
    super(name);
59
  }
60
61 2255 costa
62
  /**
63
   * Sets up the test by instantiating HarvestSiteSchedule and HarvestDocument
64
   * objects.
65
   */
66 2134 costa
  protected void setUp() {
67 2143 costa
    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 2382 costa
    String documentURL =
75
                     "http://www.lternet.edu/~dcosta/testHarvest/document1.xml";
76 2143 costa
    String errorMessage = "JUnit Testing";
77
    int harvestLogID;
78
    String harvestOperationCode = "HarvesterStartup";
79
    Date harvestStartTime = new Date();
80
    int identifier = 1;
81
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
82
    String ldapPwd = "secretpassword";
83
    String message = "JUnit Testing";
84
    int revision = 1;
85
    String scope = "docname";
86
    int siteScheduleID = 1;
87
    int status = 0;
88 2158 costa
    boolean test = true;
89 2143 costa
    String unit = "months";
90
    int updateFrequency = 1;
91
92 2134 costa
    harvester = new Harvester();
93 2158 costa
    Harvester.loadOptions(test);
94 2143 costa
    harvester.getConnection();  // initializes the database connection
95
    harvester.initLogIDs();
96
    harvester.setHarvestStartTime(new Date());
97
98
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
99
                                                  siteScheduleID,
100
                                                  documentListURL,
101
                                                  ldapDN,
102
                                                  ldapPwd,
103
                                                  dateNextHarvest,
104
                                                  dateLastHarvest,
105
                                                  updateFrequency,
106
                                                  unit,
107
                                                  contactEmail
108
                                                 );
109
110
    harvestDocument = new HarvestDocument(harvester,
111
                                          harvestSiteSchedule,
112
                                          scope,
113
                                          identifier,
114
                                          revision,
115
                                          documentType,
116
                                          documentURL
117
                                        );
118 2134 costa
  }
119
120 2255 costa
121
  /**
122
   * Closes the database connection after the test completes.
123
   */
124 2134 costa
  protected void tearDown() {
125 2143 costa
    harvester.closeConnection();
126 2134 costa
  }
127 2143 costa
128 2255 costa
129
  /**
130
   * Tests the getSiteDocument() method. The test succeeds if a non-null
131
   * StringReader is returned.
132
   */
133 2143 costa
  public void testGetSiteDocument() {
134
    StringReader stringReader = null;
135
    stringReader = harvestDocument.getSiteDocument();
136
    assertTrue(stringReader != null);
137
  }
138
139
140
  /**
141 2255 costa
   * Tests that the harvesterDocument object was created successfully.
142 2143 costa
   */
143
  public void testHarvestDocumentObject() {
144
    assertTrue(harvestDocument != null);
145
  }
146
147 2255 costa
148
  /**
149
   * Tests the metacatHighestRevision() method. This test ensures that -1
150
   * is returned for a non-existent document.
151
   */
152 2143 costa
  public void testMetacatHighestRevision() {
153
    int highestRevision;
154
155
    highestRevision = harvestDocument.metacatHighestRevision();
156
    assertTrue(highestRevision == -1);
157
  }
158 2134 costa
159
160
  /**
161 2143 costa
   * Tests the printOutput() method.
162 2134 costa
   */
163 2143 costa
  public void testPrintOutput() {
164
    harvestDocument.printOutput(System.out);
165 2134 costa
  }
166
167
168
  /**
169
   * Returns the test suite. The test suite consists of all methods in this
170
   * class whose names start with "test".
171
   *
172
   * @return  a TestSuite object
173
   */
174
  public static Test suite() {
175
    return new TestSuite(HarvestDocumentTest.class);
176
  }
177
178
179
  /**
180
   * The main program. Runs the test suite.
181
   *
182
   * @param args   command line argument array.
183
   */
184
  public static void main(String args[]) {
185
    junit.textui.TestRunner.run(suite());
186
  }
187
188
}