Revision 2288
Added by sgarg about 20 years ago
test/edu/ucsb/nceas/metacattest/InlineDataAccessTest.java | ||
---|---|---|
107 | 107 |
" <detector type=\"EM\"></detector> " + |
108 | 108 |
" </instrument> "; |
109 | 109 |
|
110 |
private String testdoc = testEmlHeader + |
|
111 |
"<dataset scope=\"document\"><title>the title</title>" |
|
112 |
+ testEmlCreatorBlock |
|
113 |
+ "<distribution scope=\"document\" id=\"inlineEntity1\">" |
|
114 |
+ "<inline>" + testEmlInlineBlock1 + "</inline></distribution>" |
|
115 |
+ "<distribution scope=\"document\" id=\"inlineEntity2\">" |
|
116 |
+ "<inline>" + testEmlInlineBlock2 + "</inline></distribution>" |
|
117 |
+ testEmlContactBlock |
|
118 |
+ getAccessBlock(anotheruser, true, false, false, false, true) |
|
119 |
+ "</dataset><additionalMetadata><describes>inlineEntity2" |
|
120 |
+ "</describes></additionalMetadata>" |
|
121 |
+ "<additionalMetadata>" |
|
122 |
+ "<describes>inlineEntity1</describes>" |
|
123 |
+ "<describes>inlineEntity2</describes>" |
|
124 |
+ getAccessBlock(anotheruser, false, false, false, false, true) |
|
125 |
+ "</additionalMetadata></eml:eml>"; |
|
126 |
|
|
127 |
|
|
110 | 128 |
/** |
111 | 129 |
* This function returns an access block based on the params passed |
112 | 130 |
*/ |
... | ... | |
273 | 291 |
suite.addTest(new InlineDataAccessTest("initialize")); |
274 | 292 |
|
275 | 293 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_1")); |
276 |
// suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_2")); |
|
277 |
// suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_3")); |
|
278 |
// suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_4")); |
|
279 |
// suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_5")); |
|
294 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_2")); |
|
295 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_3")); |
|
296 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_4")); |
|
297 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_5")); |
|
298 |
suite.addTest(new InlineDataAccessTest("inlineDataCasesTest_6")); |
|
280 | 299 |
|
281 | 300 |
return suite; |
282 | 301 |
} |
... | ... | |
316 | 335 |
// insert same document again |
317 | 336 |
insertDocid(newdocid + ".1", testdocument, FAILURE, false); |
318 | 337 |
|
319 |
// update by modifying inline data
|
|
338 |
// update by changing inline data
|
|
320 | 339 |
testdocument = getTestEmlDoc("Testing update inline", |
321 | 340 |
testEmlInlineBlock2, |
322 | 341 |
null, null, null, null, |
... | ... | |
325 | 344 |
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true); |
326 | 345 |
|
327 | 346 |
// update by removing inline data |
328 |
// testdocument = getTestEmlDoc("Testing update inline",
|
|
329 |
// null,
|
|
330 |
// null, null, null, null,
|
|
331 |
// null, null, null, null);
|
|
332 |
// updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
|
|
333 |
// readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
|
|
347 |
testdocument = getTestEmlDoc("Testing update inline", |
|
348 |
null, |
|
349 |
null, null, null, null, |
|
350 |
null, null, null, null); |
|
351 |
updateDocid(newdocid + ".3", testdocument, SUCCESS, false); |
|
352 |
readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true); |
|
334 | 353 |
|
335 | 354 |
// update by introducing inline data |
336 |
// testdocument = getTestEmlDoc("Testing update inline",
|
|
337 |
// testEmlInlineBlock1,
|
|
338 |
// null, null, null, null,
|
|
339 |
// null, null, null, null);
|
|
340 |
// updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
|
|
341 |
// readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
|
|
355 |
testdocument = getTestEmlDoc("Testing update inline", |
|
356 |
testEmlInlineBlock1, |
|
357 |
null, null, null, null, |
|
358 |
null, null, null, null); |
|
359 |
updateDocid(newdocid + ".4", testdocument, SUCCESS, false); |
|
360 |
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true); |
|
342 | 361 |
|
343 | 362 |
// read inline data only |
344 |
// readInlineDataWhichEqualsDoc(newdocid + ".1.1",
|
|
345 |
// testEmlInlineBlock1, SUCCESS, false);
|
|
363 |
readInlineDataWhichEqualsDoc(newdocid + ".1.1", |
|
364 |
testEmlInlineBlock1, SUCCESS, false); |
|
346 | 365 |
|
347 | 366 |
// delete the inline data |
348 |
deleteDocid(newdocid + ".2", SUCCESS, false); |
|
349 |
readDocidWhichEqualsDoc(newdocid + ".2", testdocument, FAILURE, false); |
|
367 |
// sleep needed only in case of inline data - jing said that |
|
368 |
// somehow the thread writing data to xml_index takes too much time |
|
369 |
// when used with inline data. hence if delete is requested too soon |
|
370 |
// database gives an error of xml_index records left with FK to |
|
371 |
// xml_document record which is going to be deleted. |
|
372 |
Thread.sleep(10000); |
|
373 |
|
|
374 |
deleteDocid(newdocid + ".4", SUCCESS, false); |
|
375 |
readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, false); |
|
350 | 376 |
m.logout(); |
351 | 377 |
} |
352 | 378 |
catch (MetacatAuthException mae) { |
... | ... | |
616 | 642 |
updateDocid(newdocid + ".3", testdocument, SUCCESS, false); |
617 | 643 |
|
618 | 644 |
// try to delete the document |
645 |
// sleep needed only in case of inline data - jing said that |
|
646 |
// somehow the thread writing data to xml_index takes too much time |
|
647 |
// when used with inline data. hence if delete is requested too soon |
|
648 |
// database gives an error of xml_index records left with FK to |
|
649 |
// xml_document record which is going to be deleted. |
|
650 |
Thread.sleep(10000); |
|
651 |
|
|
619 | 652 |
deleteDocid(newdocid + ".3", SUCCESS, false); |
620 | 653 |
m.logout(); |
621 | 654 |
|
... | ... | |
667 | 700 |
// try to read the document and the inline data |
668 | 701 |
readDocid(newdocid + ".1", FAILURE, true); |
669 | 702 |
// ERRRRRRRRRRRRRRR |
670 |
//readInlineDataWhichEqualsDoc(newdocid + ".1.1",
|
|
671 |
// testEmlInlineBlock1, SUCCESS, false);
|
|
703 |
readInlineDataWhichEqualsDoc(newdocid + ".1.1", |
|
704 |
testEmlInlineBlock1, FAILURE, true);
|
|
672 | 705 |
|
673 | 706 |
// try to update the inline data |
674 | 707 |
testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update", |
... | ... | |
954 | 987 |
} |
955 | 988 |
} |
956 | 989 |
|
990 |
|
|
991 |
/** ********* |
|
992 |
* Checking the following cases: |
|
993 |
* -> when inline data in inserted and updated, do access rules apply |
|
994 |
* to the old document |
|
995 |
*/ |
|
996 |
public void inlineDataCasesTest_6() { |
|
997 |
try { |
|
998 |
|
|
999 |
// insert the document |
|
1000 |
m.login(username, password); |
|
1001 |
testdocument = getTestEmlDoc("InlineDataAccessTest: Doing insert", |
|
1002 |
testEmlInlineBlock1, testEmlInlineBlock2, |
|
1003 |
null, null, |
|
1004 |
getAccessBlock(anotheruser, true, |
|
1005 |
true, true, false, false), |
|
1006 |
getAccessBlock(anotheruser, false, |
|
1007 |
false, false, false, true), |
|
1008 |
getAccessBlock(anotheruser, false, |
|
1009 |
false, false, false, true), |
|
1010 |
null, null); |
|
1011 |
newdocid = generateDocid(); |
|
1012 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
1013 |
|
|
1014 |
m.logout(); |
|
1015 |
|
|
1016 |
// update the document |
|
1017 |
m.login(anotheruser, anotherpassword); |
|
1018 |
testdocument = getTestEmlDoc("InlineDataAccessTest: Doing update", |
|
1019 |
testEmlInlineBlock2, testEmlInlineBlock1, |
|
1020 |
null, null, |
|
1021 |
getAccessBlock(anotheruser, true, |
|
1022 |
true, true, false, false), |
|
1023 |
getAccessBlock(anotheruser, false, |
|
1024 |
false, false, false, true), |
|
1025 |
getAccessBlock(anotheruser, false, |
|
1026 |
false, false, false, true), |
|
1027 |
null, null); |
|
1028 |
|
|
1029 |
|
|
1030 |
updateDocid(newdocid + ".2", testdocument, SUCCESS, false); |
|
1031 |
|
|
1032 |
// try reading the inline document |
|
1033 |
readInlineDataWhichEqualsDoc(newdocid + ".2.1", |
|
1034 |
testEmlInlineBlock1, FAILURE, true); |
|
1035 |
|
|
1036 |
System.out.print("Trying to read " + newdocid + ".1.1"); |
|
1037 |
readInlineDataWhichEqualsDoc(newdocid + ".1.1", |
|
1038 |
testEmlInlineBlock1, FAILURE, true); |
|
1039 |
|
|
1040 |
m.logout(); |
|
1041 |
} |
|
1042 |
catch (MetacatAuthException mae) { |
|
1043 |
fail("Authorization failed:\n" + mae.getMessage()); |
|
1044 |
} |
|
1045 |
catch (MetacatInaccessibleException mie) { |
|
1046 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
1047 |
} |
|
1048 |
catch (Exception e) { |
|
1049 |
fail("General exception:\n" + e.getMessage()); |
|
1050 |
} |
|
1051 |
} |
|
1052 |
|
|
1053 |
|
|
957 | 1054 |
/** |
958 | 1055 |
* Insert a document into metacat. The expected result is passed as result |
959 | 1056 |
*/ |
... | ... | |
1133 | 1230 |
assertTrue(testDoc.equals(doc)); |
1134 | 1231 |
} |
1135 | 1232 |
else { |
1233 |
System.out.println("doc :" + doc); |
|
1234 |
System.out.println("testDoc:" + testDoc); |
|
1136 | 1235 |
assertTrue(doc.indexOf("<error>") != -1); |
1137 | 1236 |
} |
1138 | 1237 |
} |
Also available in: Unified diff
Added another test to check if access is checked when an old version of inline data is read using action=readinlinedata