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