Revision 4356
Added by daigle over 16 years ago
test/edu/ucsb/nceas/metacattest/NonAsciiCharacterTest.java | ||
---|---|---|
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
private String prefix = "test"; |
75 |
private String newdocid = null; |
|
76 | 75 |
private String testdocument = ""; |
77 | 76 |
|
78 | 77 |
private Metacat m; |
79 | 78 |
|
80 |
private boolean SUCCESS = true; |
|
81 |
private boolean FAILURE = false; |
|
82 |
|
|
83 | 79 |
/** |
84 | 80 |
* These variables are for eml-2.0.1 only. For other eml versions, |
85 | 81 |
* this function might have to modified |
86 | 82 |
*/ |
87 | 83 |
|
88 |
private String testEml_Header = |
|
84 |
private String testEml_201_Header =
|
|
89 | 85 |
"<?xml version=\"1.0\"?><eml:eml" + |
90 | 86 |
" xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.1\"" + |
91 | 87 |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + |
92 | 88 |
" packageId=\"eml.1.1\" system=\"knb\"" + |
93 | 89 |
" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.1 eml.xsd\"" + |
94 | 90 |
" scope=\"system\">"; |
91 |
|
|
92 |
private String testEml_210_Header = |
|
93 |
"<?xml version=\"1.0\"?><eml:eml" + |
|
94 |
" xmlns:eml=\"eml://ecoinformatics.org/eml-2.1.0\"" + |
|
95 |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + |
|
96 |
" packageId=\"eml.1.1\" system=\"knb\"" + |
|
97 |
" xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.1.0 eml.xsd\"" + |
|
98 |
" scope=\"system\">"; |
|
95 | 99 |
|
96 | 100 |
private String testEmlCreatorBlock = |
97 | 101 |
"<creator scope=\"document\"> " + |
... | ... | |
158 | 162 |
* This function is for eml-2.0.1 only. For other eml versions, |
159 | 163 |
* this function might have to modified |
160 | 164 |
*/ |
161 |
private String getTestEmlDoc(String title) { |
|
165 |
private String getTestEmlDoc(String title, String emlVersion) {
|
|
162 | 166 |
|
163 | 167 |
String testDocument = ""; |
164 |
testDocument = testDocument + testEml_Header + |
|
168 |
|
|
169 |
String header; |
|
170 |
if (emlVersion == EML2_0_1) { |
|
171 |
header = testEml_201_Header; |
|
172 |
} else { |
|
173 |
header = testEml_210_Header; |
|
174 |
} |
|
175 |
|
|
176 |
testDocument = testDocument + header + |
|
165 | 177 |
"<dataset scope=\"document\"><title>" + title + "</title>" + |
166 | 178 |
testEmlCreatorBlock; |
167 | 179 |
|
... | ... | |
172 | 184 |
|
173 | 185 |
return testDocument; |
174 | 186 |
} |
187 |
|
|
188 |
/** |
|
189 |
* Returns an xml squery that searches for the doc id in the |
|
190 |
* title of documents. This function is for eml-2.0.1 only. For |
|
191 |
* other eml versions, this function might have to modified. |
|
192 |
*/ |
|
193 |
private String getTestEmlQuery(String docid, String emlVersion) { |
|
175 | 194 |
|
195 |
String docType; |
|
196 |
if (emlVersion.equals(EML2_0_1)) { |
|
197 |
docType = "eml://ecoinformatics.org/eml-2.0.1"; |
|
198 |
} else { |
|
199 |
docType = "eml://ecoinformatics.org/eml-2.1.0"; |
|
200 |
} |
|
201 |
|
|
202 |
String sQuery = ""; |
|
203 |
sQuery = |
|
204 |
"<pathquery version=\"1.0\">" + |
|
205 |
"<meta_file_id>unspecified</meta_file_id>" + |
|
206 |
"<querytitle>unspecified</querytitle>" + |
|
207 |
"<returnfield>dataset/title</returnfield>" + |
|
208 |
"<returndoctype>" + docType + "</returndoctype>" + |
|
209 |
"<querygroup operator=\"UNION\">" + |
|
210 |
"<queryterm casesensitive=\"false\" searchmode=\"contains\">" + |
|
211 |
"<value>" + docid + "</value>" + |
|
212 |
"<pathexpr>dataset/title</pathexpr>" + |
|
213 |
"</queryterm>" + |
|
214 |
"</querygroup>" + |
|
215 |
"</pathquery>"; |
|
216 |
|
|
217 |
return sQuery; |
|
218 |
} |
|
219 |
|
|
176 | 220 |
/** |
177 | 221 |
* Constructor to build the test |
178 | 222 |
* |
... | ... | |
180 | 224 |
*/ |
181 | 225 |
public NonAsciiCharacterTest(String name) { |
182 | 226 |
super(name); |
183 |
newdocid = generateDocid(); |
|
184 | 227 |
} |
185 | 228 |
|
186 | 229 |
/** |
... | ... | |
210 | 253 |
TestSuite suite = new TestSuite(); |
211 | 254 |
suite.addTest(new NonAsciiCharacterTest("initialize")); |
212 | 255 |
// Test basic functions |
213 |
suite.addTest(new NonAsciiCharacterTest("invalidXMLCharactersTest")); |
|
214 |
suite.addTest(new NonAsciiCharacterTest("symbolEncodedFormatTest")); |
|
215 |
suite.addTest(new NonAsciiCharacterTest("quoteTest")); |
|
216 |
suite.addTest(new NonAsciiCharacterTest("numericCharacterReferenceFormatTest")); |
|
217 |
suite.addTest(new NonAsciiCharacterTest("nonLatinUnicodeCharacterTest")); |
|
256 |
suite.addTest(new NonAsciiCharacterTest("invalidXMLCharacters201Test")); |
|
257 |
suite.addTest(new NonAsciiCharacterTest("invalidXMLCharacters210Test")); |
|
258 |
suite.addTest(new NonAsciiCharacterTest("symbolEncodedFormat201Test")); |
|
259 |
suite.addTest(new NonAsciiCharacterTest("symbolEncodedFormat210Test")); |
|
260 |
suite.addTest(new NonAsciiCharacterTest("quote201Test")); |
|
261 |
suite.addTest(new NonAsciiCharacterTest("quote210Test")); |
|
262 |
suite.addTest(new NonAsciiCharacterTest("numericCharacterReferenceFormat201Test")); |
|
263 |
suite.addTest(new NonAsciiCharacterTest("numericCharacterReferenceFormat210Test")); |
|
264 |
suite.addTest(new NonAsciiCharacterTest("nonLatinUnicodeCharacter201Test")); |
|
265 |
suite.addTest(new NonAsciiCharacterTest("nonLatinUnicodeCharacter210Test")); |
|
218 | 266 |
|
219 | 267 |
return suite; |
220 | 268 |
} |
... | ... | |
227 | 275 |
assertTrue(1 == 1); |
228 | 276 |
} |
229 | 277 |
|
230 |
|
|
231 |
/** ********* |
|
232 |
* Test inserting document with > & < |
|
278 |
/** |
|
279 |
* Test inserting an EML 2.0.1 document with > & < |
|
233 | 280 |
* should fail because this means an invalid xml document is being inserted |
234 | 281 |
*/ |
235 |
public void invalidXMLCharactersTest() { |
|
282 |
public void invalidXMLCharacters201Test() { |
|
283 |
debug("\nRunning: invalidXMLCharacters201Test"); |
|
236 | 284 |
try { |
237 |
newdocid = generateDocid(); |
|
285 |
String newdocid = generateDocid();
|
|
238 | 286 |
m.login(username, password); |
239 |
testdocument = getTestEmlDoc("Checking > & <");
|
|
287 |
testdocument = getTestEmlDoc("Checking > & < in doc: " + newdocid, EML2_0_1);
|
|
240 | 288 |
insertDocid(newdocid + ".1", testdocument, FAILURE, true); |
241 | 289 |
m.logout(); |
242 | 290 |
} |
... | ... | |
250 | 298 |
fail("General exception:\n" + e.getMessage()); |
251 | 299 |
} |
252 | 300 |
} |
253 |
|
|
254 |
|
|
255 |
/** ********* |
|
256 |
* Test inserting document with > & < |
|
301 |
|
|
302 |
/** |
|
303 |
* Test inserting an EML 2.1.0 document with > & < |
|
257 | 304 |
* should fail because this means an invalid xml document is being inserted |
258 | 305 |
*/ |
259 |
public void symbolEncodedFormatTest() { |
|
306 |
public void invalidXMLCharacters210Test() { |
|
307 |
debug("\nRunning: invalidXMLCharacters210Test"); |
|
260 | 308 |
try { |
261 |
newdocid = generateDocid(); |
|
309 |
String newdocid = generateDocid();
|
|
262 | 310 |
m.login(username, password); |
263 |
testdocument = getTestEmlDoc("Checking > < " ' &"); |
|
264 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
311 |
testdocument = getTestEmlDoc("Checking > & < in doc: " + newdocid, EML2_1_0); |
|
312 |
insertDocid(newdocid + ".1", testdocument, FAILURE, true); |
|
313 |
m.logout(); |
|
314 |
} |
|
315 |
catch (MetacatAuthException mae) { |
|
316 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
317 |
} |
|
318 |
catch (MetacatInaccessibleException mie) { |
|
319 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
320 |
} |
|
321 |
catch (Exception e) { |
|
322 |
fail("General exception:\n" + e.getMessage()); |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* Test inserting and reading an EML 2.0.1 document with > & < |
|
328 |
* Read should succeed since the same document should be read |
|
329 |
* back from disk that was submitted. Query should succeed as |
|
330 |
* well because the characters in this test are not changed in |
|
331 |
* the database. |
|
332 |
*/ |
|
333 |
public void symbolEncodedFormat201Test() { |
|
334 |
debug("\nRunning: symbolEncodedFormat201Test"); |
|
335 |
try { |
|
336 |
String newdocid = generateDocid(); |
|
337 |
m.login(username, password); |
|
338 |
|
|
339 |
String testTitle = |
|
340 |
"Checking > < " ' & in doc: " + newdocid + ".1"; |
|
341 |
testdocument = getTestEmlDoc(testTitle, EML2_0_1); |
|
342 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
343 |
|
|
344 |
// this tests reading the document back from disk |
|
265 | 345 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false); |
346 |
|
|
347 |
// this tests searching for the document in the database |
|
348 |
Thread.sleep(3000); |
|
349 |
queryDocWhichHasTitle(newdocid + ".1", testTitle, EML2_0_1, SUCCESS); |
|
350 |
|
|
266 | 351 |
m.logout(); |
267 | 352 |
} |
268 | 353 |
catch (MetacatAuthException mae) { |
... | ... | |
275 | 360 |
fail("General exception:\n" + e.getMessage()); |
276 | 361 |
} |
277 | 362 |
} |
363 |
|
|
364 |
/** |
|
365 |
* Test inserting and reading an EML 2.1.0 document with > & < |
|
366 |
* Read should succeed since the same document should be read |
|
367 |
* back from disk that was submitted. Query should succeed as |
|
368 |
* well because the characters in this test are not changed in |
|
369 |
* the database. |
|
370 |
*/ |
|
371 |
public void symbolEncodedFormat210Test() { |
|
372 |
debug("\nRunning: symbolEncodedFormat210Test"); |
|
373 |
try { |
|
374 |
String newdocid = generateDocid(); |
|
375 |
m.login(username, password); |
|
376 |
|
|
377 |
String testTitle = |
|
378 |
"Checking > < " ' & in doc: " + newdocid + ".1"; |
|
379 |
testdocument = getTestEmlDoc(testTitle, EML2_1_0); |
|
380 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
381 |
|
|
382 |
// this tests reading the document back from disk |
|
383 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false); |
|
384 |
|
|
385 |
// this tests searching for the document in the database |
|
386 |
Thread.sleep(3000); |
|
387 |
queryDocWhichHasTitle(newdocid + ".1", testTitle, EML2_1_0, SUCCESS); |
|
388 |
|
|
389 |
m.logout(); |
|
390 |
} |
|
391 |
catch (MetacatAuthException mae) { |
|
392 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
393 |
} |
|
394 |
catch (MetacatInaccessibleException mie) { |
|
395 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
396 |
} |
|
397 |
catch (Exception e) { |
|
398 |
fail("General exception:\n" + e.getMessage()); |
|
399 |
} |
|
400 |
} |
|
278 | 401 |
|
279 |
|
|
280 |
/** ********* |
|
281 |
* Test inserting document with single quote and double quote |
|
282 |
* should fail because this means an invalid xml document is being inserted |
|
402 |
/** |
|
403 |
* Test inserting and reading an EML 2.0.1 document with single quote and double quote. |
|
404 |
* Read should succeed since the same document should be read back from disk |
|
405 |
* that was submitted. Query should succeed because we look for the converted |
|
406 |
* character (' and "). |
|
283 | 407 |
*/ |
284 |
public void quoteTest() { |
|
408 |
public void quote201Test() { |
|
409 |
debug("\nRunning: quote201Test"); |
|
285 | 410 |
try { |
286 |
newdocid = generateDocid(); |
|
411 |
String newdocid = generateDocid();
|
|
287 | 412 |
m.login(username, password); |
288 |
testdocument = getTestEmlDoc("Checking ' ` \""); |
|
413 |
|
|
414 |
String testTitle = "Checking ' ` \" in doc: " + newdocid + ".1"; |
|
415 |
String convertedTestTitle = "Checking ' ` " in doc: " + newdocid + ".1"; |
|
416 |
|
|
417 |
testdocument = getTestEmlDoc(testTitle, EML2_0_1); |
|
289 | 418 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, true); |
290 |
testdocument = getTestEmlDoc("Checking ' ` ""); |
|
419 |
|
|
420 |
// this tests reading the document back from disk |
|
291 | 421 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
422 |
|
|
423 |
// this tests searching for the document in the database |
|
424 |
Thread.sleep(3000); |
|
425 |
queryDocWhichHasTitle(newdocid + ".1", convertedTestTitle, EML2_0_1, SUCCESS); |
|
426 |
|
|
292 | 427 |
m.logout(); |
293 | 428 |
} |
294 | 429 |
catch (MetacatAuthException mae) { |
... | ... | |
301 | 436 |
fail("General exception:\n" + e.getMessage()); |
302 | 437 |
} |
303 | 438 |
} |
439 |
|
|
440 |
/** |
|
441 |
* Test inserting and reading an EML 2.1.0 document with single quote and double quote. |
|
442 |
* Read should succeed since the same document should be read back from disk |
|
443 |
* that was submitted. Query shoud succeed because we look for the converted |
|
444 |
* character (' and "). |
|
445 |
*/ |
|
446 |
public void quote210Test() { |
|
447 |
debug("\nRunning: quote210Test"); |
|
448 |
try { |
|
449 |
String newdocid = generateDocid(); |
|
450 |
m.login(username, password); |
|
451 |
|
|
452 |
String testTitle = "Checking ' ` \" in doc: " + newdocid + ".1"; |
|
453 |
String convertedTestTitle = "Checking ' ` " in doc: " + newdocid + ".1"; |
|
454 |
|
|
455 |
testdocument = getTestEmlDoc(testTitle, EML2_1_0); |
|
456 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, true); |
|
457 |
|
|
458 |
// this tests reading the document back from disk |
|
459 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
|
460 |
|
|
461 |
// this tests searching for the document in the database |
|
462 |
Thread.sleep(3000); |
|
463 |
queryDocWhichHasTitle(newdocid + ".1", convertedTestTitle, EML2_1_0, SUCCESS); |
|
464 |
|
|
465 |
m.logout(); |
|
466 |
} |
|
467 |
catch (MetacatAuthException mae) { |
|
468 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
469 |
} |
|
470 |
catch (MetacatInaccessibleException mie) { |
|
471 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
472 |
} |
|
473 |
catch (Exception e) { |
|
474 |
fail("General exception:\n" + e.getMessage()); |
|
475 |
} |
|
476 |
} |
|
304 | 477 |
|
478 |
/** |
|
479 |
* Test inserting and reading an EML 2.0.1 document with the code representation |
|
480 |
* of a micro sign (µ). Read should succeed since the same document should be |
|
481 |
* read back from disk that was submitted. Query should succeed because we look |
|
482 |
* for the converted character (µ). |
|
483 |
*/ |
|
484 |
public void numericCharacterReferenceFormat201Test() { |
|
485 |
debug("\nRunning: numericCharacterReferenceFormat201Test"); |
|
486 |
try { |
|
487 |
String newdocid = generateDocid(); |
|
488 |
m.login(username, password); |
|
489 |
|
|
490 |
String testTitle = "Checking µ in doc: " + newdocid + ".1"; |
|
491 |
String convertedTestTitle = "Checking µ in doc: " + newdocid + ".1"; |
|
492 |
|
|
493 |
testdocument = getTestEmlDoc(testTitle, EML2_0_1); |
|
494 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, true); |
|
305 | 495 |
|
496 |
// this tests reading the document back from disk |
|
497 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
|
498 |
|
|
499 |
// this tests searching for the document in the database |
|
500 |
Thread.sleep(3000); |
|
501 |
queryDocWhichHasTitle(newdocid + ".1", convertedTestTitle, EML2_0_1, SUCCESS); |
|
502 |
|
|
503 |
m.logout(); |
|
504 |
} |
|
505 |
catch (MetacatAuthException mae) { |
|
506 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
507 |
} |
|
508 |
catch (MetacatInaccessibleException mie) { |
|
509 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
510 |
} |
|
511 |
catch (Exception e) { |
|
512 |
fail("General exception:\n" + e.getMessage()); |
|
513 |
} |
|
514 |
} |
|
306 | 515 |
|
307 |
/** ********* |
|
308 |
* Test inserting document with micro sign |
|
309 |
* should fail because this means an invalid xml document is being inserted |
|
516 |
/** |
|
517 |
* Test inserting and reading an EML 2.1.0 document with the code representation |
|
518 |
* of a micro sign (µ). Read should succeed since the same document should be |
|
519 |
* read back from disk that was submitted. Query should succeed because we look |
|
520 |
* for the converted character (µ). |
|
310 | 521 |
*/ |
311 |
public void numericCharacterReferenceFormatTest() { |
|
522 |
public void numericCharacterReferenceFormat210Test() { |
|
523 |
debug("\nRunning: numericCharacterReferenceFormat210Test"); |
|
312 | 524 |
try { |
313 |
newdocid = generateDocid(); |
|
525 |
String newdocid = generateDocid();
|
|
314 | 526 |
m.login(username, password); |
315 |
testdocument = getTestEmlDoc("Checking µ"); |
|
527 |
|
|
528 |
String testTitle = "Checking µ in doc: " + newdocid + ".1"; |
|
529 |
String convertedTestTitle = "Checking µ in doc: " + newdocid + ".1"; |
|
530 |
|
|
531 |
testdocument = getTestEmlDoc(testTitle, EML2_1_0); |
|
316 | 532 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, true); |
317 |
testdocument = getTestEmlDoc("Checking µ"); |
|
533 |
|
|
534 |
// this tests reading the document back from disk |
|
318 | 535 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
536 |
|
|
537 |
// this tests searching for the document in the database |
|
538 |
Thread.sleep(3000); |
|
539 |
queryDocWhichHasTitle(newdocid + ".1", convertedTestTitle, EML2_1_0, SUCCESS); |
|
540 |
|
|
319 | 541 |
m.logout(); |
320 | 542 |
} |
321 | 543 |
catch (MetacatAuthException mae) { |
... | ... | |
329 | 551 |
} |
330 | 552 |
} |
331 | 553 |
|
332 |
|
|
333 |
/** ********* |
|
334 |
* Test inserting document with characters like µ |
|
335 |
* should fail because this means an invalid xml document is being inserted |
|
554 |
/** |
|
555 |
* Test inserting and reading an EML 2.0.1 document with the micro sign (µ). |
|
556 |
* Read should succeed since the same document should be read back from disk |
|
557 |
* that was submitted. Query should succeed because we look for the same |
|
558 |
* character (µ). |
|
336 | 559 |
*/ |
337 |
public void nonLatinUnicodeCharacterTest() { |
|
560 |
public void nonLatinUnicodeCharacter201Test() { |
|
561 |
debug("\nRunning: nonLatinUnicodeCharacter201Test"); |
|
338 | 562 |
try { |
339 |
newdocid = generateDocid(); |
|
563 |
String newdocid = generateDocid();
|
|
340 | 564 |
m.login(username, password); |
341 |
testdocument = getTestEmlDoc("Checking charcters like µ"); |
|
565 |
|
|
566 |
String testTitle = "Checking characters like µ in doc: " + newdocid + ".1"; |
|
567 |
|
|
568 |
testdocument = getTestEmlDoc(testTitle, EML2_0_1); |
|
342 | 569 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
343 |
//testdocument = getTestEmlDoc("Checking charcters like µ"); |
|
570 |
|
|
571 |
// this tests reading the document back from disk |
|
344 | 572 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
573 |
|
|
574 |
// this tests searching for the document in the database |
|
575 |
Thread.sleep(3000); |
|
576 |
queryDocWhichHasTitle(newdocid + ".1", testTitle, EML2_0_1, SUCCESS); |
|
577 |
|
|
345 | 578 |
m.logout(); |
346 | 579 |
} |
347 | 580 |
catch (MetacatAuthException mae) { |
... | ... | |
354 | 587 |
fail("General exception:\n" + e.getMessage()); |
355 | 588 |
} |
356 | 589 |
} |
590 |
|
|
591 |
/** |
|
592 |
* Test inserting and reading an EML 2.1.0 document with the micro sign (µ). |
|
593 |
* Read should succeed since the same document should be read back from disk |
|
594 |
* that was submitted. Query should succeed because we look for the same |
|
595 |
* character (µ). |
|
596 |
*/ |
|
597 |
public void nonLatinUnicodeCharacter210Test() { |
|
598 |
debug("\nRunning: nonLatinUnicodeCharacter210Test"); |
|
599 |
try { |
|
600 |
String newdocid = generateDocid(); |
|
601 |
m.login(username, password); |
|
602 |
|
|
603 |
String testTitle = "Checking characters like µ in doc: " + newdocid + ".1"; |
|
604 |
|
|
605 |
testdocument = getTestEmlDoc(testTitle, EML2_1_0); |
|
606 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
357 | 607 |
|
608 |
// this tests reading the document back from disk |
|
609 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); |
|
610 |
|
|
611 |
// this tests searching for the document in the database |
|
612 |
Thread.sleep(3000); |
|
613 |
queryDocWhichHasTitle(newdocid + ".1", testTitle, EML2_1_0, SUCCESS); |
|
614 |
|
|
615 |
m.logout(); |
|
616 |
} |
|
617 |
catch (MetacatAuthException mae) { |
|
618 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
619 |
} |
|
620 |
catch (MetacatInaccessibleException mie) { |
|
621 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
622 |
} |
|
623 |
catch (Exception e) { |
|
624 |
fail("General exception:\n" + e.getMessage()); |
|
625 |
} |
|
626 |
} |
|
627 |
|
|
358 | 628 |
/** |
359 | 629 |
* Insert a document into metacat. The expected result is passed as result |
360 | 630 |
*/ |
361 |
|
|
362 | 631 |
private String insertDocid(String docid, String docText, boolean result, |
363 | 632 |
boolean expectMetacatException) { |
364 | 633 |
String response = null; |
... | ... | |
394 | 663 |
/** |
395 | 664 |
* Insert a document into metacat. The expected result is passed as result |
396 | 665 |
*/ |
397 |
|
|
398 | 666 |
private String uploadDocid(String docid, String filePath, boolean result, |
399 | 667 |
boolean expectedKarmaException) { |
400 | 668 |
String response = null; |
... | ... | |
472 | 740 |
} |
473 | 741 |
|
474 | 742 |
/** |
475 |
* Delete a document into metacat. The expected result is passed as result
|
|
743 |
* Delete a document from metacat. The expected result is passed as result
|
|
476 | 744 |
*/ |
477 | 745 |
private void deleteDocid(String docid, boolean result, |
478 | 746 |
boolean expextedKarmaFailure) { |
... | ... | |
540 | 808 |
* Read a document from metacat and check if it is equal to a given string. |
541 | 809 |
* The expected result is passed as result |
542 | 810 |
*/ |
543 |
|
|
544 | 811 |
private void readDocidWhichEqualsDoc(String docid, String testDoc, |
545 | 812 |
boolean result, |
546 |
boolean expextedKarmaFailure) {
|
|
813 |
boolean expectedKarmaFailure) {
|
|
547 | 814 |
try { |
548 | 815 |
Reader r = m.read(docid); |
549 | 816 |
String doc = IOUtil.getAsString(r, true); |
... | ... | |
564 | 831 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
565 | 832 |
} |
566 | 833 |
catch (InsufficientKarmaException ike) { |
567 |
if (!expextedKarmaFailure) {
|
|
834 |
if (!expectedKarmaFailure) {
|
|
568 | 835 |
fail("Insufficient karma:\n" + ike.getMessage()); |
569 | 836 |
} |
570 | 837 |
} |
... | ... | |
576 | 843 |
} |
577 | 844 |
|
578 | 845 |
} |
846 |
|
|
847 |
/** |
|
848 |
* Query a document by looking for it's doc id in the title element. |
|
849 |
* Then check if the testTitle exists in the doc. |
|
850 |
* @param docId the id of the doc to look for |
|
851 |
* @param testTitle the title containing special characters |
|
852 |
* @param result are we expecting SUCCESS or FAILURE |
|
853 |
* @param expextedKarmaFailure |
|
854 |
*/ |
|
855 |
private void queryDocWhichHasTitle(String docId, String testTitle, |
|
856 |
String emlVersion, boolean result) { |
|
857 |
try { |
|
858 |
String sQuery = getTestEmlQuery(docId, emlVersion); |
|
859 |
debug("sQuery: " + sQuery); |
|
860 |
Reader queryReader = new StringReader(sQuery); |
|
861 |
Reader resultReader = m.query(queryReader); |
|
862 |
String queryResult = IOUtil.getAsString(resultReader, true); |
|
863 |
if (result) { |
|
864 |
if (!queryResult.contains(testTitle)) { |
|
865 |
System.out.println("queryResult: " + queryResult); |
|
866 |
System.out.println("does not contain title: " + testTitle); |
|
867 |
} |
|
579 | 868 |
|
869 |
assertTrue(queryResult.contains(testTitle)); |
|
870 |
} |
|
871 |
else { |
|
872 |
assertTrue(queryResult.indexOf("<error>") != -1); |
|
873 |
} |
|
874 |
} |
|
875 |
catch (MetacatInaccessibleException mie) { |
|
876 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
877 |
} |
|
878 |
catch (Exception e) { |
|
879 |
fail("General exception:\n" + e.getMessage()); |
|
880 |
} |
|
881 |
|
|
882 |
} |
|
883 |
|
|
580 | 884 |
/** |
581 | 885 |
* Create a hopefully unique docid for testing insert and update. Does |
582 | 886 |
* not include the 'revision' part of the id. |
Also available in: Unified diff
Increase test cases to include testing read action which reads file from disk and squery which reads from db. Create separate cases for eml 2.0.1 and 2.1.0