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 13:45:59 -0700 (Thu, 26 Aug 2004) $'
11
 * '$Revision: 2254 $'
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
 * Test 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
  public HarvestDocumentTest(String name) {
53
    super(name);
54
  }
55
  
56
  
57
  protected void setUp() {
58
    String contactEmail = "jdoe@institution.edu";
59
    String dateLastHarvest = "2004-04-01 00:00:00.0";
60
    String dateNextHarvest = "2004-05-01 00:00:00.0";
61
    int detailLogID;
62
    String documentListURL = 
63
                 "http://www.institution.edu/~jdoe/public_html/harvestList.xml";
64
    String documentType = "eml://ecoinformatics.org/eml-2.0.0";
65
    String documentURL = "http://www.lternet.edu/~dcosta/document1.xml";
66
    String errorMessage = "JUnit Testing";
67
    int harvestLogID;
68
    String harvestOperationCode = "HarvesterStartup";
69
    Date harvestStartTime = new Date();
70
    int identifier = 1;
71
    String ldapDN = "uid=jdoe,o=lter,dc=ecoinformatics,dc=org";
72
    String ldapPwd = "secretpassword";
73
    String message = "JUnit Testing";
74
    int revision = 1;
75
    String scope = "docname";
76
    int siteScheduleID = 1;
77
    int status = 0;
78
    boolean test = true;
79
    String unit = "months";
80
    int updateFrequency = 1;
81

    
82
    harvester = new Harvester();
83
    Harvester.loadOptions(test);
84
    harvester.getConnection();  // initializes the database connection
85
    harvester.initLogIDs();
86
    harvester.setHarvestStartTime(new Date());
87

    
88
    harvestSiteSchedule = new HarvestSiteSchedule(harvester,
89
                                                  siteScheduleID,
90
                                                  documentListURL,
91
                                                  ldapDN,
92
                                                  ldapPwd,
93
                                                  dateNextHarvest,
94
                                                  dateLastHarvest,
95
                                                  updateFrequency,
96
                                                  unit,
97
                                                  contactEmail
98
                                                 );
99

    
100
    harvestDocument = new HarvestDocument(harvester,
101
                                          harvestSiteSchedule,
102
                                          scope,
103
                                          identifier,
104
                                          revision,
105
                                          documentType,
106
                                          documentURL
107
                                        );
108
  }
109
  
110
  
111
  protected void tearDown() {
112
    harvester.closeConnection();
113
  }
114
  
115
  
116
  public void testGetSiteDocument() {
117
    StringReader stringReader = null;
118
    stringReader = harvestDocument.getSiteDocument();
119
    assertTrue(stringReader != null);
120
  }
121
  
122
  
123
  /**
124
   * Test that the harvesterDocument object was created successfully.
125
   */
126
  public void testHarvestDocumentObject() {
127
    assertTrue(harvestDocument != null);
128
  }
129
  
130
  
131
  public void testMetacatHighestRevision() {
132
    int highestRevision;
133
    
134
    highestRevision = harvestDocument.metacatHighestRevision();
135
    assertTrue(highestRevision == -1);
136
  }
137

    
138

    
139
  /**
140
   * Tests the printOutput() method.
141
   */
142
  public void testPrintOutput() {
143
    harvestDocument.printOutput(System.out);
144
  }
145
  
146
  
147
  /**
148
   * Returns the test suite. The test suite consists of all methods in this
149
   * class whose names start with "test".
150
   * 
151
   * @return  a TestSuite object
152
   */
153
  public static Test suite() {
154
    return new TestSuite(HarvestDocumentTest.class);
155
  }
156
  
157

    
158
  /**
159
   * The main program. Runs the test suite.
160
   * 
161
   * @param args   command line argument array.
162
   */
163
  public static void main(String args[]) {
164
    junit.textui.TestRunner.run(suite());
165
  }
166

    
167
}
(2-2/5)