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