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