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