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