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 4385 daigle
import edu.ucsb.nceas.MCTestCase;
31 2134 costa
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32 5035 daigle
import edu.ucsb.nceas.metacat.properties.PropertyService;
33 4701 daigle
import edu.ucsb.nceas.metacat.util.MetacatUtil;
34 4127 daigle
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
35 4385 daigle
36 2134 costa
import junit.framework.Test;
37
import junit.framework.TestSuite;
38
39
/**
40 2255 costa
 * Tests Harvester code using JUnit.
41 2134 costa
 *
42
 * @author  costa
43
 */
44 4385 daigle
public class HarvesterTest extends MCTestCase {
45 2134 costa
46
  private Harvester harvester;
47 4127 daigle
	/* Initialize Properties */
48
	static {
49
		try {
50 4816 daigle
			PropertyService.getInstance();
51 4127 daigle
		} catch (Exception e) {
52
			System.err.println("Exception in initialize option in MetacatServletNetTest "
53
					+ e.getMessage());
54
		}
55
	}
56 2134 costa
57 2255 costa
  /**
58 4127 daigle
	 * Constructor for this test.
59
	 *
60
	 * @param name
61
	 *            name of the test case
62
	 */
63 2134 costa
  public HarvesterTest(String name) {
64
    super(name);
65
  }
66
67 2255 costa
68
  /**
69
   * Sets up the test by instantiating a Harvester object.
70
   */
71 2134 costa
  protected void setUp() {
72
    harvester = new Harvester();
73
  }
74
75 2255 costa
76
  /**
77
   * No clean-up actions necessary for these tests.
78
   */
79 2134 costa
  protected void tearDown() {
80
  }
81
82 2255 costa
83
  /**
84
   * Tests the dequoteText() string function. It converts single quotes to
85
   * double quotes.
86
   */
87 2143 costa
  public void testDequoteText() {
88
    String singleQuoteString = "I can't see how it's done!\n";
89
    String compareString = "I can\"t see how it\"s done!";
90
    String dequotedString = "";
91
92
    dequotedString = harvester.dequoteText(singleQuoteString);
93
    assertTrue(dequotedString.equals(compareString));
94
    System.out.println("Dequoted string: " + dequotedString);
95
  }
96
97
98 2134 costa
  /**
99 2255 costa
   * Tests that the Harvester object was created successfully.
100 2143 costa
   */
101
  public void testHarvesterObject() {
102
    assertTrue(harvester != null);
103
  }
104
105
106 4127 daigle
    /**
107
	 * Tests loading of Harvester properties from a configuration file.
108
	 */
109
	public void testLoadProperties() {
110 4999 costa
	    boolean commandLineMode = true;
111 4127 daigle
		String ctm = null;
112
		boolean test = true;
113
114 8099 leinfelder
		Harvester.loadProperties(metacatContextDir);
115 4127 daigle
		try {
116 4172 daigle
			ctm = PropertyService.getProperty("harvester.connectToMetacat");
117 4127 daigle
		} catch (PropertyNotFoundException pnfe) {
118
			fail("Could not get connectToMetacat property: "+ pnfe.getMessage());
119
		}
120
		assertTrue(ctm.equals("true") || ctm.equals("false"));
121
	}
122 2134 costa
123
124
  /**
125 4127 daigle
	 * Prints the files in the current working directory. This may be useful for
126
	 * determining which directory all other tests are running in.
127
	 */
128 2143 costa
  public void testWorkingDirectory() {
129
    String[] dir = new java.io.File(".").list(); // Get files in current dir
130
131
    java.util.Arrays.sort(dir);                  // Sort the directory listing
132
133
    for (int i=0; i<dir.length; i++)
134
      System.out.println(dir[i]);                // Print the list
135
  }
136
137
138
  /**
139 2134 costa
   * Returns the test suite. The test suite consists of all methods in this
140
   * class whose names start with "test".
141
   *
142
   * @return  a TestSuite object
143
   */
144
  public static Test suite() {
145
    return new TestSuite(HarvesterTest.class);
146
  }
147
148
149
  /**
150
   * The main program. Runs the test suite.
151
   *
152
   * @param args   command line argument array.
153
   */
154
  public static void main(String args[]) {
155
    junit.textui.TestRunner.run(suite());
156
  }
157
158
}