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 Harvester 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.Harvester;
31
import edu.ucsb.nceas.utilities.Options;
32
import java.io.File;
33
import java.io.FileInputStream;
34
import java.io.IOException;
35
import junit.framework.Test;
36
import junit.framework.TestCase;
37
import junit.framework.TestSuite;
38

    
39
/**
40
 * Test Harvester code using JUnit.
41
 *
42
 * @author  costa
43
 */
44
public class HarvesterTest extends TestCase {
45

    
46
  private Harvester harvester;
47
  
48

    
49
  public HarvesterTest(String name) {
50
    super(name);
51
  }
52
  
53
  
54
  protected void setUp() {
55
    harvester = new Harvester();
56
  }
57
  
58
  
59
  protected void tearDown() {
60
  }
61
  
62
  
63
  public void testDequoteText() {
64
    String singleQuoteString = "I can't see how it's done!\n";
65
    String compareString = "I can\"t see how it\"s done!";
66
    String dequotedString = "";
67
    
68
    dequotedString = harvester.dequoteText(singleQuoteString);
69
    assertTrue(dequotedString.equals(compareString));
70
    System.out.println("Dequoted string: " + dequotedString);
71
  }
72
  
73
  
74
  /**
75
   * Test that the Harvester object was created successfully.
76
   */
77
  public void testHarvesterObject() {
78
    assertTrue(harvester != null);
79
  }
80
  
81
  
82
  /**
83
   * Tests loading of Harvester properties from a configuration file.
84
   */
85
  public void testLoadOptions() {
86
    Options options;
87
    String ctm;
88
    boolean test = true;
89
    
90
    Harvester.loadOptions(test);
91
    options = Harvester.options;
92
    ctm = options.getOption("connectToMetacat");
93
    assertTrue(ctm.equals("true") || ctm.equals("false"));
94
  }
95
  
96
  
97
  /**
98
   * Prints the files in the current working directory. This may be useful
99
   * for determining which directory all other tests are running in.
100
   */
101
  public void testWorkingDirectory() {
102
    String[] dir = new java.io.File(".").list(); // Get files in current dir
103

    
104
    java.util.Arrays.sort(dir);                  // Sort the directory listing
105

    
106
    for (int i=0; i<dir.length; i++)
107
      System.out.println(dir[i]);                // Print the list
108
  }
109
  
110
  
111
  /**
112
   * Returns the test suite. The test suite consists of all methods in this
113
   * class whose names start with "test".
114
   * 
115
   * @return  a TestSuite object
116
   */
117
  public static Test suite() {
118
    return new TestSuite(HarvesterTest.class);
119
  }
120
  
121

    
122
  /**
123
   * The main program. Runs the test suite.
124
   * 
125
   * @param args   command line argument array.
126
   */
127
  public static void main(String args[]) {
128
    junit.textui.TestRunner.run(suite());
129
  }
130

    
131
}
(5-5/5)