Revision 1795
Added by Matt Jones over 20 years ago
MetacatClientTest.java | ||
---|---|---|
52 | 52 |
public class MetacatClientTest extends TestCase |
53 | 53 |
{ |
54 | 54 |
private String metacatUrl = |
55 |
"http://dev.nceas.ucsb.edu/tao/servlet/metacat"; |
|
56 |
//"http://dev.nceas.ucsb.edu/tao/servlet/metacat";
|
|
55 |
"http://dev.nceas.ucsb.edu:8091/tao/servlet/metacat";
|
|
56 |
//"http://knb.ecoinformatics.org/knb/servlet/metacat";
|
|
57 | 57 |
private String username = "@mcuser@"; |
58 | 58 |
private String password = "@mcpassword@"; |
59 | 59 |
private String failpass = "uidfnkj43987yfdn"; |
60 |
private String docid = "jones.204.22"; |
|
61 | 60 |
private String prefix = "test"; |
62 | 61 |
private String newdocid = null; |
63 | 62 |
private String testfile = "test/jones.204.22.xml"; |
64 | 63 |
private String queryFile = "test/query.xml"; |
65 |
//private String docid = "Gramling.61.26"; |
|
66 | 64 |
private String testdocument = ""; |
67 | 65 |
|
68 | 66 |
private Metacat m; |
... | ... | |
116 | 114 |
suite.addTest(new MetacatClientTest("insert")); |
117 | 115 |
suite.addTest(new MetacatClientTest("read")); |
118 | 116 |
suite.addTest(new MetacatClientTest("query")); |
117 |
suite.addTest(new MetacatClientTest("update")); |
|
118 |
suite.addTest(new MetacatClientTest("delete")); |
|
119 | 119 |
return suite; |
120 | 120 |
} |
121 | 121 |
|
... | ... | |
206 | 206 |
m.login(username, password); |
207 | 207 |
String response = m.insert(identifier, |
208 | 208 |
new StringReader(testdocument), null); |
209 |
System.err.println( |
|
210 |
DateFormat.getDateTimeInstance().format(new Date())); |
|
211 |
//Thread.sleep(20000); |
|
212 |
System.err.println( |
|
213 |
DateFormat.getDateTimeInstance().format(new Date())); |
|
214 | 209 |
assertTrue(response.indexOf("<success>") != -1); |
215 | 210 |
assertTrue(response.indexOf(identifier) != -1); |
216 | 211 |
System.err.println(response); |
... | ... | |
229 | 224 |
} |
230 | 225 |
|
231 | 226 |
/** |
227 |
* Test the update() function with a known document |
|
228 |
*/ |
|
229 |
public void update() |
|
230 |
{ |
|
231 |
try { |
|
232 |
String identifier = newdocid + ".2"; |
|
233 |
m.login(username, password); |
|
234 |
String response = m.update(identifier, |
|
235 |
new StringReader(testdocument), null); |
|
236 |
assertTrue(response.indexOf("<success>") != -1); |
|
237 |
assertTrue(response.indexOf(identifier) != -1); |
|
238 |
System.err.println(response); |
|
239 |
|
|
240 |
} catch (MetacatAuthException mae) { |
|
241 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
242 |
} catch (MetacatInaccessibleException mie) { |
|
243 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
244 |
} catch (InsufficientKarmaException ike) { |
|
245 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
246 |
} catch (MetacatException me) { |
|
247 |
fail("Metacat Error:\n" + me.getMessage()); |
|
248 |
} catch (Exception e) { |
|
249 |
fail("General exception:\n" + e.getMessage()); |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Test the delete() function with a known document |
|
255 |
*/ |
|
256 |
public void delete() |
|
257 |
{ |
|
258 |
try { |
|
259 |
String identifier = newdocid + ".2"; |
|
260 |
m.login(username, password); |
|
261 |
String response = m.delete(identifier); |
|
262 |
assertTrue(response.indexOf("<success>") != -1); |
|
263 |
System.err.println(response); |
|
264 |
|
|
265 |
} catch (MetacatAuthException mae) { |
|
266 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
267 |
} catch (MetacatInaccessibleException mie) { |
|
268 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
269 |
} catch (InsufficientKarmaException ike) { |
|
270 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
271 |
} catch (MetacatException me) { |
|
272 |
fail("Metacat Error:\n" + me.getMessage()); |
|
273 |
} catch (Exception e) { |
|
274 |
fail("General exception:\n" + e.getMessage()); |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
232 | 279 |
* Create a hopefully unique docid for testing insert and update. Does |
233 | 280 |
* not include the 'revision' part of the id. |
234 | 281 |
* |
Also available in: Unified diff
Implemented the update and delete methods in the interface, along with tests.