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: 2009-02-23 11:29:07 -0800 (Mon, 23 Feb 2009) $'
11
 * '$Revision: 4816 $'
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.MCTestCase;
31
import edu.ucsb.nceas.metacat.harvesterClient.HarvestDocument;
32
import edu.ucsb.nceas.metacat.harvesterClient.HarvestSiteSchedule;
33
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
34
import edu.ucsb.nceas.metacat.service.PropertyService;
35
import edu.ucsb.nceas.metacat.util.MetacatUtil;
36

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

    
42
/**
43
 * Tests HarvestDocument code using JUnit.
44
 *
45
 * @author  costa
46
 */
47
public class HarvestDocumentTest extends MCTestCase {
48

    
49
  private Harvester harvester;
50
  private HarvestDocument harvestDocument;
51
  private HarvestSiteSchedule harvestSiteSchedule;
52
  /* Initialize Properties*/
53
  static
54
  {
55
	  try
56
	  {
57
		  PropertyService.getInstance();
58
	  }
59
	  catch(Exception e)
60
	  {
61
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
62
	  }
63
  }
64

    
65
  /**
66
   * Constructor for this test.
67
   * 
68
   * @param name     name of the test case
69
   */
70
  public HarvestDocumentTest(String name) {
71
    super(name);
72
  }
73
  
74

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

    
105
    harvester = new Harvester();
106
    Harvester.loadProperties(test);
107
    harvester.getConnection();  // initializes the database connection
108
    harvester.initLogIDs();
109
    harvester.setHarvestStartTime(new Date());
110

    
111
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
112
                                                  siteScheduleID,
113
                                                  documentListURL,
114
                                                  ldapDN,
115
                                                  ldapPwd,
116
                                                  dateNextHarvest,
117
                                                  dateLastHarvest,
118
                                                  updateFrequency,
119
                                                  unit,
120
                                                  contactEmail
121
                                                 );
122

    
123
    harvestDocument = new HarvestDocument(harvester,
124
                                          harvestSiteSchedule,
125
                                          scope,
126
                                          identifier,
127
                                          revision,
128
                                          documentType,
129
                                          documentURL
130
                                        );
131
  }
132
  
133

    
134
  /**
135
   * Closes the database connection after the test completes.
136
   */
137
  protected void tearDown() {
138
    harvester.closeConnection();
139
  }
140
  
141

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

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

    
172

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

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

    
201
}
(2-2/5)