Revision 2265
Added by sgarg about 20 years ago
test/edu/ucsb/nceas/metacattest/client/MetacatClientTest.java | ||
---|---|---|
46 | 46 |
import junit.framework.Test; |
47 | 47 |
import junit.framework.TestCase; |
48 | 48 |
import junit.framework.TestSuite; |
49 |
import java.io.FileInputStream; |
|
49 | 50 |
|
50 | 51 |
/** |
51 | 52 |
* A JUnit test for testing Step class processing |
... | ... | |
113 | 114 |
public static Test suite() |
114 | 115 |
{ |
115 | 116 |
TestSuite suite = new TestSuite(); |
116 |
suite.addTest(new MetacatClientTest("initialize")); |
|
117 |
suite.addTest(new MetacatClientTest("invalidLogin")); |
|
118 |
suite.addTest(new MetacatClientTest("logoutAndInvalidInsert")); |
|
119 |
suite.addTest(new MetacatClientTest("login")); |
|
120 |
suite.addTest(new MetacatClientTest("insert")); |
|
121 |
suite.addTest(new MetacatClientTest("upload")); |
|
122 |
suite.addTest(new MetacatClientTest("invalidRead")); |
|
123 |
suite.addTest(new MetacatClientTest("read")); |
|
124 |
suite.addTest(new MetacatClientTest("query")); |
|
125 |
suite.addTest(new MetacatClientTest("invalidUpdate")); |
|
126 |
suite.addTest(new MetacatClientTest("update")); |
|
127 |
suite.addTest(new MetacatClientTest("invalidDelete")); |
|
128 |
suite.addTest(new MetacatClientTest("delete")); |
|
129 |
suite.addTest(new MetacatClientTest("inaccessibleMetacat")); |
|
130 |
suite.addTest(new MetacatClientTest("reuseSession")); |
|
131 |
suite.addTest(new MetacatClientTest("reuseInvalidSession")); |
|
132 |
return suite; |
|
133 |
} |
|
117 |
suite.addTest(new MetacatClientTest("initialize")); |
|
118 |
suite.addTest(new MetacatClientTest("invalidLogin")); |
|
119 |
suite.addTest(new MetacatClientTest("logoutAndInvalidInsert")); |
|
120 |
suite.addTest(new MetacatClientTest("login")); |
|
121 |
suite.addTest(new MetacatClientTest("insert")); |
|
122 |
suite.addTest(new MetacatClientTest("upload")); |
|
123 |
suite.addTest(new MetacatClientTest("upload_stream")); |
|
124 |
suite.addTest(new MetacatClientTest("invalidRead")); |
|
125 |
suite.addTest(new MetacatClientTest("read")); |
|
126 |
suite.addTest(new MetacatClientTest("query")); |
|
127 |
suite.addTest(new MetacatClientTest("invalidUpdate")); |
|
128 |
suite.addTest(new MetacatClientTest("update")); |
|
129 |
suite.addTest(new MetacatClientTest("invalidDelete")); |
|
130 |
suite.addTest(new MetacatClientTest("delete")); |
|
131 |
suite.addTest(new MetacatClientTest("inaccessibleMetacat")); |
|
132 |
suite.addTest(new MetacatClientTest("reuseSession")); |
|
133 |
suite.addTest(new MetacatClientTest("reuseInvalidSession")); |
|
134 |
return suite; |
|
135 |
} |
|
134 | 136 |
|
135 | 137 |
/** |
136 | 138 |
* Run an initial test that always passes to check that the test |
... | ... | |
200 | 202 |
} catch (InsufficientKarmaException ike) { |
201 | 203 |
fail("Insufficient karma:\n" + ike.getMessage()); |
202 | 204 |
} catch (MetacatException me) { |
203 |
fail("Metacat Error:\n" + me.getMessage()); |
|
205 |
if(me.getMessage(). |
|
206 |
indexOf("Permission denied for user public inser") == -1){ |
|
207 |
fail("Metacat Error:\n" + me.getMessage()); |
|
208 |
} |
|
204 | 209 |
} catch (Exception e) { |
205 | 210 |
fail("General exception:\n" + e.getMessage()); |
206 | 211 |
} |
... | ... | |
332 | 337 |
} |
333 | 338 |
|
334 | 339 |
/** |
340 |
* Test the upload() function by passing an InputStream |
|
341 |
*/ |
|
342 |
public void upload_stream() |
|
343 |
{ |
|
344 |
try { |
|
345 |
newdocid = generateDocid(); |
|
346 |
String identifier = newdocid + ".1"; |
|
347 |
m.login(username, password); |
|
348 |
File testFile = new File(onlinetestdatafile); |
|
349 |
String response = m.upload(identifier, "onlineDataFile1", |
|
350 |
new FileInputStream(testFile), |
|
351 |
(int) testFile.length()); |
|
352 |
|
|
353 |
assertTrue(response.indexOf("<success>") != -1); |
|
354 |
assertTrue(response.indexOf(identifier) != -1); |
|
355 |
System.err.println(response); |
|
356 |
|
|
357 |
} catch (MetacatAuthException mae) { |
|
358 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
359 |
} catch (MetacatInaccessibleException mie) { |
|
360 |
mie.printStackTrace(); |
|
361 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
362 |
} catch (InsufficientKarmaException ike) { |
|
363 |
assertTrue(1 == 1); |
|
364 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
365 |
} catch (MetacatException me) { |
|
366 |
fail("Metacat Error:\n" + me.getMessage()); |
|
367 |
} catch (Exception e) { |
|
368 |
fail("General exception:\n" + e.getMessage()); |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
335 | 373 |
* Test the invalidUpdate() function. A user try to update a document |
336 | 374 |
* which it doesn't have permission |
337 | 375 |
*/ |
... | ... | |
536 | 574 |
} catch (InsufficientKarmaException ike) { |
537 | 575 |
fail("Insufficient karma:\n" + ike.getMessage()); |
538 | 576 |
} catch (MetacatException me) { |
539 |
fail("Metacat Error:\n" + me.getMessage()); |
|
577 |
if(me.getMessage(). |
|
578 |
indexOf("Permission denied for user public inser") == -1){ |
|
579 |
fail("Metacat Error:\n" + me.getMessage()); |
|
580 |
} |
|
540 | 581 |
} catch (Exception e) { |
541 | 582 |
fail("General exception:\n" + e.getMessage()); |
542 | 583 |
} |
Also available in: Unified diff
Added a new method to check upload function when a data stream is passed.