Project

General

Profile

1 2134 costa
/**
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$'
10
 *     '$Date$'
11
 * '$Revision$'
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 2158 costa
import edu.ucsb.nceas.utilities.Options;
32 2134 costa
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. Not yet implemented. The test
41
 * contained herein is just a placeholder for the actual tests to be
42
 * added.
43
 *
44
 * @author  costa
45
 */
46
public class HarvesterTest extends TestCase {
47
48
  private Harvester harvester;
49
50
51
  public HarvesterTest(String name) {
52
    super(name);
53
  }
54
55
56
  protected void setUp() {
57
    harvester = new Harvester();
58
  }
59
60
61
  protected void tearDown() {
62
  }
63
64
65 2143 costa
  public void testDequoteText() {
66
    String singleQuoteString = "I can't see how it's done!\n";
67
    String compareString = "I can\"t see how it\"s done!";
68
    String dequotedString = "";
69
70
    dequotedString = harvester.dequoteText(singleQuoteString);
71
    assertTrue(dequotedString.equals(compareString));
72
    System.out.println("Dequoted string: " + dequotedString);
73
  }
74
75
76 2134 costa
  /**
77 2143 costa
   * Test that the Harvester object was created successfully.
78
   */
79
  public void testHarvesterObject() {
80
    assertTrue(harvester != null);
81
  }
82
83
84
  /**
85 2134 costa
   * Tests loading of Harvester properties from a configuration file.
86
   */
87 2158 costa
  public void testLoadOptions() {
88
    Options options;
89
    String ctm;
90
    boolean test = true;
91
92
    Harvester.loadOptions(test);
93
    options = Harvester.options;
94
    ctm = options.getOption("connectToMetacat");
95
    assertTrue(ctm.equals("true") || ctm.equals("false"));
96 2134 costa
  }
97
98
99
  /**
100 2143 costa
   * Prints the files in the current working directory. This may be useful
101
   * for determining which directory all other tests are running in.
102
   */
103
  public void testWorkingDirectory() {
104
    String[] dir = new java.io.File(".").list(); // Get files in current dir
105
106
    java.util.Arrays.sort(dir);                  // Sort the directory listing
107
108
    for (int i=0; i<dir.length; i++)
109
      System.out.println(dir[i]);                // Print the list
110
  }
111
112
113
  /**
114 2134 costa
   * Returns the test suite. The test suite consists of all methods in this
115
   * class whose names start with "test".
116
   *
117
   * @return  a TestSuite object
118
   */
119
  public static Test suite() {
120
    return new TestSuite(HarvesterTest.class);
121
  }
122
123
124
  /**
125
   * The main program. Runs the test suite.
126
   *
127
   * @param args   command line argument array.
128
   */
129
  public static void main(String args[]) {
130
    junit.textui.TestRunner.run(suite());
131
  }
132
133
}