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