Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *    Purpose: To test the ReplicationServerList class by JUnit
6
 *    Authors: Jing Tao
7
 *
8
 *   '$Author: daigle $'
9
 *     '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
10
 * '$Revision: 4080 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacattest;
28

    
29
import edu.ucsb.nceas.metacat.*;
30
import edu.ucsb.nceas.metacat.service.PropertyService;
31
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
32
import edu.ucsb.nceas.utilities.Options;
33
//import edu.ucsb.nceas.morpho.framework.*;
34
import junit.framework.Test;
35
import junit.framework.TestCase;
36
import junit.framework.TestResult;
37
import junit.framework.TestSuite;
38
import org.apache.commons.logging.Log;
39
import org.apache.commons.logging.LogFactory;
40

    
41
import java.io.*;
42
import java.net.*;
43
import java.util.*;
44

    
45

    
46
/**
47
 * A JUnit test for testing Step class processing
48
 */
49
public class SubTreeTest extends TestCase
50
{
51
  private SubTree tree = null;
52
  private static final Log log = LogFactory.getLog("edu.ucsb.nceas.metacattest.ReplicationServerListTest");
53
  /* Initialize Options*/
54
  static
55
  {
56
	  try
57
	  {
58
		  Options.initialize(new File("build/tests/metacat.properties"));
59
		  MetaCatUtil.pathsForIndexing 
60
		         = MetaCatUtil.getOptionList(PropertyService.getProperty("indexPaths"));
61
	  }
62
	  catch(Exception e)
63
	  {
64
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
65
	  }
66
  }
67
  /**
68
   * Constructor to build the test
69
   *
70
   * @param name the name of the test method
71
   */
72
  public SubTreeTest(String name)
73
  {
74
    super(name);
75
  }
76

    
77
  /**
78
   * Constructor to build the test
79
   *
80
   * @param name the name of the test method
81
   * @param tree the subtree
82
   */
83
  public SubTreeTest(String name, SubTree myTree)
84
  {
85
    super(name);
86
    this.tree = myTree;
87
  }
88

    
89
  /**
90
   * Establish a testing framework by initializing appropriate objects
91
   */
92
  public void setUp()
93
 {
94

    
95
 }
96

    
97
  /**
98
   * Release any objects after tests are complete
99
   */
100
  public void tearDown()
101
  {
102
    //DBConnectionPool will be release
103
    DBConnectionPool.release();
104
  }
105

    
106
  /**
107
   * Create a suite of tests to be run together
108
   */
109
  public static Test suite()
110
  {
111
     //Get DBConnection pool, this is only for junit test.
112
    //Because DBConnection is singleton class. So there is only one DBConnection
113
    //pool in the program
114
    try
115
    {
116
      DBConnectionPool pool = DBConnectionPool.getInstance();
117
    }//try
118
    catch (Exception e)
119
    {
120
        log.debug("Error in ReplicationServerList() to get" +
121
                        " DBConnection pool"+e.getMessage());
122
    }//catch
123

    
124
    TestSuite suite = new TestSuite();
125

    
126
    try
127
    {
128

    
129
      //create a new subtree
130
      SubTree subTree = new SubTree("eml.349", "distribution1", 118214, 118223);
131

    
132
      //Doing test test cases
133
      suite.addTest(new SubTreeTest("initialize"));
134
      System.out.println("before adding testGetSubTreeNodeStack() into suite");
135
      suite.addTest(new SubTreeTest("testGetSubTreeNodeStack", subTree));
136
      System.out.println("here!!");
137

    
138

    
139
    }//try
140
    catch (Exception e)
141
    {
142
        log.debug("Error in SubTreeTest.suite: "+
143
                                e.getMessage());
144
    }//catch
145
    return suite;
146
 }
147

    
148

    
149

    
150
  /**
151
   * Run an initial test that always passes to check that the test
152
   * harness is working.
153
   */
154
  public void initialize()
155
  {
156
    System.out.println("in initialize");
157
    assertTrue(1 == 1);
158
  }
159

    
160
  /**
161
   * Test the method getSubTreeNodeStack
162
   */
163
  public void testGetSubTreeNodeStack()
164
  {
165
    Stack nodeStack = null;
166
    try{
167
      nodeStack = tree.getSubTreeNodeStack();
168
    }//try
169
    catch (Exception e)
170
    {
171
        log.debug("Error in SubTreeTest.suite: "+ e.getMessage());
172
    }//catch
173

    
174
    while (nodeStack != null && !nodeStack.empty())
175
    {
176
      NodeRecord node =(NodeRecord)nodeStack.pop();
177
      String nodeType = node.getNodeType();
178
      if ( nodeType != null && nodeType.equals("ELEMENT"))
179
      {
180
          log.debug("Elment: "+ node.getNodeName());
181
      }
182
      else if (nodeType != null && nodeType.equals("ATTRIBUTE"))
183
      {
184
          log.debug("Attribute: "  +node.getNodeName() +
185
                                 " = " + node.getNodeData());
186
      }
187
      else
188
      {
189
          log.debug("text: " + node.getNodeData());
190
      }
191
    }
192
   
193
  }
194
}
(16-16/18)