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: 2009-07-27 14:47:44 -0700 (Mon, 27 Jul 2009) $'
11
 * '$Revision: 4999 $'
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
			PropertyService.getInstance();
51
		} catch (Exception e) {
52
			System.err.println("Exception in initialize option in MetacatServletNetTest "
53
					+ e.getMessage());
54
		}
55
	}
56

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

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

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

    
83
  /**
84
   * Tests the dequoteText() string function. It converts single quotes to
85
   * double quotes.
86
   */
87
  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
  /**
99
   * Tests that the Harvester object was created successfully.
100
   */
101
  public void testHarvesterObject() {
102
    assertTrue(harvester != null);
103
  }
104
  
105
  
106
    /**
107
	 * Tests loading of Harvester properties from a configuration file.
108
	 */
109
	public void testLoadProperties() {
110
	    boolean commandLineMode = true;
111
		String ctm = null;
112
		boolean test = true;
113

    
114
		Harvester.loadProperties(commandLineMode, 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)