Revision 8806
Added by ben leinfelder over 10 years ago
test/edu/ucsb/nceas/metacattest/MetaCatServletTest.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
package edu.ucsb.nceas.metacattest; |
28 | 28 |
|
29 |
import java.io.InputStream; |
|
30 |
import java.io.InputStreamReader; |
|
31 |
import java.io.StringWriter; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Properties; |
|
34 |
|
|
35 |
import junit.framework.Test; |
|
36 |
import junit.framework.TestSuite; |
|
29 | 37 |
import edu.ucsb.nceas.MCTestCase; |
30 | 38 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
31 | 39 |
import edu.ucsb.nceas.metacat.client.MetacatClient; |
... | ... | |
34 | 42 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
35 | 43 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
36 | 44 |
|
37 |
import junit.framework.Test; |
|
38 |
import junit.framework.TestSuite; |
|
39 | 45 |
|
40 |
import java.io.*; |
|
41 |
import java.net.*; |
|
42 |
import java.util.*; |
|
43 |
|
|
44 |
|
|
45 | 46 |
/** |
46 | 47 |
* A JUnit test for testing Step class processing |
47 | 48 |
*/ |
... | ... | |
167 | 168 |
String user = PropertyService.getProperty("test.mcUser"); |
168 | 169 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
169 | 170 |
assertTrue(logIn(user, passwd)); |
171 |
this.testLogOut(); |
|
172 |
|
|
170 | 173 |
} catch (PropertyNotFoundException pnfe) { |
171 | 174 |
fail("Could not find property: " + pnfe.getMessage()); |
172 | 175 |
} |
... | ... | |
181 | 184 |
String user = PropertyService.getProperty("test.mcUser"); |
182 | 185 |
String passwd = "BogusPasswordShouldFail"; |
183 | 186 |
assertTrue(!logIn(user, passwd)); |
187 |
this.testLogOut(); |
|
188 |
|
|
184 | 189 |
} catch (PropertyNotFoundException pnfe) { |
185 | 190 |
fail("Could not find property: " + pnfe.getMessage()); |
186 | 191 |
} |
... | ... | |
202 | 207 |
|
203 | 208 |
debug("Logging into lter: " + user + " : " + passwd); |
204 | 209 |
assertTrue(logIn(user, passwd)); |
210 |
this.testLogOut(); |
|
205 | 211 |
|
212 |
|
|
206 | 213 |
} |
207 | 214 |
|
208 | 215 |
/** |
... | ... | |
219 | 226 |
} |
220 | 227 |
assertTrue(!logIn(user, passwd)); |
221 | 228 |
// assertTrue( withProtocol.getProtocol().equals("http")); |
229 |
this.testLogOut(); |
|
230 |
|
|
222 | 231 |
} |
223 | 232 |
|
224 | 233 |
/** |
... | ... | |
237 | 246 |
debug("logging in Other user: " + user + ":" + passwd); |
238 | 247 |
assertTrue(logIn(user, passwd)); |
239 | 248 |
// assertTrue( withProtocol.getProtocol().equals("http")); |
249 |
this.testLogOut(); |
|
250 |
|
|
240 | 251 |
} |
241 | 252 |
|
242 | 253 |
/** |
... | ... | |
253 | 264 |
} |
254 | 265 |
assertTrue(!logIn(user, passwd)); |
255 | 266 |
// assertTrue( withProtocol.getProtocol().equals("http")); |
267 |
this.testLogOut(); |
|
268 |
|
|
256 | 269 |
} |
257 | 270 |
|
258 | 271 |
|
... | ... | |
266 | 279 |
try { |
267 | 280 |
String user = PropertyService.getProperty("test.mcUser"); |
268 | 281 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
269 |
|
|
282 |
metacat.login(user, passwd); |
|
283 |
|
|
270 | 284 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator") |
271 | 285 |
+ "1"; |
272 | 286 |
debug("insert docid: " + name); |
... | ... | |
277 | 291 |
+ "<permission>read</permission>" + "</allow>" + "</acl>"; |
278 | 292 |
debug("xml document: " + content); |
279 | 293 |
assertTrue(handleXMLDocument(content, name, "insert")); |
294 |
metacat.logout(); |
|
295 |
|
|
280 | 296 |
} catch (PropertyNotFoundException pnfe) { |
281 | 297 |
fail("Could not find property: " + pnfe.getMessage()); |
282 |
} |
|
298 |
} catch (Exception e) { |
|
299 |
// TODO Auto-generated catch block |
|
300 |
fail(e.getMessage()); |
|
301 |
e.printStackTrace(); |
|
302 |
} |
|
283 | 303 |
} |
284 | 304 |
|
285 | 305 |
/** |
... | ... | |
292 | 312 |
try { |
293 | 313 |
String user = PropertyService.getProperty("test.mcUser"); |
294 | 314 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
315 |
metacat.login(user, passwd); |
|
295 | 316 |
|
296 | 317 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator") |
297 | 318 |
+ "1"; |
... | ... | |
301 | 322 |
+ "<permission>read</permission>" + "</allow>" + "</acl>"; |
302 | 323 |
debug("xml document: " + content); |
303 | 324 |
assertTrue(handleXMLDocument(content, name, "insert")); |
304 |
} catch (PropertyNotFoundException pnfe) { |
|
305 |
fail("Could not find property: " + pnfe.getMessage()); |
|
325 |
metacat.logout(); |
|
326 |
|
|
327 |
} catch (Exception pnfe) { |
|
328 |
fail(pnfe.getMessage()); |
|
306 | 329 |
} |
307 | 330 |
} |
308 | 331 |
|
... | ... | |
316 | 339 |
try { |
317 | 340 |
String user = PropertyService.getProperty("test.mcUser"); |
318 | 341 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
342 |
metacat.login(user, passwd); |
|
319 | 343 |
|
320 | 344 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator") |
321 | 345 |
+ "1"; |
... | ... | |
326 | 350 |
|
327 | 351 |
debug("xml document: " + content); |
328 | 352 |
assertTrue(!handleXMLDocument(content, name, "insert")); |
329 |
} catch (PropertyNotFoundException pnfe) { |
|
330 |
fail("Could not find property: " + pnfe.getMessage()); |
|
353 |
this.testLogOut(); |
|
354 |
|
|
355 |
} catch (Exception pnfe) { |
|
356 |
fail(pnfe.getMessage()); |
|
331 | 357 |
} |
332 | 358 |
} |
333 | 359 |
|
... | ... | |
338 | 364 |
debug("\nRunning: testReadXMLDocumentXMLFormat test"); |
339 | 365 |
String name = null; |
340 | 366 |
try { |
367 |
String user = PropertyService.getProperty("test.mcUser"); |
|
368 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
|
369 |
metacat.login(user, passwd); |
|
341 | 370 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") |
342 | 371 |
+ serialNumber |
343 | 372 |
+ PropertyService.getProperty("document.accNumSeparator") + "1"; |
344 |
} catch (PropertyNotFoundException pnfe) { |
|
373 |
assertTrue(handleReadAction(name, "xml")); |
|
374 |
metacat.logout(); |
|
375 |
} catch (Exception pnfe) { |
|
345 | 376 |
fail("Could not find property: " + pnfe.getMessage()); |
346 | 377 |
} |
347 |
assertTrue(handleReadAction(name, "xml")); |
|
348 | 378 |
|
349 | 379 |
} |
350 | 380 |
|
... | ... | |
355 | 385 |
debug("\nRunning: testReadXMLDocumentHTMLFormat test"); |
356 | 386 |
String name = null; |
357 | 387 |
try { |
388 |
String user = PropertyService.getProperty("test.mcUser"); |
|
389 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
|
390 |
metacat.login(user, passwd); |
|
358 | 391 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") |
359 | 392 |
+ serialNumber |
360 | 393 |
+ PropertyService.getProperty("document.accNumSeparator") + "1"; |
361 |
} catch (PropertyNotFoundException pnfe) { |
|
362 |
fail("Could not find property: " + pnfe.getMessage()); |
|
394 |
assertTrue(handleReadAction(name, "html")); |
|
395 |
metacat.logout(); |
|
396 |
} catch (Exception pnfe) { |
|
397 |
fail(pnfe.getMessage()); |
|
363 | 398 |
} |
364 |
assertTrue(handleReadAction(name, "html")); |
|
365 | 399 |
|
366 | 400 |
} |
367 | 401 |
|
... | ... | |
372 | 406 |
debug("\nRunning: testReadXMLDocumentZipFormat test"); |
373 | 407 |
String name = null; |
374 | 408 |
try { |
409 |
String user = PropertyService.getProperty("test.mcUser"); |
|
410 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
|
411 |
metacat.login(user, passwd); |
|
375 | 412 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") |
376 | 413 |
+ serialNumber |
377 | 414 |
+ PropertyService.getProperty("document.accNumSeparator") + "1"; |
378 |
} catch (PropertyNotFoundException pnfe) { |
|
379 |
fail("Could not find property: " + pnfe.getMessage()); |
|
415 |
assertTrue(handleReadAction(name, "zip")); |
|
416 |
metacat.logout(); |
|
417 |
} catch (Exception pnfe) { |
|
418 |
fail(pnfe.getMessage()); |
|
380 | 419 |
} |
381 |
assertTrue(handleReadAction(name, "zip")); |
|
382 | 420 |
|
383 | 421 |
} |
384 | 422 |
|
... | ... | |
392 | 430 |
String user = PropertyService.getProperty("test.mcUser"); |
393 | 431 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
394 | 432 |
|
433 |
metacat.login(user, passwd); |
|
434 |
|
|
395 | 435 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") + serialNumber + PropertyService.getProperty("document.accNumSeparator") |
396 | 436 |
+ "2"; |
397 | 437 |
debug("update docid: " + name); |
... | ... | |
402 | 442 |
+ "<permission>read</permission>" + "</allow>" + "</acl>"; |
403 | 443 |
debug("xml document: " + content); |
404 | 444 |
assertTrue(handleXMLDocument(content, name, "update")); |
405 |
} catch (PropertyNotFoundException pnfe) { |
|
406 |
fail("Could not find property: " + pnfe.getMessage()); |
|
445 |
this.testLogOut(); |
|
446 |
} catch (Exception pnfe) { |
|
447 |
fail(pnfe.getMessage()); |
|
407 | 448 |
} |
408 | 449 |
} |
409 | 450 |
|
... | ... | |
412 | 453 |
*/ |
413 | 454 |
public void testDeleteXMLDocument() { |
414 | 455 |
debug("\nRunning: testDeleteXMLDocument test"); |
456 |
|
|
415 | 457 |
String name = null; |
416 | 458 |
try { |
459 |
String user = PropertyService.getProperty("test.mcUser"); |
|
460 |
String passwd = PropertyService.getProperty("test.mcPassword"); |
|
461 |
metacat.login(user, passwd); |
|
462 |
|
|
417 | 463 |
name = "john" + PropertyService.getProperty("document.accNumSeparator") |
418 | 464 |
+ serialNumber |
419 | 465 |
+ PropertyService.getProperty("document.accNumSeparator") + "2"; |
420 |
} catch (PropertyNotFoundException pnfe) { |
|
421 |
fail("Could not find property: " + pnfe.getMessage()); |
|
466 |
debug("delete docid: " + name); |
|
467 |
assertTrue(handleDeleteFile(name)); |
|
468 |
metacat.logout(); |
|
469 |
|
|
470 |
} catch (Exception pnfe) { |
|
471 |
fail(pnfe.getMessage()); |
|
422 | 472 |
} |
423 |
debug("delete docid: " + name); |
|
424 |
assertTrue(handleDeleteFile(name)); |
|
473 |
|
|
425 | 474 |
|
426 | 475 |
} |
427 | 476 |
|
... | ... | |
619 | 668 |
response = sw.toString(); |
620 | 669 |
sw.close(); |
621 | 670 |
} catch (Exception e) { |
671 |
e.printStackTrace(); |
|
622 | 672 |
return null; |
623 | 673 |
} |
624 | 674 |
|
Also available in: Unified diff
handle login/logout when testing using metacat client (recent refactoring to use more standard http client code)