Revision 1789
Added by Matt Jones about 21 years ago
MetacatClientTest.java | ||
---|---|---|
32 | 32 |
import java.io.InputStreamReader; |
33 | 33 |
import java.io.IOException; |
34 | 34 |
import java.io.Reader; |
35 |
import java.io.StringReader; |
|
35 | 36 |
import java.io.StringWriter; |
36 | 37 |
|
37 | 38 |
import junit.framework.Test; |
... | ... | |
50 | 51 |
private String password = "@mcpassword@"; |
51 | 52 |
private String failpass = "uidfnkj43987yfdn"; |
52 | 53 |
private String docid = "jones.204.22"; |
54 |
private String newdocid = "@newdocid@"; |
|
53 | 55 |
private String testfile = "test/jones.204.22.xml"; |
54 | 56 |
private String queryFile = "test/query.xml"; |
55 | 57 |
//private String docid = "Gramling.61.26"; |
... | ... | |
104 | 106 |
suite.addTest(new MetacatClientTest("initialize")); |
105 | 107 |
suite.addTest(new MetacatClientTest("invalidLogin")); |
106 | 108 |
suite.addTest(new MetacatClientTest("login")); |
109 |
suite.addTest(new MetacatClientTest("insert")); |
|
107 | 110 |
suite.addTest(new MetacatClientTest("read")); |
108 | 111 |
suite.addTest(new MetacatClientTest("query")); |
109 | 112 |
return suite; |
... | ... | |
186 | 189 |
fail("General exception:\n" + e.getMessage()); |
187 | 190 |
} |
188 | 191 |
} |
192 |
|
|
193 |
/** |
|
194 |
* Test the insert() function with a known document |
|
195 |
*/ |
|
196 |
public void insert() |
|
197 |
{ |
|
198 |
try { |
|
199 |
m.login(username, password); |
|
200 |
String response = m.insert(newdocid, |
|
201 |
new StringReader(testdocument), null); |
|
202 |
assertTrue(response.indexOf("<success>") != -1); |
|
203 |
assertTrue(response.indexOf(newdocid) != -1); |
|
204 |
|
|
205 |
} catch (MetacatAuthException mae) { |
|
206 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
207 |
} catch (MetacatInaccessibleException mie) { |
|
208 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
209 |
} catch (InsufficientKarmaException ike) { |
|
210 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
211 |
} catch (MetacatException me) { |
|
212 |
fail("Metacat Error:\n" + me.getMessage()); |
|
213 |
} catch (Exception e) { |
|
214 |
fail("General exception:\n" + e.getMessage()); |
|
215 |
} |
|
216 |
} |
|
189 | 217 |
} |
Also available in: Unified diff
Implemented the "insert()" method and wrote a test to test it. The new test
depends on the property "newdocid" be set to something unique in the build.xml
file so that the insert will work properly. Probably need to fix this to be
some kind of autoincrement counter or random number so that it can be run
several times in succession. Right now, if you run the test without resetting
the newdocid property (and touch the test file), it will fail on the second
and subsequent passes.