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: daigle $'
10
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
11
 * '$Revision: 4080 $'
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 edu.ucsb.nceas.metacat.service.PropertyService;
34
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
35
import edu.ucsb.nceas.utilities.Options;
36

    
37
import java.io.File;
38
import java.io.StringReader;
39
import java.util.Date;
40
import junit.framework.Test;
41
import junit.framework.TestCase;
42
import junit.framework.TestSuite;
43

    
44
/**
45
 * Tests HarvestDocument code using JUnit.
46
 *
47
 * @author  costa
48
 */
49
public class HarvestDocumentTest extends TestCase {
50

    
51
  private Harvester harvester;
52
  private HarvestDocument harvestDocument;
53
  private HarvestSiteSchedule harvestSiteSchedule;
54
  /* Initialize Options*/
55
  static
56
  {
57
	  try
58
	  {
59
		  Options.initialize(new File("build/tests/metacat.properties"));
60
		  MetaCatUtil.pathsForIndexing 
61
		         = MetaCatUtil.getOptionList(PropertyService.getProperty("indexPaths"));
62
	  }
63
	  catch(Exception e)
64
	  {
65
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
66
	  }
67
  }
68

    
69
  /**
70
   * Constructor for this test.
71
   * 
72
   * @param name     name of the test case
73
   */
74
  public HarvestDocumentTest(String name) {
75
    super(name);
76
  }
77
  
78

    
79
  /**
80
   * Sets up the test by instantiating HarvestSiteSchedule and HarvestDocument
81
   * objects.
82
   */
83
  protected void setUp() {
84
    String contactEmail = "jdoe@institution.edu";
85
    String dateLastHarvest = "2004-04-01 00:00:00.0";
86
    String dateNextHarvest = "2004-05-01 00:00:00.0";
87
    int detailLogID;
88
    String documentListURL = 
89
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
90
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
91
    String documentURL = 
92
                     "http://www.lternet.edu/~dcosta/testHarvest/document1.xml";
93
    String errorMessage = "JUnit Testing";
94
    int harvestLogID;
95
    String harvestOperationCode = "HarvesterStartup";
96
    Date harvestStartTime = new Date();
97
    int identifier = 1;
98
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
99
    String ldapPwd = "secretpassword";
100
    String message = "JUnit Testing";
101
    int revision = 1;
102
    String scope = "docname";
103
    int siteScheduleID = 1;
104
    int status = 0;
105
    boolean test = true;
106
    String unit = "months";
107
    int updateFrequency = 1;
108

    
109
    harvester = new Harvester();
110
    Harvester.loadOptions(test);
111
    harvester.getConnection();  // initializes the database connection
112
    harvester.initLogIDs();
113
    harvester.setHarvestStartTime(new Date());
114

    
115
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
116
                                                  siteScheduleID,
117
                                                  documentListURL,
118
                                                  ldapDN,
119
                                                  ldapPwd,
120
                                                  dateNextHarvest,
121
                                                  dateLastHarvest,
122
                                                  updateFrequency,
123
                                                  unit,
124
                                                  contactEmail
125
                                                 );
126

    
127
    harvestDocument = new HarvestDocument(harvester,
128
                                          harvestSiteSchedule,
129
                                          scope,
130
                                          identifier,
131
                                          revision,
132
                                          documentType,
133
                                          documentURL
134
                                        );
135
  }
136
  
137

    
138
  /**
139
   * Closes the database connection after the test completes.
140
   */
141
  protected void tearDown() {
142
    harvester.closeConnection();
143
  }
144
  
145

    
146
  /**
147
   * Tests the getSiteDocument() method. The test succeeds if a non-null
148
   * StringReader is returned.
149
   */
150
  public void testGetSiteDocument() {
151
    StringReader stringReader = null;
152
    stringReader = harvestDocument.getSiteDocument();
153
    assertTrue(stringReader != null);
154
  }
155
  
156
  
157
  /**
158
   * Tests that the harvesterDocument object was created successfully.
159
   */
160
  public void testHarvestDocumentObject() {
161
    assertTrue(harvestDocument != null);
162
  }
163
  
164

    
165
  /**
166
   * Tests the metacatHighestRevision() method. This test ensures that -1
167
   * is returned for a non-existent document.
168
   */
169
  public void testMetacatHighestRevision() {
170
    int highestRevision;
171
    
172
    highestRevision = harvestDocument.metacatHighestRevision();
173
    assertTrue(highestRevision == -1);
174
  }
175

    
176

    
177
  /**
178
   * Tests the printOutput() method.
179
   */
180
  public void testPrintOutput() {
181
    harvestDocument.printOutput(System.out);
182
  }
183
  
184
  
185
  /**
186
   * Returns the test suite. The test suite consists of all methods in this
187
   * class whose names start with "test".
188
   * 
189
   * @return  a TestSuite object
190
   */
191
  public static Test suite() {
192
    return new TestSuite(HarvestDocumentTest.class);
193
  }
194
  
195

    
196
  /**
197
   * The main program. Runs the test suite.
198
   * 
199
   * @param args   command line argument array.
200
   */
201
  public static void main(String args[]) {
202
    junit.textui.TestRunner.run(suite());
203
  }
204

    
205
}
(2-2/5)