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: jones $'
|
9
|
* '$Date: 2006-11-10 11:30:36 -0800 (Fri, 10 Nov 2006) $'
|
10
|
* '$Revision: 3080 $'
|
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
|
import org.apache.commons.logging.Log;
|
36
|
import org.apache.commons.logging.LogFactory;
|
37
|
|
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
|
private static final Log log = LogFactory.getLog("edu.ucsb.nceas.metacattest.ReplicationServerListTest");
|
50
|
|
51
|
/**
|
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
|
|
73
|
/**
|
74
|
* Establish a testing framework by initializing appropriate objects
|
75
|
*/
|
76
|
public void setUp()
|
77
|
{
|
78
|
|
79
|
}
|
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
|
log.debug("Error in ReplicationServerList() to get" +
|
105
|
" DBConnection pool"+e.getMessage());
|
106
|
}//catch
|
107
|
|
108
|
TestSuite suite = new TestSuite();
|
109
|
|
110
|
try
|
111
|
{
|
112
|
|
113
|
//create a new subtree
|
114
|
SubTree subTree = new SubTree("eml.349", "distribution1", 118214, 118223);
|
115
|
|
116
|
//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
|
|
122
|
|
123
|
}//try
|
124
|
catch (Exception e)
|
125
|
{
|
126
|
log.debug("Error in SubTreeTest.suite: "+
|
127
|
e.getMessage());
|
128
|
}//catch
|
129
|
return suite;
|
130
|
}
|
131
|
|
132
|
|
133
|
|
134
|
/**
|
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
|
* Test the method getSubTreeNodeStack
|
146
|
*/
|
147
|
public void testGetSubTreeNodeStack()
|
148
|
{
|
149
|
Stack nodeStack = null;
|
150
|
try{
|
151
|
nodeStack = tree.getSubTreeNodeStack();
|
152
|
}//try
|
153
|
catch (Exception e)
|
154
|
{
|
155
|
log.debug("Error in SubTreeTest.suite: "+ e.getMessage());
|
156
|
}//catch
|
157
|
|
158
|
while (!nodeStack.empty())
|
159
|
{
|
160
|
NodeRecord node =(NodeRecord)nodeStack.pop();
|
161
|
String nodeType = node.getNodeType();
|
162
|
if ( nodeType != null && nodeType.equals("ELEMENT"))
|
163
|
{
|
164
|
log.debug("Elment: "+ node.getNodeName());
|
165
|
}
|
166
|
else if (nodeType != null && nodeType.equals("ATTRIBUTE"))
|
167
|
{
|
168
|
log.debug("Attribute: " +node.getNodeName() +
|
169
|
" = " + node.getNodeData());
|
170
|
}
|
171
|
else
|
172
|
{
|
173
|
log.debug("text: " + node.getNodeData());
|
174
|
}
|
175
|
}
|
176
|
assertTrue(1 == 1);
|
177
|
}
|
178
|
}
|