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: tao $'
10
 *     '$Date: 2007-11-03 21:09:12 -0700 (Sat, 03 Nov 2007) $'
11
 * '$Revision: 3566 $'
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.MetaCatUtil;
31
import edu.ucsb.nceas.metacat.harvesterClient.Harvester;
32
import edu.ucsb.nceas.utilities.Options;
33
import java.io.File;
34
import java.io.FileInputStream;
35
import java.io.IOException;
36
import junit.framework.Test;
37
import junit.framework.TestCase;
38
import junit.framework.TestSuite;
39

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

    
47
  private Harvester harvester;
48
  /* Initialize Options*/
49
  static
50
  {
51
	  try
52
	  {
53
		  Options.initialize(new File("build/tests/metacat.properties"));
54
		  MetaCatUtil.pathsForIndexing 
55
		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
56
	  }
57
	  catch(Exception e)
58
	  {
59
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
60
	  }
61
  }
62

    
63
  /**
64
   * Constructor for this test.
65
   * 
66
   * @param name     name of the test case
67
   */
68
  public HarvesterTest(String name) {
69
    super(name);
70
  }
71
  
72

    
73
  /**
74
   * Sets up the test by instantiating a Harvester object.
75
   */
76
  protected void setUp() {
77
    harvester = new Harvester();
78
  }
79
  
80

    
81
  /**
82
   * No clean-up actions necessary for these tests.
83
   */
84
  protected void tearDown() {
85
  }
86
  
87

    
88
  /**
89
   * Tests the dequoteText() string function. It converts single quotes to
90
   * double quotes.
91
   */
92
  public void testDequoteText() {
93
    String singleQuoteString = "I can't see how it's done!\n";
94
    String compareString = "I can\"t see how it\"s done!";
95
    String dequotedString = "";
96
    
97
    dequotedString = harvester.dequoteText(singleQuoteString);
98
    assertTrue(dequotedString.equals(compareString));
99
    System.out.println("Dequoted string: " + dequotedString);
100
  }
101
  
102
  
103
  /**
104
   * Tests that the Harvester object was created successfully.
105
   */
106
  public void testHarvesterObject() {
107
    assertTrue(harvester != null);
108
  }
109
  
110
  
111
  /**
112
   * Tests loading of Harvester properties from a configuration file.
113
   */
114
  public void testLoadOptions() {
115
    Options options;
116
    String ctm;
117
    boolean test = true;
118
    
119
    Harvester.loadOptions(test);
120
    options = Harvester.options;
121
    ctm = options.getOption("connectToMetacat");
122
    assertTrue(ctm.equals("true") || ctm.equals("false"));
123
  }
124
  
125
  
126
  /**
127
   * Prints the files in the current working directory. This may be useful
128
   * for determining which directory all other tests are running in.
129
   */
130
  public void testWorkingDirectory() {
131
    String[] dir = new java.io.File(".").list(); // Get files in current dir
132

    
133
    java.util.Arrays.sort(dir);                  // Sort the directory listing
134

    
135
    for (int i=0; i<dir.length; i++)
136
      System.out.println(dir[i]);                // Print the list
137
  }
138
  
139
  
140
  /**
141
   * Returns the test suite. The test suite consists of all methods in this
142
   * class whose names start with "test".
143
   * 
144
   * @return  a TestSuite object
145
   */
146
  public static Test suite() {
147
    return new TestSuite(HarvesterTest.class);
148
  }
149
  
150

    
151
  /**
152
   * The main program. Runs the test suite.
153
   * 
154
   * @param args   command line argument array.
155
   */
156
  public static void main(String args[]) {
157
    junit.textui.TestRunner.run(suite());
158
  }
159

    
160
}
(5-5/5)