Revision 8304
Added by Matt Jones over 10 years ago
MetacatClientTest.java | ||
---|---|---|
113 | 113 |
*/ |
114 | 114 |
public void setUp() |
115 | 115 |
{ |
116 |
FileInputStream fis = null; |
|
116 | 117 |
try { |
117 |
FileInputStream fis = new FileInputStream(testfile);
|
|
118 |
fis = new FileInputStream(testfile); |
|
118 | 119 |
testdocument = IOUtils.toString(fis); |
120 |
fis.close(); |
|
119 | 121 |
} catch (IOException ioe) { |
120 | 122 |
fail("Can't read test data to run the test: " + testfile); |
123 |
} finally { |
|
124 |
IOUtils.closeQuietly(fis); |
|
121 | 125 |
} |
122 | 126 |
|
123 | 127 |
try { |
... | ... | |
390 | 394 |
* Test to get access control part of a document |
391 | 395 |
*/ |
392 | 396 |
public void getAccessControl() { |
393 |
try { |
|
394 |
FileInputStream fis = new FileInputStream(testEMLWithAccess); |
|
395 |
String document = IOUtils.toString(fis); |
|
396 |
String identifier = newdocid + ".1"; |
|
397 |
m.login(username, password); |
|
398 |
String response = m.insert(identifier, |
|
399 |
new StringReader(document), null); |
|
400 |
assertTrue(response.indexOf("<success>") != -1); |
|
401 |
assertTrue(response.indexOf(identifier) != -1); |
|
402 |
response = m.getAccessControl(identifier); |
|
403 |
//System.out.println("reponse is "+reponse); |
|
404 |
assertTrue(response.indexOf("<permission>read</permission>") != -1); |
|
405 |
assertTrue(response.indexOf("<principal>public</principal>") != -1); |
|
406 |
} catch (MetacatAuthException mae) { |
|
407 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
408 |
} catch (MetacatInaccessibleException mie) { |
|
409 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
410 |
} catch (InsufficientKarmaException ike) { |
|
411 |
assertTrue(1 == 1); |
|
412 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
413 |
} catch (MetacatException me) { |
|
414 |
fail("Metacat Error:\n" + me.getMessage()); |
|
415 |
} catch (Exception e) { |
|
416 |
fail("General exception:\n" + e.getMessage()); |
|
397 |
FileInputStream fis = null; |
|
398 |
try { |
|
399 |
fis = new FileInputStream(testEMLWithAccess); |
|
400 |
String document = IOUtils.toString(fis); |
|
401 |
String identifier = newdocid + ".1"; |
|
402 |
m.login(username, password); |
|
403 |
String response = m.insert(identifier, new StringReader(document), null); |
|
404 |
assertTrue(response.indexOf("<success>") != -1); |
|
405 |
assertTrue(response.indexOf(identifier) != -1); |
|
406 |
response = m.getAccessControl(identifier); |
|
407 |
//System.out.println("reponse is "+reponse); |
|
408 |
assertTrue(response.indexOf("<permission>read</permission>") != -1); |
|
409 |
assertTrue(response.indexOf("<principal>public</principal>") != -1); |
|
410 |
fis.close(); |
|
411 |
} catch (MetacatAuthException mae) { |
|
412 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
413 |
} catch (MetacatInaccessibleException mie) { |
|
414 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
415 |
} catch (InsufficientKarmaException ike) { |
|
416 |
assertTrue(1 == 1); |
|
417 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
418 |
} catch (MetacatException me) { |
|
419 |
fail("Metacat Error:\n" + me.getMessage()); |
|
420 |
} catch (Exception e) { |
|
421 |
fail("General exception:\n" + e.getMessage()); |
|
422 |
} finally { |
|
423 |
IOUtils.closeQuietly(fis); |
|
424 |
} |
|
417 | 425 |
} |
418 |
|
|
419 |
} |
|
420 | 426 |
|
421 | 427 |
/** |
422 | 428 |
* Test to get access control part of a document |
Also available in: Unified diff
Reviewed code for all uses of FileInputStream, checking to see if the method should be closing the stream, and if so, closing it in the method as well as in the finally clause to ensure we don't leak file descriptors.