Revision 6046
Added by rnahf over 13 years ago
test/edu/ucsb/nceas/metacattest/OnlineDataAccessTest.java | ||
---|---|---|
411 | 411 |
public static Test suite() { |
412 | 412 |
TestSuite suite = new TestSuite(); |
413 | 413 |
suite.addTest(new OnlineDataAccessTest("initialize")); |
414 |
|
|
415 | 414 |
suite.addTest(new OnlineDataAccessTest("onlineData201CasesTest_1")); |
416 | 415 |
suite.addTest(new OnlineDataAccessTest("onlineData210CasesTest_1")); |
417 | 416 |
suite.addTest(new OnlineDataAccessTest("onlineData201CasesTest_2")); |
... | ... | |
423 | 422 |
suite.addTest(new OnlineDataAccessTest("onlineData201CasesTest_5")); |
424 | 423 |
suite.addTest(new OnlineDataAccessTest("onlineData201CasesTest_6")); |
425 | 424 |
suite.addTest(new OnlineDataAccessTest("onlineData210CasesTest_6")); |
426 |
|
|
427 | 425 |
return suite; |
428 | 426 |
} |
429 | 427 |
|
... | ... | |
450 | 448 |
*/ |
451 | 449 |
public void onlineData201CasesTest_1() { |
452 | 450 |
try { |
453 |
debug("\nRunning: onlineData201CasesTest_1"); |
|
451 |
debug("\nRunning: onlineData201CasesTest_1"); |
|
452 |
|
|
453 |
// upload online data |
|
454 |
onlineDocid = generateDocid(); |
|
455 |
m.login(username, password); |
|
456 |
debug("\nUpload online data with id: "+ onlineDocid + ".1"); |
|
457 |
uploadDocid(onlineDocid + ".1", |
|
458 |
onlinetestdatafile1, SUCCESS, false); |
|
454 | 459 |
|
455 |
// upload online data |
|
456 |
onlineDocid = generateDocid(); |
|
457 |
m.login(username, password); |
|
458 |
uploadDocid(onlineDocid + ".1", |
|
459 |
onlinetestdatafile1, SUCCESS, false); |
|
460 |
// try to read the data |
|
461 |
readDocid(onlineDocid + ".1", SUCCESS, false); |
|
460 | 462 |
|
461 |
// try to read the data |
|
462 |
readDocid(onlineDocid + ".1", SUCCESS, false); |
|
463 |
|
|
464 |
// try to upload another data with same id |
|
465 |
uploadDocid(onlineDocid + ".1", |
|
466 |
onlinetestdatafile2, FAILURE, false); |
|
463 |
// try to upload another data with same id |
|
464 |
debug("\nUpload of (different) online data with same id: "+ onlineDocid + ".1"); |
|
465 |
uploadDocid(onlineDocid + ".1", |
|
466 |
onlinetestdatafile2, FAILURE, false); |
|
467 | 467 |
|
468 |
// try to upload another data with updated id |
|
469 |
uploadDocid(onlineDocid + ".2", |
|
470 |
onlinetestdatafile2, SUCCESS, false); |
|
468 |
// try to upload another data with updated id |
|
469 |
debug("\nUpload of data with updated id: "+ onlineDocid + ".2"); |
|
471 | 470 |
|
472 |
// try to set the permissions for the uploaded document |
|
473 |
// the docid given is for the online document |
|
474 |
testdocument = get201TestEmlDoc("OnlineDataAccessTest: Doing insert", |
|
475 |
null, null, |
|
476 |
"ecogrid://knb/" + onlineDocid + ".2", |
|
477 |
null, getAccessBlock(anotheruser, true, |
|
478 |
true, false, false, false), |
|
479 |
null, null, null, null); |
|
480 |
newdocid = generateDocid(); |
|
481 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
482 |
m.logout(); |
|
471 |
uploadDocid(onlineDocid + ".2", |
|
472 |
onlinetestdatafile2, SUCCESS, false); |
|
483 | 473 |
|
484 |
// check if the permissions were set properly |
|
485 |
m.login(anotheruser, anotherpassword); |
|
486 |
readDocid(onlineDocid + ".1", SUCCESS, false); |
|
487 |
readDocid(onlineDocid + ".2", SUCCESS, false); |
|
488 |
m.logout(); |
|
474 |
// try to set the permissions for the uploaded document |
|
475 |
// the docid given is for the online document |
|
476 |
testdocument = get201TestEmlDoc("OnlineDataAccessTest: Doing insert", |
|
477 |
null, null, |
|
478 |
"ecogrid://knb/" + onlineDocid + ".2", |
|
479 |
null, getAccessBlock(anotheruser, true, |
|
480 |
true, false, false, false), |
|
481 |
null, null, null, null); |
|
482 |
newdocid = generateDocid(); |
|
483 |
debug("\nInsert of document with id: "+ newdocid + ".1"); |
|
484 |
insertDocid(newdocid + ".1", testdocument, SUCCESS, false); |
|
485 |
m.logout(); |
|
489 | 486 |
|
490 |
m.login(username, password); |
|
487 |
// check if the permissions were set properly |
|
488 |
m.login(anotheruser, anotherpassword); |
|
489 |
readDocid(onlineDocid + ".1", SUCCESS, false); |
|
490 |
readDocid(onlineDocid + ".2", SUCCESS, false); |
|
491 |
m.logout(); |
|
491 | 492 |
|
492 |
// delete the document - able to delete .1 |
|
493 |
// but not able to delete .2 as no rules |
|
494 |
// written to access table when a document |
|
495 |
// is 'uploaded' |
|
496 |
deleteDocid(onlineDocid + ".1", SUCCESS, false); |
|
497 |
deleteDocid(onlineDocid + ".2", FAILURE, true); |
|
493 |
m.login(username, password); |
|
498 | 494 |
|
499 |
// try to read the documents now |
|
500 |
readDocid(onlineDocid + ".1", FAILURE, true); |
|
501 |
readDocid(onlineDocid + ".2", FAILURE, true); |
|
495 |
// delete the document - able to delete .1 |
|
496 |
// but not able to delete .2 as no rules |
|
497 |
// written to access table when a document |
|
498 |
// is 'uploaded' |
|
499 |
debug("\nDeleting .1 and .2 version of document with ids: "+ onlineDocid); |
|
500 |
deleteDocid(onlineDocid + ".1", SUCCESS, false); |
|
501 |
deleteDocid(onlineDocid + ".2", FAILURE, true); |
|
502 | 502 |
|
503 |
m.logout(); |
|
503 |
// try to read the documents now |
|
504 |
readDocid(onlineDocid + ".1", FAILURE, true); |
|
505 |
readDocid(onlineDocid + ".2", FAILURE, true); |
|
504 | 506 |
|
507 |
m.logout(); |
|
508 |
|
|
505 | 509 |
} |
506 | 510 |
catch (MetacatAuthException mae) { |
507 |
fail("Authorization failed:\n" + mae.getMessage());
|
|
511 |
fail("Authorization failed (testLocation:\n" + mae.getMessage());
|
|
508 | 512 |
} |
509 | 513 |
catch (MetacatInaccessibleException mie) { |
510 |
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
|
514 |
fail("Metacat Inaccessible:\n" + mie.getMessage());
|
|
511 | 515 |
} |
512 | 516 |
catch (Exception e) { |
513 |
fail("General exception:\n" + e.getMessage());
|
|
517 |
fail("General exception:\n" + e.getMessage());
|
|
514 | 518 |
} |
515 | 519 |
} |
516 | 520 |
|
... | ... | |
1854 | 1858 |
|
1855 | 1859 |
private String insertDocid(String docid, String docText, boolean result, |
1856 | 1860 |
boolean expectKarmaException) { |
1857 |
String response = null; |
|
1861 |
System.out.println("docText being inserted:\n" + docText + "\n"); |
|
1862 |
String response = null; |
|
1858 | 1863 |
try { |
1859 | 1864 |
response = m.insert(docid, |
1860 | 1865 |
new StringReader(testdocument), null); |
... | ... | |
1868 | 1873 |
System.err.println(response); |
1869 | 1874 |
} |
1870 | 1875 |
catch (MetacatInaccessibleException mie) { |
1871 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
1876 |
fail("Metacat Inaccessible (in insertDocid):\n" + mie.getMessage());
|
|
1872 | 1877 |
} |
1873 | 1878 |
catch (InsufficientKarmaException ike) { |
1874 | 1879 |
if (!expectKarmaException) { |
1875 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
1880 |
fail("Insufficient karma (in insertDocid):\n" + ike.getMessage());
|
|
1876 | 1881 |
} |
1877 | 1882 |
} |
1878 | 1883 |
catch (MetacatException me) { |
1879 | 1884 |
if (result) { |
1880 |
fail("Metacat Error:\n" + me.getMessage()); |
|
1885 |
fail("Metacat Error (in insertDocid):\n" + me.getMessage());
|
|
1881 | 1886 |
} |
1882 | 1887 |
else { |
1883 |
System.err.println("Metacat Error: " + me.getMessage());
|
|
1888 |
System.err.println("Expected Metacat Error (in insertDocid): " + me.getMessage());
|
|
1884 | 1889 |
} |
1885 | 1890 |
} |
1886 | 1891 |
catch (Exception e) { |
1887 |
fail("General exception:\n" + e.getMessage()); |
|
1892 |
fail("General exception (in insertDocid):\n" + e.getMessage());
|
|
1888 | 1893 |
} |
1889 | 1894 |
return response; |
1890 | 1895 |
} |
... | ... | |
1908 | 1913 |
System.err.println("response from metacat: " + response); |
1909 | 1914 |
} |
1910 | 1915 |
catch (MetacatInaccessibleException mie) { |
1911 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
1916 |
fail("Metacat Inaccessible (in uploadDocid):\n" + mie.getMessage());
|
|
1912 | 1917 |
} |
1913 | 1918 |
catch (InsufficientKarmaException ike) { |
1914 | 1919 |
if (!expectedKarmaException) { |
1915 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
1920 |
fail("Insufficient karma (in uploadDocid):\n" + ike.getMessage());
|
|
1916 | 1921 |
} |
1917 | 1922 |
} |
1918 | 1923 |
catch (MetacatException me) { |
1919 | 1924 |
if (result) { |
1920 |
fail("Metacat Error:\n" + me.getMessage()); |
|
1925 |
fail("Metacat Error (in uploadDocid):\n" + me.getMessage());
|
|
1921 | 1926 |
} |
1922 | 1927 |
else { |
1923 |
System.err.println("Metacat Error: " + me.getMessage());
|
|
1928 |
System.err.println("Expected Metacat Error (in uploadDocid): " + me.getMessage());
|
|
1924 | 1929 |
} |
1925 | 1930 |
} |
1926 | 1931 |
catch (Exception e) { |
1927 |
fail("General exception:\n" + e.getMessage()); |
|
1932 |
fail("General exception (in uploadDocid):\n" + e.getMessage());
|
|
1928 | 1933 |
} |
1929 | 1934 |
return response; |
1930 | 1935 |
} |
... | ... | |
1949 | 1954 |
System.err.println(response); |
1950 | 1955 |
} |
1951 | 1956 |
catch (MetacatInaccessibleException mie) { |
1952 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
1957 |
fail("Metacat Inaccessible (in updateDocid):\n" + mie.getMessage());
|
|
1953 | 1958 |
} |
1954 | 1959 |
catch (InsufficientKarmaException ike) { |
1955 | 1960 |
if (!expectedKarmaFailure) { |
1956 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
1961 |
fail("Insufficient karma (in updateDocid):\n" + ike.getMessage());
|
|
1957 | 1962 |
} |
1958 | 1963 |
} |
1959 | 1964 |
catch (MetacatException me) { |
... | ... | |
1961 | 1966 |
(me.getMessage().indexOf( |
1962 | 1967 |
"User tried to update an access module when they don't have \"ALL\" permission") != |
1963 | 1968 |
-1))) { |
1964 |
fail("Metacat Error:\n" + me.getMessage()); |
|
1969 |
fail("Metacat Error (in updateDocid):\n" + me.getMessage());
|
|
1965 | 1970 |
} |
1966 | 1971 |
} |
1967 | 1972 |
catch (Exception e) { |
1968 |
fail("General exception:\n" + e.getMessage()); |
|
1973 |
fail("General exception (in updateDocid):\n" + e.getMessage());
|
|
1969 | 1974 |
} |
1970 | 1975 |
|
1971 | 1976 |
return response; |
... | ... | |
1991 | 1996 |
} |
1992 | 1997 |
catch (InsufficientKarmaException ike) { |
1993 | 1998 |
if (!expectedKarmaFailure) { |
1994 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
1999 |
fail("Insufficient karma (in deleteDocid):\n" + ike.getMessage());
|
|
1995 | 2000 |
} |
1996 | 2001 |
|
1997 | 2002 |
} |
1998 | 2003 |
catch (MetacatException me) { |
1999 | 2004 |
if (result) { |
2000 |
fail("Metacat Error:\n" + me.getMessage()); |
|
2005 |
fail("Metacat Error (in deleteDocid):\n" + me.getMessage());
|
|
2001 | 2006 |
} |
2002 | 2007 |
else { |
2003 |
System.err.println("Metacat Error:\n" + me.getMessage());
|
|
2008 |
System.err.println("Expected Metacat Error (in deleteDocid):\n" + me.getMessage());
|
|
2004 | 2009 |
} |
2005 | 2010 |
} |
2006 | 2011 |
catch (Exception e) { |
2007 |
fail("General exception:\n" + e.getMessage()); |
|
2012 |
fail("General exception (in deleteDocid):\n" + e.getMessage());
|
|
2008 | 2013 |
} |
2009 | 2014 |
} |
2010 | 2015 |
|
... | ... | |
2023 | 2028 |
// System.err.println(response); |
2024 | 2029 |
} |
2025 | 2030 |
catch (MetacatInaccessibleException mie) { |
2026 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
2031 |
fail("Metacat Inaccessible (in readDocid):\n" + mie.getMessage());
|
|
2027 | 2032 |
} |
2028 | 2033 |
catch (InsufficientKarmaException ike) { |
2029 | 2034 |
if (!expextedKarmaFailure) { |
2030 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
2035 |
fail("Insufficient karma (in readDocid):\n" + ike.getMessage());
|
|
2031 | 2036 |
} |
2032 | 2037 |
} |
2033 | 2038 |
catch (MetacatException me) { |
2034 | 2039 |
if (result) { |
2035 |
fail("Metacat Error:\n" + me.getMessage()); |
|
2040 |
fail("Metacat Error (in readDocid):\n" + me.getMessage());
|
|
2036 | 2041 |
} |
2037 | 2042 |
else { |
2038 |
System.err.println("Metacat Error:\n" + me.getMessage());
|
|
2043 |
System.err.println("Expected Metacat Error (in readDocid):\n" + me.getMessage());
|
|
2039 | 2044 |
} |
2040 | 2045 |
} |
2041 | 2046 |
catch (Exception e) { |
2042 |
fail("General exception:\n" + e.getMessage()); |
|
2047 |
fail("General exception (in readDocid):\n" + e.getMessage());
|
|
2043 | 2048 |
} |
2044 | 2049 |
} |
2045 | 2050 |
|
... | ... | |
2068 | 2073 |
} |
2069 | 2074 |
} |
2070 | 2075 |
catch (MetacatInaccessibleException mie) { |
2071 |
fail("Metacat Inaccessible:\n" + mie.getMessage()); |
|
2076 |
fail("Metacat Inaccessible (in readDocidWhichEquals...):\n" + mie.getMessage());
|
|
2072 | 2077 |
} |
2073 | 2078 |
catch (InsufficientKarmaException ike) { |
2074 | 2079 |
if (!expextedKarmaFailure) { |
2075 |
fail("Insufficient karma:\n" + ike.getMessage()); |
|
2080 |
fail("Insufficient karma (in readDocidWhichEquals...):\n" + ike.getMessage());
|
|
2076 | 2081 |
} |
2077 | 2082 |
} |
2078 | 2083 |
catch (MetacatException me) { |
2079 |
fail("Metacat Error:\n" + me.getMessage()); |
|
2084 |
fail("Metacat Error (in readDocidWhichEquals...):\n" + me.getMessage());
|
|
2080 | 2085 |
} |
2081 | 2086 |
catch (Exception e) { |
2082 |
fail("General exception:\n" + e.getMessage()); |
|
2087 |
fail("General exception (in readDocidWhichEquals...):\n" + e.getMessage());
|
|
2083 | 2088 |
} |
2084 | 2089 |
|
2085 | 2090 |
} |
Also available in: Unified diff
put in more explanatory exception methods in the private helper functions that throw exceptions, and some debug statements in the onlineData201CasesTest_1 test.