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 ReplicationServerListTest extends TestCase
|
48
|
{
|
49
|
private static String metacatReplicationURL=
|
50
|
MetaCatUtil.getOption("junitreplicationurl");
|
51
|
private ReplicationServerList serverList = null;
|
52
|
private static final Log log = LogFactory.getLog("edu.ucsb.nceas.metacattest.ReplicationServerListTest");
|
53
|
|
54
|
/**
|
55
|
* Constructor to build the test
|
56
|
*
|
57
|
* @param name the name of the test method
|
58
|
*/
|
59
|
public ReplicationServerListTest(String name)
|
60
|
{
|
61
|
super(name);
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Constructor to build the test
|
66
|
*
|
67
|
* @param name the name of the test method
|
68
|
* @param list the ReplicationServerList will be passed int
|
69
|
*/
|
70
|
public ReplicationServerListTest(String name, ReplicationServerList list)
|
71
|
{
|
72
|
super(name);
|
73
|
serverList=list;
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Establish a testing framework by initializing appropriate objects
|
78
|
*/
|
79
|
public void setUp()
|
80
|
{
|
81
|
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Release any objects after tests are complete
|
86
|
*/
|
87
|
public void tearDown()
|
88
|
{
|
89
|
//DBConnectionPool will be release
|
90
|
DBConnectionPool.release();
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Create a suite of tests to be run together
|
95
|
*/
|
96
|
public static Test suite()
|
97
|
{
|
98
|
//Get DBConnection pool, this is only for junit test.
|
99
|
//Because DBConnection is singleton class. So there is only one DBConnection
|
100
|
//pool in the program
|
101
|
try
|
102
|
{
|
103
|
DBConnectionPool pool = DBConnectionPool.getInstance();
|
104
|
}//try
|
105
|
catch (Exception e)
|
106
|
{
|
107
|
log.debug("Error in ReplicationServerList() to get" +
|
108
|
" DBConnection pool"+e.getMessage());
|
109
|
}//catch
|
110
|
|
111
|
TestSuite suite = new TestSuite();
|
112
|
suite.addTest(new ReplicationServerListTest("initialize"));
|
113
|
|
114
|
try
|
115
|
{
|
116
|
|
117
|
//Add two server into xml_replication table
|
118
|
URL dev = new URL(metacatReplicationURL+"?action=servercontrol&server=dev"+
|
119
|
"&subaction=add&replicate=1&datareplicate=1&hub=1");
|
120
|
URL epsilon = new URL(metacatReplicationURL+"?action=servercontrol"+
|
121
|
"&server=epsilon&subaction=add&replicate=0&datareplicate=1&hub=0");
|
122
|
InputStream input = dev.openStream();
|
123
|
input.close();
|
124
|
input = epsilon.openStream();
|
125
|
input.close();
|
126
|
|
127
|
//create a new server list
|
128
|
ReplicationServerList list = new ReplicationServerList();
|
129
|
|
130
|
//Doing test test cases
|
131
|
suite.addTest(new ReplicationServerListTest("testSize", list));
|
132
|
|
133
|
suite.addTest(new ReplicationServerListTest("testServerAt0", list));
|
134
|
suite.addTest(new ReplicationServerListTest("testServerAt1", list));
|
135
|
|
136
|
suite.addTest(new ReplicationServerListTest
|
137
|
("testNonEmptyServerList", list));
|
138
|
|
139
|
suite.addTest(new ReplicationServerListTest("testServerIsNotInList", list));
|
140
|
suite.addTest(new ReplicationServerListTest("testServerIsInList", list));
|
141
|
|
142
|
suite.addTest(new ReplicationServerListTest
|
143
|
("testGetLastCheckedDate", list));
|
144
|
|
145
|
suite.addTest(new ReplicationServerListTest
|
146
|
("testGetReplicationValueFalse", list));
|
147
|
|
148
|
suite.addTest(new ReplicationServerListTest
|
149
|
("testGetReplicationValueTrue", list));
|
150
|
suite.addTest(new ReplicationServerListTest
|
151
|
("testGetDataReplicationValueFalse", list));
|
152
|
|
153
|
suite.addTest(new ReplicationServerListTest("testGetHubValueTrue", list));
|
154
|
suite.addTest(new ReplicationServerListTest("testGetHubValueFalse", list));
|
155
|
|
156
|
//Delete this two server
|
157
|
URL deleteDev = new URL(metacatReplicationURL+"?action=servercontrol" +
|
158
|
"&server=dev&subaction=delete");
|
159
|
URL deleteEpsilon = new URL(metacatReplicationURL+"?action=servercontrol" +
|
160
|
"&server=epsilon&subaction=delete");
|
161
|
input = deleteDev.openStream();
|
162
|
input.close();
|
163
|
input = deleteEpsilon.openStream();
|
164
|
input.close();
|
165
|
}//try
|
166
|
catch (Exception e)
|
167
|
{
|
168
|
log.debug("Error in ReplicationServerListTest.suite: "+
|
169
|
e.getMessage());
|
170
|
}//catch
|
171
|
|
172
|
|
173
|
|
174
|
|
175
|
return suite;
|
176
|
}
|
177
|
|
178
|
|
179
|
|
180
|
/**
|
181
|
* Run an initial test that always passes to check that the test
|
182
|
* harness is working.
|
183
|
*/
|
184
|
public void initialize()
|
185
|
{
|
186
|
assertTrue(1 == 1);
|
187
|
}
|
188
|
|
189
|
|
190
|
/**
|
191
|
* Test the a empty server list is empty
|
192
|
*/
|
193
|
public void testEmptyServerList()
|
194
|
{
|
195
|
|
196
|
assertTrue(serverList.isEmpty());
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* Test the a non-empty server list is non-empty
|
201
|
*/
|
202
|
public void testNonEmptyServerList()
|
203
|
{
|
204
|
|
205
|
assertTrue(!serverList.isEmpty());
|
206
|
}
|
207
|
|
208
|
/**
|
209
|
* Test the size() method
|
210
|
*/
|
211
|
public void testSize()
|
212
|
{
|
213
|
int size = serverList.size();
|
214
|
assertTrue(size ==2);
|
215
|
}
|
216
|
|
217
|
/**
|
218
|
* Test the method serverAt(0)
|
219
|
*/
|
220
|
public void testServerAt0()
|
221
|
{
|
222
|
ReplicationServer server = serverList.serverAt(0);
|
223
|
String serverName = server.getServerName();
|
224
|
assertTrue(serverName.equals("dev"));
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* Test the method serverAt(1)
|
229
|
*/
|
230
|
public void testServerAt1()
|
231
|
{
|
232
|
ReplicationServer server = serverList.serverAt(1);
|
233
|
String serverName = server.getServerName();
|
234
|
assertTrue(serverName.equals("epsilon"));
|
235
|
}
|
236
|
|
237
|
|
238
|
/**
|
239
|
* Test the a given server is not in the server list
|
240
|
*/
|
241
|
public void testServerIsNotInList()
|
242
|
{
|
243
|
assertTrue(!serverList.isGivenServerInList("localhost"));
|
244
|
}
|
245
|
|
246
|
/**
|
247
|
* Test the a given server is in the server list
|
248
|
*/
|
249
|
public void testServerIsInList()
|
250
|
{
|
251
|
assertTrue(serverList.isGivenServerInList("dev"));
|
252
|
}
|
253
|
|
254
|
/**
|
255
|
* Test the method getLastCheckedDate
|
256
|
*/
|
257
|
public void testGetLastCheckedDate()
|
258
|
{
|
259
|
String lastCheckedDate = serverList.getLastCheckedDate("dev");
|
260
|
assertTrue(lastCheckedDate.equals("0001-01-01 BC"));
|
261
|
}
|
262
|
|
263
|
/**
|
264
|
* Test the method getReplicationValue(resulst is true)
|
265
|
*/
|
266
|
public void testGetReplicationValueTrue()
|
267
|
{
|
268
|
assertTrue(serverList.getReplicationValue("dev"));
|
269
|
}
|
270
|
|
271
|
/**
|
272
|
* Test the method getReplicationValue(result is false)
|
273
|
*/
|
274
|
public void testGetReplicationValueFalse()
|
275
|
{
|
276
|
assertTrue(!serverList.getReplicationValue("epsilon"));
|
277
|
}
|
278
|
|
279
|
/**
|
280
|
* Test the method getDataReplicationValue(result is true)
|
281
|
*/
|
282
|
public void testGetDataReplicationValueTrue()
|
283
|
{
|
284
|
assertTrue(serverList.getDataReplicationValue("dev"));
|
285
|
}
|
286
|
|
287
|
/**
|
288
|
* Test the method getDataReplicationValue(result is false)
|
289
|
*/
|
290
|
public void testGetDataReplicationValueFalse()
|
291
|
{
|
292
|
assertTrue(!serverList.getDataReplicationValue("epsilon"));
|
293
|
}
|
294
|
|
295
|
/**
|
296
|
* Test the method getHubValue(result is true)
|
297
|
*/
|
298
|
public void testGetHubValueTrue()
|
299
|
{
|
300
|
assertTrue(serverList.getHubValue("dev"));
|
301
|
}
|
302
|
|
303
|
/**
|
304
|
* Test the method getHubValue(result is false)
|
305
|
*/
|
306
|
public void testGetHubValueFalse()
|
307
|
{
|
308
|
assertTrue(!serverList.getHubValue("epsilon"));
|
309
|
}
|
310
|
|
311
|
|
312
|
}//ReplicationServerListTest
|