126 |
126 |
suite.addTest(new MetacatClientTest("update"));
|
127 |
127 |
suite.addTest(new MetacatClientTest("invalidDelete"));
|
128 |
128 |
suite.addTest(new MetacatClientTest("delete"));
|
129 |
|
suite.addTest(new MetacatClientTest("inaccessiblemetacat"));
|
|
129 |
suite.addTest(new MetacatClientTest("inaccessibleMetacat"));
|
|
130 |
suite.addTest(new MetacatClientTest("reuseSession"));
|
130 |
131 |
return suite;
|
131 |
132 |
}
|
132 |
133 |
|
... | ... | |
202 |
203 |
} catch (Exception e) {
|
203 |
204 |
fail("General exception:\n" + e.getMessage());
|
204 |
205 |
}
|
205 |
|
|
206 |
206 |
}
|
207 |
207 |
|
208 |
208 |
/**
|
... | ... | |
403 |
403 |
* inaccessible url. Then try to login it. If get a MetacatInaccessible
|
404 |
404 |
* exception, this is right.
|
405 |
405 |
*/
|
406 |
|
public void inaccessiblemetacat()
|
|
406 |
public void inaccessibleMetacat()
|
407 |
407 |
{
|
408 |
408 |
Metacat mWrong = null;
|
409 |
409 |
try {
|
... | ... | |
422 |
422 |
}
|
423 |
423 |
|
424 |
424 |
/**
|
|
425 |
* Try to perform an action that requires a session to be valid without
|
|
426 |
* having logged in first by setting the sessionId from a previous
|
|
427 |
* session. Then insert a document.
|
|
428 |
*/
|
|
429 |
public void reuseSession()
|
|
430 |
{
|
|
431 |
String oldSessionId = "";
|
|
432 |
try {
|
|
433 |
Metacat mtemp = MetacatFactory.createMetacatConnection(metacatUrl);
|
|
434 |
String response = mtemp.login(username, password);
|
|
435 |
oldSessionId = mtemp.getSessionId();
|
|
436 |
} catch (MetacatAuthException mae) {
|
|
437 |
fail("Authorization failed:\n" + mae.getMessage());
|
|
438 |
} catch (MetacatInaccessibleException mie) {
|
|
439 |
System.err.println("Metacat is: " + metacatUrl);
|
|
440 |
fail("Metacat connection failed." + mie.getMessage());
|
|
441 |
}
|
|
442 |
|
|
443 |
try {
|
|
444 |
String identifier = generateDocid() + ".1";
|
|
445 |
Metacat m2 = null;
|
|
446 |
try {
|
|
447 |
m2 = MetacatFactory.createMetacatConnection(metacatUrl);
|
|
448 |
} catch (MetacatInaccessibleException mie) {
|
|
449 |
System.err.println("Metacat is: " + metacatUrl);
|
|
450 |
fail("Metacat connection failed." + mie.getMessage());
|
|
451 |
}
|
|
452 |
m2.setSessionId(oldSessionId);
|
|
453 |
String response = m2.insert(identifier,
|
|
454 |
new StringReader(testdocument), null);
|
|
455 |
System.err.println("Reuse Insert response: " + response);
|
|
456 |
assertTrue(response.indexOf("<success>") != -1);
|
|
457 |
} catch (MetacatInaccessibleException mie) {
|
|
458 |
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
|
459 |
} catch (InsufficientKarmaException ike) {
|
|
460 |
fail("Insufficient karma:\n" + ike.getMessage());
|
|
461 |
} catch (MetacatException me) {
|
|
462 |
fail("Metacat Error:\n" + me.getMessage());
|
|
463 |
} catch (Exception e) {
|
|
464 |
fail("General exception:\n" + e.getMessage());
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
/**
|
425 |
469 |
* Create a hopefully unique docid for testing insert and update. Does
|
426 |
470 |
* not include the 'revision' part of the id.
|
427 |
471 |
*
|
New versions of the Metacat client API that allow access to the sessionId
so that a session can be reused over several different instances.