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