Project

General

Profile

1 1503 tao
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5 3080 jones
 *    Purpose: To test the ReplicationServerList class by JUnit
6
 *    Authors: Jing Tao
7 1503 tao
 *
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
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 4384 daigle
import edu.ucsb.nceas.MCTestCase;
30 1503 tao
import edu.ucsb.nceas.metacat.*;
31 4080 daigle
import edu.ucsb.nceas.metacat.service.PropertyService;
32 4701 daigle
import edu.ucsb.nceas.metacat.util.MetacatUtil;
33 4384 daigle
34 1503 tao
import junit.framework.Test;
35
import junit.framework.TestSuite;
36 4384 daigle
37 2917 jones
import org.apache.commons.logging.Log;
38
import org.apache.commons.logging.LogFactory;
39 1503 tao
40
import java.util.*;
41
42
43
/**
44
 * A JUnit test for testing Step class processing
45
 */
46 4384 daigle
public class SubTreeTest extends MCTestCase
47 1503 tao
{
48
  private SubTree tree = null;
49 2917 jones
  private static final Log log = LogFactory.getLog("edu.ucsb.nceas.metacattest.ReplicationServerListTest");
50 4127 daigle
  /* Initialize properties*/
51 3567 tao
  static
52
  {
53
	  try
54
	  {
55 4701 daigle
		  MetacatUtil.pathsForIndexing
56
		         = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
57 3567 tao
	  }
58
	  catch(Exception e)
59
	  {
60
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
61
	  }
62
  }
63 1503 tao
  /**
64
   * Constructor to build the test
65
   *
66
   * @param name the name of the test method
67
   */
68
  public SubTreeTest(String name)
69
  {
70
    super(name);
71
  }
72
73
  /**
74
   * Constructor to build the test
75
   *
76
   * @param name the name of the test method
77
   * @param tree the subtree
78
   */
79
  public SubTreeTest(String name, SubTree myTree)
80
  {
81
    super(name);
82
    this.tree = myTree;
83
  }
84 2243 sgarg
85 1503 tao
  /**
86
   * Establish a testing framework by initializing appropriate objects
87
   */
88
  public void setUp()
89
 {
90 2243 sgarg
91 1503 tao
 }
92
93
  /**
94
   * Release any objects after tests are complete
95
   */
96
  public void tearDown()
97
  {
98
    //DBConnectionPool will be release
99
    DBConnectionPool.release();
100
  }
101
102
  /**
103
   * Create a suite of tests to be run together
104
   */
105
  public static Test suite()
106
  {
107
     //Get DBConnection pool, this is only for junit test.
108
    //Because DBConnection is singleton class. So there is only one DBConnection
109
    //pool in the program
110
    try
111
    {
112
      DBConnectionPool pool = DBConnectionPool.getInstance();
113
    }//try
114
    catch (Exception e)
115
    {
116 2917 jones
        log.debug("Error in ReplicationServerList() to get" +
117
                        " DBConnection pool"+e.getMessage());
118 1503 tao
    }//catch
119 2243 sgarg
120 1503 tao
    TestSuite suite = new TestSuite();
121 2243 sgarg
122 1503 tao
    try
123
    {
124 2243 sgarg
125 1503 tao
      //create a new subtree
126
      SubTree subTree = new SubTree("eml.349", "distribution1", 118214, 118223);
127 2243 sgarg
128 1503 tao
      //Doing test test cases
129
      suite.addTest(new SubTreeTest("initialize"));
130
      System.out.println("before adding testGetSubTreeNodeStack() into suite");
131
      suite.addTest(new SubTreeTest("testGetSubTreeNodeStack", subTree));
132
      System.out.println("here!!");
133 2243 sgarg
134
135 1503 tao
    }//try
136
    catch (Exception e)
137
    {
138 2917 jones
        log.debug("Error in SubTreeTest.suite: "+
139
                                e.getMessage());
140 1503 tao
    }//catch
141
    return suite;
142
 }
143
144
145 2243 sgarg
146 1503 tao
  /**
147
   * Run an initial test that always passes to check that the test
148
   * harness is working.
149
   */
150
  public void initialize()
151
  {
152
    System.out.println("in initialize");
153
    assertTrue(1 == 1);
154
  }
155
156
  /**
157 2243 sgarg
   * Test the method getSubTreeNodeStack
158 1503 tao
   */
159
  public void testGetSubTreeNodeStack()
160
  {
161 2243 sgarg
    Stack nodeStack = null;
162
    try{
163
      nodeStack = tree.getSubTreeNodeStack();
164
    }//try
165
    catch (Exception e)
166
    {
167 2917 jones
        log.debug("Error in SubTreeTest.suite: "+ e.getMessage());
168 2243 sgarg
    }//catch
169
170 3567 tao
    while (nodeStack != null && !nodeStack.empty())
171 1503 tao
    {
172
      NodeRecord node =(NodeRecord)nodeStack.pop();
173
      String nodeType = node.getNodeType();
174
      if ( nodeType != null && nodeType.equals("ELEMENT"))
175
      {
176 2917 jones
          log.debug("Elment: "+ node.getNodeName());
177 1503 tao
      }
178
      else if (nodeType != null && nodeType.equals("ATTRIBUTE"))
179
      {
180 2917 jones
          log.debug("Attribute: "  +node.getNodeName() +
181
                                 " = " + node.getNodeData());
182 1503 tao
      }
183
      else
184
      {
185 2917 jones
          log.debug("text: " + node.getNodeData());
186 1503 tao
      }
187
    }
188 3567 tao
189 2243 sgarg
  }
190 2917 jones
}