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: daigle $'
10
 *     '$Date: 2008-12-26 13:11:00 -0800 (Fri, 26 Dec 2008) $'
11
 * '$Revision: 4701 $'
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.MCTestCase;
31
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32
import edu.ucsb.nceas.metacat.service.PropertyService;
33
import edu.ucsb.nceas.metacat.util.MetacatUtil;
34
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
35

    
36
import junit.framework.Test;
37
import junit.framework.TestSuite;
38

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

    
46
  private Harvester harvester;
47
	/* Initialize Properties */
48
	static {
49
		try {
50
			MetacatUtil.pathsForIndexing = MetacatUtil.getOptionList(
51
					PropertyService.getProperty("xml.indexPaths"));
52
		} catch (Exception e) {
53
			System.err.println("Exception in initialize option in MetacatServletNetTest "
54
					+ e.getMessage());
55
		}
56
	}
57

    
58
  /**
59
	 * Constructor for this test.
60
	 * 
61
	 * @param name
62
	 *            name of the test case
63
	 */
64
  public HarvesterTest(String name) {
65
    super(name);
66
  }
67
  
68

    
69
  /**
70
   * Sets up the test by instantiating a Harvester object.
71
   */
72
  protected void setUp() {
73
    harvester = new Harvester();
74
  }
75
  
76

    
77
  /**
78
   * No clean-up actions necessary for these tests.
79
   */
80
  protected void tearDown() {
81
  }
82
  
83

    
84
  /**
85
   * Tests the dequoteText() string function. It converts single quotes to
86
   * double quotes.
87
   */
88
  public void testDequoteText() {
89
    String singleQuoteString = "I can't see how it's done!\n";
90
    String compareString = "I can\"t see how it\"s done!";
91
    String dequotedString = "";
92
    
93
    dequotedString = harvester.dequoteText(singleQuoteString);
94
    assertTrue(dequotedString.equals(compareString));
95
    System.out.println("Dequoted string: " + dequotedString);
96
  }
97
  
98
  
99
  /**
100
   * Tests that the Harvester object was created successfully.
101
   */
102
  public void testHarvesterObject() {
103
    assertTrue(harvester != null);
104
  }
105
  
106
  
107
    /**
108
	 * Tests loading of Harvester properties from a configuration file.
109
	 */
110
	public void testLoadProperties() {
111
		String ctm = null;
112
		boolean test = true;
113

    
114
		Harvester.loadProperties(test);
115
		try {
116
			ctm = PropertyService.getProperty("harvester.connectToMetacat");
117
		} catch (PropertyNotFoundException pnfe) {
118
			fail("Could not get connectToMetacat property: "+ pnfe.getMessage());
119
		}
120
		assertTrue(ctm.equals("true") || ctm.equals("false"));
121
	}
122
  
123
  
124
  /**
125
	 * 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
  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
   * 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
}
(5-5/5)