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-05-04 09:29:51 -0700 (Tue, 04 May 2004) $'
11
 * '$Revision: 2158 $'
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. Not yet implemented. The test
42
 * contained herein is just a placeholder for the actual tests to be
43
 * added.
44
 *
45
 * @author  costa
46
 */
47
public class HarvestDocumentTest extends TestCase {
48

    
49
  private Harvester harvester;
50
  private HarvestDocument harvestDocument;
51
  private HarvestSiteSchedule harvestSiteSchedule;
52
  
53

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

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

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

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

    
140

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

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

    
169
}
(2-2/5)