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