Revision 5352
Added by berkley almost 14 years ago
CrudServiceTest.java | ||
---|---|---|
80 | 80 |
public static Test suite() |
81 | 81 |
{ |
82 | 82 |
TestSuite suite = new TestSuite(); |
83 |
/*suite.addTest(new CrudServiceTest("initialize"));
|
|
83 |
suite.addTest(new CrudServiceTest("initialize")); |
|
84 | 84 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
85 | 85 |
suite.addTest(new CrudServiceTest("testCreateAndGet")); |
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata"));*/
|
|
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata")); |
|
87 | 87 |
suite.addTest(new CrudServiceTest("testUpdate")); |
88 | 88 |
//suite.addTest(new CrudServiceTest("")); |
89 | 89 |
//suite.addTest(new CrudServiceTest("")); |
... | ... | |
105 | 105 |
CrudService cs = CrudService.getInstance(); |
106 | 106 |
AuthToken token = getToken(); |
107 | 107 |
//create a doc |
108 |
System.out.println("CST: creating document"); |
|
109 | 108 |
Identifier id = createDoc(token, getTestDoc()); |
110 |
System.out.println("CST: document created. Id: " + id.getValue()); |
|
111 | 109 |
|
112 | 110 |
//get the doc and sysmetadata |
113 |
System.out.println("CST: getting document with id " + id.getValue()); |
|
114 | 111 |
String gotDoc = getDoc(token, id); |
115 |
System.out.println("CST: getting sysmeta for doc with id " + id.getValue()); |
|
116 | 112 |
SystemMetadata sm = getSystemMetadata(token, id); |
117 | 113 |
|
118 | 114 |
//update the doc |
119 | 115 |
gotDoc = gotDoc.replaceAll("XXX", "YYY"); |
120 |
System.out.println("CST: Changed test doc to " + gotDoc); |
|
121 | 116 |
Identifier newid = new Identifier(); |
122 | 117 |
newid.setValue(generateDocumentId()); |
123 |
System.out.println("CST: Generated newid " + newid.getValue()); |
|
124 | 118 |
StringBufferInputStream sbis = new StringBufferInputStream(gotDoc); |
125 | 119 |
SystemMetadata newsm = createSystemMetadata(newid, gotDoc); |
126 |
System.out.println("CST: Created system metadata for new doc...updating newid: " + newid.getValue() + " obsId: " + id.getValue()); |
|
127 | 120 |
Identifier updatedid = cs.update(token, newid, sbis, id, newsm); |
128 |
System.out.println("CST: Called update. Returned id " + updatedid.getValue()); |
|
129 | 121 |
|
130 | 122 |
//get doc - check that it matches update |
131 | 123 |
String newdoc = getDoc(token, newid); |
132 | 124 |
assertTrue(gotDoc.equals(newdoc)); |
133 | 125 |
|
134 | 126 |
//get sysmeta - check that ids and other fields are updated |
135 |
System.out.println("CST: confirming obsoletedBy fields for sm doc with id " + id.getValue()); |
|
136 | 127 |
SystemMetadata newnewsm = getSystemMetadata(token, id); |
137 |
List obsoletedByList = newnewsm.getObsoletedByList(); |
|
138 |
assertTrue(obsoletedByList.size() == 1); |
|
139 |
String obsBy = ((Identifier)obsoletedByList.get(0)).getValue(); |
|
140 |
System.out.println("CST: obsBy: " + obsBy); |
|
141 |
System.out.println("CST: id: " + id.getValue()); |
|
142 |
assertTrue(obsBy.equals(newid.getValue())); |
|
128 |
assertTrue(newnewsm.getObsoletedBy(0).getValue().equals(newid.getValue())); |
|
129 |
|
|
130 |
//get the new sysmeta and make sure the obsoletes field is set |
|
131 |
SystemMetadata newnewnewsm = getSystemMetadata(token, newid); |
|
132 |
assertTrue(newnewnewsm.getObsolete(0).getValue().equals(id.getValue())); |
|
143 | 133 |
} |
144 | 134 |
catch(Exception e) |
145 | 135 |
{ |
... | ... | |
204 | 194 |
AuthToken token = getToken(); |
205 | 195 |
//run create |
206 | 196 |
Identifier id = createDoc(token, getTestDoc()); |
207 |
//run get
|
|
197 |
//compare the docs
|
|
208 | 198 |
String gotDoc = getDoc(token, id); |
209 |
System.out.println("got doc: " + gotDoc); |
|
210 |
//compare the docs |
|
211 | 199 |
assertTrue(gotDoc.trim().equals(getTestDoc().trim())); |
212 | 200 |
|
213 | 201 |
try |
... | ... | |
255 | 243 |
private SystemMetadata getSystemMetadata(AuthToken token, Identifier id) |
256 | 244 |
throws Exception |
257 | 245 |
{ |
258 |
System.out.println("getting system metadata for id: " + id.getValue()); |
|
259 | 246 |
CrudService cs = CrudService.getInstance(); |
260 | 247 |
return cs.getSystemMetadata(token, id); |
261 | 248 |
} |
... | ... | |
266 | 253 |
private String getDoc(AuthToken token, Identifier id) |
267 | 254 |
throws Exception |
268 | 255 |
{ |
269 |
System.out.println("getting doc for id " + id.getValue()); |
|
270 | 256 |
CrudService cs = CrudService.getInstance(); |
271 | 257 |
//try to get the same doc then compare them |
272 | 258 |
InputStream gotDocStream = cs.get(token, id); |
... | ... | |
278 | 264 |
sb.append(new String(b, 0, numread)); |
279 | 265 |
numread = gotDocStream.read(b, 0, 1024); |
280 | 266 |
} |
281 |
System.out.println("returning doc for id " + id.getValue()); |
|
282 | 267 |
return sb.toString(); |
283 | 268 |
} |
284 | 269 |
|
... | ... | |
298 | 283 |
{ |
299 | 284 |
CrudService cs = CrudService.getInstance(); |
300 | 285 |
//login and get a sessionid |
301 |
System.out.println("creating MetacatRestClient with url " + cs.getContextUrl()); |
|
302 | 286 |
MetacatRestClient restClient = new MetacatRestClient(cs.getContextUrl()); |
303 | 287 |
String username = PropertyService.getProperty("test.mcUser"); |
304 | 288 |
String password = PropertyService.getProperty("test.mcPassword"); |
305 |
System.out.println("logging in with username: " + username + " and password " + password + " to context " + cs.getContextUrl()); |
|
306 | 289 |
String response = restClient.login(username, password); |
307 |
//System.out.println("response to login: " + response); |
|
308 | 290 |
String sessionid = restClient.getSessionId(); |
309 | 291 |
SessionService sessionService = SessionService.getInstance(); |
310 | 292 |
sessionService.registerSession(new SessionData(sessionid, username, new String[0], password, "CrudServiceLogin")); |
311 |
System.out.println("sessionid: " + sessionid); |
|
312 | 293 |
AuthToken token = new AuthToken(sessionid); |
313 | 294 |
return token; |
314 | 295 |
} |
... | ... | |
324 | 305 |
id = new Identifier(); |
325 | 306 |
String docid = generateDocumentId(); |
326 | 307 |
id.setValue(docid); |
327 |
System.out.println("creating doc with id " + id.getValue()); |
|
328 | 308 |
|
329 | 309 |
//create the system metadata then run the create method |
330 | 310 |
StringBufferInputStream sbis = new StringBufferInputStream(testDoc); |
331 | 311 |
SystemMetadata sm = createSystemMetadata(id, testDoc); |
332 | 312 |
//create the doc |
333 | 313 |
cs.create(token, id, sbis, sm); |
334 |
System.out.println("document with id " + id.getValue() + " created."); |
|
335 | 314 |
return id; |
336 | 315 |
} |
337 | 316 |
|
... | ... | |
343 | 322 |
{ |
344 | 323 |
SystemMetadata sm = new SystemMetadata(); |
345 | 324 |
//set the id |
346 |
System.out.println("creating system metadata object for document with id " + id.getValue()); |
|
347 | 325 |
sm.setIdentifier(id); |
348 |
System.out.println("sm id is " + id.getValue()); |
|
349 | 326 |
sm.setObjectFormat(ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0")); |
350 |
System.out.println("sm objectformat: " + sm.getObjectFormat()); |
|
351 | 327 |
//create the checksum |
352 | 328 |
String checksumS = checksum(testDoc); |
353 | 329 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5"); |
... | ... | |
355 | 331 |
checksum.setValue(checksumS); |
356 | 332 |
checksum.setAlgorithm(ca); |
357 | 333 |
sm.setChecksum(checksum); |
358 |
System.out.println("sm checksum is " + checksumS); |
|
359 | 334 |
//set the size |
360 | 335 |
sm.setSize(testDoc.getBytes().length); |
361 |
System.out.println("sm size: " + testDoc.getBytes().length); |
|
362 | 336 |
//submitter |
363 | 337 |
Principal p = new Principal(); |
364 | 338 |
p.setValue("joe"); |
Also available in: Unified diff
removed system.outs