Project

General

Profile

« Previous | Next » 

Revision 2260

Added by sgarg about 20 years ago

Made changes in AccessControl and Online Data Access tests.

View differences:

test/onlineDataFile1
1
DATe
1
DATE
test/edu/ucsb/nceas/metacattest/OnlineDataAccessTest.java
46 46
import java.io.File;
47 47

  
48 48
/**
49
 * A JUnit test for testing Access Control in Metacat
49
 * A JUnit test for testing Access Control for online data in Metacat
50 50
 */
51 51
public class OnlineDataAccessTest
52 52
    extends TestCase {
......
332 332

  
333 333
            // try to set the permissions for the uploaded document
334 334
            // the docid given is for the online document
335
            testdocument = getTestEmlDoc("Testing insert", null, null,
335
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
336
                                         null, null,
336 337
                                         "ecogrid://knb/" + onlineDocid + ".1",
337 338
                                         null, getAccessBlock(anotheruser, true,
338 339
                true, false, false, false),
......
406 407
                        onlinetestdatafile2, FAILURE, false);
407 408

  
408 409
            // try to upload another document with updated id
409
            // ERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
410
            //uploadDocid(onlineDocid + ".3",
411
            //            onlinetestdatafile2, FAILURE, false);
410
            uploadDocid(onlineDocid + ".3",
411
                        onlinetestdatafile2, FAILURE, true);
412 412

  
413 413

  
414 414
            // try to set the permissions for the uploaded document
415 415
            // the docid given is for the online document
416
            testdocument = getTestEmlDoc("Testing insert", null, null,
416
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
417
                                         null, null,
417 418
                                         "ecogrid://knb/" + onlineDocid + ".1",
418 419
                                         "ecogrid://knb/" + onlineDocid + ".2",
419 420
                                         getAccessBlock(anotheruser, true,
420
                true, false, false, false),
421
                                         true, false, false, false),
421 422
                                         null, null, null, null);
422 423
            newdocid = generateDocid();
423 424
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
......
425 426
            // delete the document - should not be able to delete .1
426 427
            // but should be able to delete .2
427 428
            deleteDocid(onlineDocid + ".1", FAILURE, false);
428
            deleteDocid(onlineDocid + ".2", FAILURE, false);
429
            deleteDocid(onlineDocid + ".2", FAILURE, true);
429 430

  
430 431
            m.logout();
431 432

  
......
466 467
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
467 468

  
468 469
            // upload a document which gives read access to the online document
469
            testdocument = getTestEmlDoc("Another insert", null, null,
470
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
471
                                         null, null,
470 472
                                         "ecogrid://knb/" + onlineDocid + ".1",
471 473
                                         null, getAccessBlock(anotheruser, true,
472 474
                true, false, false, false),
......
482 484
            readDocid(onlineDocid + ".1", SUCCESS, false);
483 485

  
484 486
            // try to upload another data with updated id
485
            // ERRRRRRRRRRRRRRRRRRRRRR
486
            //uploadDocid(onlineDocid + ".2",
487
            //            onlinetestdatafile2, FAILURE, true);
487
            uploadDocid(onlineDocid + ".2",
488
                        onlinetestdatafile2, FAILURE, true);
488 489

  
489 490
            // try to set the permissions for the uploaded document
490 491
            // the docid given is for the online document
491
            testdocument = getTestEmlDoc("Testing insert", null, null,
492
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
493
                                         null, null,
492 494
                                         "ecogrid://knb/" + onlineDocid + ".1",
493 495
                                         null, getAccessBlock(anotheruser, true,
494 496
                false, false, false, true),
......
507 509
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
508 510

  
509 511
            // upload a document which gives read access to the online document
510
            testdocument = getTestEmlDoc("Another insert", null, null,
512
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Another insert",
513
                                         null, null,
511 514
                                         "ecogrid://knb/" + onlineDocid + ".1",
512 515
                                         null, getAccessBlock(anotheruser, true,
513 516
                false, true, false, false),
......
528 531

  
529 532
            // try to set the permissions for the uploaded document
530 533
            // the docid given is for the online document
531
            testdocument = getTestEmlDoc("Testing insert", null, null,
534
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Another insert",
535
                                         null, null,
532 536
                                         "ecogrid://knb/" + onlineDocid + ".1",
533 537
                                         null, getAccessBlock(anotheruser, true,
534
                false, false, false, true),
538
                                         false, false, false, true),
535 539
                                         null, null, null, null);
536 540
            newdocid = generateDocid();
537 541
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
......
547 551
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
548 552

  
549 553
            // upload a document which gives read access to the online document
550
            testdocument = getTestEmlDoc("Another insert", null, null,
554
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Another insert",
555
                                         null, null,
551 556
                                         "ecogrid://knb/" + onlineDocid + ".1",
552 557
                                         null, getAccessBlock(anotheruser, true,
553 558
                                         false, false, true, false),
......
563 568
            readDocid(onlineDocid + ".1", FAILURE, true);
564 569

  
565 570
            // try to upload another data with updated id
566
            // ERRRRRRRRRRRRRRRRRRRRR
567
            // uploadDocid(onlineDocid + ".2",
568
            //           onlinetestdatafile2, FAILURE, true);
571
            uploadDocid(onlineDocid + ".2",
572
                          onlinetestdatafile2, FAILURE, true);
569 573

  
570 574
            // try to set the permissions for the uploaded document
571 575
            // the docid given is for the online document
572
            testdocument = getTestEmlDoc("Testing insert", null, null,
576
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
577
                                         null, null,
573 578
                                         "ecogrid://knb/" + onlineDocid + ".1",
574 579
                                         null, getAccessBlock(anotheruser, true,
575 580
                                         false, false, false, true),
576 581
                                         null, null, null, null);
577 582
            newdocid = generateDocid();
578 583
            // ERRRRRRRRRRRRRRRR
579
            //insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
584
            // User does not have permission to update of access rules for data
585
            // insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
580 586

  
581 587
            // delete the document
582 588
            deleteDocid(onlineDocid + ".1", FAILURE, true);
......
589 595
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
590 596

  
591 597
            // upload a document which gives read access to the online document
592
            testdocument = getTestEmlDoc("Another insert", null, null,
598
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
599
                                         null, null,
593 600
                                         "ecogrid://knb/" + onlineDocid + ".1",
594 601
                                         null, getAccessBlock(anotheruser, true,
595 602
                                         false, false, false, true),
......
610 617

  
611 618
            // try to set the permissions for the uploaded document
612 619
            // the docid given is for the online document
613
            testdocument = getTestEmlDoc("Testing insert", null, null,
620
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
621
                                         null, null,
614 622
                                         "ecogrid://knb/" + onlineDocid + ".1",
615 623
                                         null, getAccessBlock(anotheruser, true,
616 624
                                         true, false, false, false),
......
662 670
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
663 671

  
664 672
            // upload a document which gives read access to the online document
665
            testdocument = getTestEmlDoc("Another insert", null, null,
673
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
674
                                         null, null,
666 675
                                         "ecogrid://knb/" + onlineDocid + ".1",
667 676
                                         null, null, null, null,
668 677
                                         getAccessBlock(anotheruser, true,
......
678 687
            readDocid(onlineDocid + ".1", SUCCESS, false);
679 688

  
680 689
            // try to upload another data with updated id
681
            // ERRRRRRRRRRRRRRRRRRRRRR
682
            //uploadDocid(onlineDocid + ".2",
683
            //            onlinetestdatafile2, FAILURE, true);
690
            uploadDocid(onlineDocid + ".2",
691
                        onlinetestdatafile2, FAILURE, true);
684 692

  
685 693
            // try to set the permissions for the uploaded document
686 694
            // the docid given is for the online document
687
            testdocument = getTestEmlDoc("Testing insert", null, null,
695
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
696
                                         null, null,
688 697
                                         "ecogrid://knb/" + onlineDocid + ".1",
689 698
                                         null, null, null, null,
690 699
                                         getAccessBlock(anotheruser, true,
......
703 712
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
704 713

  
705 714
            // upload a document which gives read access to the online document
706
            testdocument = getTestEmlDoc("Another insert", null, null,
715
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
716
                                         null, null,
707 717
                                         "ecogrid://knb/" + onlineDocid + ".1",
708 718
                                         null, null, null, null,
709 719
                                         getAccessBlock(anotheruser, true,
......
724 734

  
725 735
            // try to set the permissions for the uploaded document
726 736
            // the docid given is for the online document
727
            testdocument = getTestEmlDoc("Testing insert", null, null,
737
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
738
                                         null, null,
728 739
                                         "ecogrid://knb/" + onlineDocid + ".1",
729 740
                                         null, null, null, null,
730 741
                                         getAccessBlock(anotheruser, true,
......
743 754
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
744 755

  
745 756
            // upload a document which gives read access to the online document
746
            testdocument = getTestEmlDoc("Another insert", null, null,
757
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
758
                                         null, null,
747 759
                                         "ecogrid://knb/" + onlineDocid + ".1",
748 760
                                         null, null, null, null,
749 761
                                         getAccessBlock(anotheruser, true,
......
759 771
            readDocid(onlineDocid + ".1", FAILURE, true);
760 772

  
761 773
            // try to upload another data with updated id
762
            // ERRRRRRRRRRRRRRRRRRRRR
763
            // uploadDocid(onlineDocid + ".2",
764
            //           onlinetestdatafile2, FAILURE, true);
774
            uploadDocid(onlineDocid + ".2",
775
                        onlinetestdatafile2, FAILURE, true);
765 776

  
766 777
            // try to set the permissions for the uploaded document
767 778
            // the docid given is for the online document
768
            testdocument = getTestEmlDoc("Testing insert", null, null,
779
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
780
                                         null, null,
769 781
                                         "ecogrid://knb/" + onlineDocid + ".1",
770 782
                                         null, null, null, null,
771 783
                                         getAccessBlock(anotheruser, true,
772 784
                                         false, false, false, true), null);
773 785
            newdocid = generateDocid();
774 786
            // ERRRRRRRRRRRRRRRR
775
            //insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
787
            // User does not have permission to update of access rules for data
788
            // insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
776 789

  
777 790
            // delete the document
778 791
            deleteDocid(onlineDocid + ".1", FAILURE, true);
......
785 798
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
786 799

  
787 800
            // upload a document which gives read access to the online document
788
            testdocument = getTestEmlDoc("Another insert", null, null,
801
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
802
                                         null, null,
789 803
                                         "ecogrid://knb/" + onlineDocid + ".1",
790 804
                                         null, null, null, null,
791 805
                                         getAccessBlock(anotheruser, true,
......
806 820

  
807 821
            // try to set the permissions for the uploaded document
808 822
            // the docid given is for the online document
809
            testdocument = getTestEmlDoc("Testing insert", null, null,
823
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
824
                                         null, null,
810 825
                                         "ecogrid://knb/" + onlineDocid + ".1",
811 826
                                         null, null, null, null,
812 827
                                         getAccessBlock(anotheruser, true,
......
849 864
            m.login(username, password);
850 865

  
851 866
            /////////Case 1
852
            testdocument = getTestEmlDoc("Testing insert", null, null,
867
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert", null, null,
853 868
                                         "ecogrid://knb/" + onlineDocid + ".1",
854 869
                                         null, null, null, null, null,
855 870
                                         getAccessBlock(anotheruser, true,
......
858 873
            insertDocid(newdocid + ".1", testdocument, FAILURE, false);
859 874

  
860 875
            /////////Case 2
861
            testdocument = getTestEmlDoc("Testing insert", null, null,
876
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert", null, null,
862 877
                                         "ecogrid://knb/" + onlineDocid + ".1",
863 878
                                         null, null, null, null,
864 879
                                         getAccessBlock(anotheruser, true,
865 880
                                         true, false, false, false), null);
866 881
            newdocid = generateDocid();
867 882

  
868
            // ERRRRRRRRRRRRRRRR - what is the right behaviour??????
869
            //insertDocid(newdocid + ".1", testdocument, FAILURE, false);
883
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
870 884
            m.logout();
871 885

  
872 886
        }
......
897 911

  
898 912
            // insert a document
899 913
            m.login(username, password);
900
            testdocument = getTestEmlDoc("Doing insert", null, null, null,
914
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
915
                                         null, null, null,
901 916
                                         null, getAccessBlock(anotheruser, true,
902 917
                                         true, false, false, false), null, null,
903 918
                                         null, null);
......
908 923

  
909 924
            // update document
910 925
            m.login(username, password);
911
            testdocument = getTestEmlDoc("Doing update", null, null, null,
926
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing update",
927
                                         null, null, null,
912 928
                                         null, getAccessBlock(anotheruser, true,
913 929
                                         true, false, false, false), null, null,
914 930
                                         null, null);
......
929 945

  
930 946
            // upload data and update the document
931 947
            m.login(username, password);
932
            testdocument = getTestEmlDoc("Doing update", null, null,
948
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing update",
949
                                         null, null,
933 950
                                         "ecogrid://knb/" + onlineDocid + ".1",
934 951
                                         null, getAccessBlock(anotheruser, true,
935 952
                                         true, false, false, false), null, null,
......
939 956

  
940 957
            // set read for document - no read for data
941 958
            m.login(username, password);
942
            testdocument = getTestEmlDoc("Doing update", null, null,
959
            testdocument = getTestEmlDoc("OnlineDataAccessTest: Doing insert",
960
                                         null, null,
943 961
                                         "ecogrid://knb/" + onlineDocid + ".1",
944 962
                                         null, getAccessBlock(anotheruser, true,
945 963
                                         true, false, false, false), null, null,
test/edu/ucsb/nceas/metacattest/AccessControlTest.java
58 58
    private String anotherpassword = "@mcanotherpassword@";
59 59
    private String prefix = "test";
60 60
    private String newdocid = null;
61
    private String onlineDocid = null;
62 61
    private String testdocument = "";
62
    private String onlineDocid;
63 63
    private String onlinetestdatafile1 = "test/onlineDataFile1";
64 64
    private String onlinetestdatafile2 = "test/onlineDataFile2";
65 65

  
......
208 208

  
209 209
        testDocument += "</dataset>";
210 210

  
211
        // if(inlineAccessBlock1 != null || inlineAccessBlock2 != null ||
212
        //    onlineAccessBlock1 != null || onlineAccessBlock2 != null){
213
        //     testDocument += "<addtionalMetadata>";
214
        // }
215

  
216 211
        if (inlineAccessBlock1 != null) {
217 212
            testDocument += "<additionalMetadata>";
218 213
            testDocument += "<describes>inlineEntity1</describes>";
......
284 279
        TestSuite suite = new TestSuite();
285 280
        suite.addTest(new AccessControlTest("initialize"));
286 281
        // Test basic functions
287
        //suite.addTest(new AccessControlTest("login"));
288
        //suite.addTest(new AccessControlTest("insert"));
289
        //suite.addTest(new AccessControlTest("read"));
290
        //suite.addTest(new AccessControlTest("update"));
291
        //suite.addTest(new AccessControlTest("delete"));
292
        // Tests when no access is specified
293
        //suite.addTest(new AccessControlTest("documentTest"));
294
        //suite.addTest(new AccessControlTest("documentWithInlineDataTest"));
295
        //suite.addTest(new AccessControlTest("documentWithOnlineDataTest"));
296
        suite.addTest(new AccessControlTest("onlineDataCasesTest_1"));
297
        suite.addTest(new AccessControlTest("onlineDataCasesTest_2"));
298
        suite.addTest(new AccessControlTest("onlineDataCasesTest_3"));
282
        suite.addTest(new AccessControlTest("documentTest"));
283
        suite.addTest(new AccessControlTest("AccessControlTestForPublic"));
299 284

  
300
        //suite.addTest(new AccessControlTest("noAccessSpecified_Random"));
301
        //suite.addTest(new AccessControlTest("noAccessSpecified_Public"));
302

  
303 285
        return suite;
304 286
    }
305 287

  
306
    /** *********
307
     * Test the case when no access is specified and owner is logged in
308
     * No online or inline data is involved
309
     */
310

  
311
    public void onlineDataCasesTest_1() {
312
        try {
313
            /////////Case 1./////////////////////
314
            // upload an online document
315
            onlineDocid = generateDocid();
316
            m.login(username, password);
317
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
318
            m.logout();
319

  
320
            // write a document with no access rules from a
321
            // different userid which refers to this document
322
            m.login(anotheruser, anotherpassword);
323
            testdocument = getTestEmlDoc("Testing insert", null, null,
324
                                         "ecogrid://knb/" + onlineDocid + ".1",
325
                                         null, null, null, null, null, null);
326
            newdocid = generateDocid();
327
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
328
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
329

  
330
            m.logout();
331
            m.login(anotheruser, anotherpassword);
332

  
333
            // write a document with access rules from a
334
            // different userid which refers to this document
335
            testdocument = getTestEmlDoc("Another insert", null, null,
336
                                         "ecogrid://knb/" + onlineDocid + ".1",
337
                                         null, getAccessBlock(anotheruser, true,
338
                false, false, false, true),
339
                                         null, null, null, null);
340
            newdocid = generateDocid();
341
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
342

  
343
            m.logout();
344

  
345
            /////////Case 2./////////////////////
346
            // upload an online document
347
            onlineDocid = generateDocid();
348
            m.login(username, password);
349
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
350

  
351
            testdocument = getTestEmlDoc("Testing insert", null, null,
352
                                         "ecogrid://knb/" + onlineDocid + ".1",
353
                                         null, null,
354
                                         null, null, null, null);
355
            newdocid = generateDocid();
356
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
357

  
358
            m.logout();
359

  
360
            // write a document with no access rules from a
361
            // different userid which refers to this document
362
            m.login(anotheruser, anotherpassword);
363
            testdocument = getTestEmlDoc("Testing insert", null, null,
364
                                         "ecogrid://knb/" + onlineDocid + ".1",
365
                                         null, null, null, null, null, null);
366
            newdocid = generateDocid();
367
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
368
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
369

  
370
            m.logout();
371
            m.login(anotheruser, anotherpassword);
372
            // write a document with access rules from a
373
            // different userid which refers to this document
374
            testdocument = getTestEmlDoc("Another insert", null, null,
375
                                         "ecogrid://knb/" + onlineDocid + ".1",
376
                                         null, getAccessBlock(anotheruser, true,
377
                false, false, false, true),
378
                                         null, null, null, null);
379
            newdocid = generateDocid();
380
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
381

  
382
            m.logout();
383
        }
384
        catch (MetacatAuthException mae) {
385
            fail("Authorization failed:\n" + mae.getMessage());
386
        }
387
        catch (MetacatInaccessibleException mie) {
388
            fail("Metacat Inaccessible:\n" + mie.getMessage());
389
        }
390
        catch (Exception e) {
391
            fail("General exception:\n" + e.getMessage());
392
        }
393
    }
394

  
395
    public void onlineDataCasesTest_2() {
396
        try {
397

  
398
            /////////Case 3./////////////////////
399
            // upload an online document
400
            onlineDocid = generateDocid();
401
            m.login(username, password);
402
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
403

  
404
            testdocument = getTestEmlDoc("Testing insert", null, null,
405
                                         "ecogrid://knb/" + onlineDocid + ".1",
406
                                         null, getAccessBlock(anotheruser, true,
407
                true, false, false, false),
408
                                         null, null, null, null);
409
            newdocid = generateDocid();
410
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
411

  
412
            m.logout();
413

  
414
            // write a document with no access rules from a
415
            // different userid which refers to this document
416
            m.login(anotheruser, anotherpassword);
417
            testdocument = getTestEmlDoc("Testing insert", null, null,
418
                                         "ecogrid://knb/" + onlineDocid + ".1",
419
                                         null, null, null, null, null, null);
420
            newdocid = generateDocid();
421
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
422
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
423

  
424
            m.logout();
425
            m.login(anotheruser, anotherpassword);
426

  
427
            // write a document with access rules from a
428
            // different userid which refers to this document
429
            testdocument = getTestEmlDoc("Another insert", null, null,
430
                                         "ecogrid://knb/" + onlineDocid + ".1",
431
                                         null, getAccessBlock(anotheruser, true,
432
                false, false, false, true),
433
                                         null, null, null, null);
434
            newdocid = generateDocid();
435
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
436

  
437
            m.logout();
438

  
439
            /////////Case 4./////////////////////
440
            // upload an online document
441
            onlineDocid = generateDocid();
442
            m.login(username, password);
443
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
444

  
445
            testdocument = getTestEmlDoc("Testing insert", null, null,
446
                                         "ecogrid://knb/" + onlineDocid + ".1",
447
                                         null, getAccessBlock(anotheruser, true,
448
                false, true, false, false),
449
                                         null, null, null, null);
450
            newdocid = generateDocid();
451
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
452

  
453
            m.logout();
454

  
455
            // write a document with no access rules from a
456
            // different userid which refers to this document
457
            m.login(anotheruser, anotherpassword);
458
            testdocument = getTestEmlDoc("Testing insert", null, null,
459
                                         "ecogrid://knb/" + onlineDocid + ".1",
460
                                         null, null, null, null, null, null);
461
            newdocid = generateDocid();
462
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
463
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
464

  
465
            m.logout();
466
            m.login(anotheruser, anotherpassword);
467

  
468
            // write a document with access rules from a
469
            // different userid which refers to this document
470
            testdocument = getTestEmlDoc("Another insert", null, null,
471
                                         "ecogrid://knb/" + onlineDocid + ".1",
472
                                         null, getAccessBlock(anotheruser, true,
473
                false, false, false, true),
474
                                         null, null, null, null);
475
            newdocid = generateDocid();
476
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
477

  
478
            m.logout();
479

  
480
            /////////Case 5./////////////////////
481
            // upload an online document
482
            onlineDocid = generateDocid();
483
            m.login(username, password);
484
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
485

  
486
            testdocument = getTestEmlDoc("Testing insert", null, null,
487
                                         "ecogrid://knb/" + onlineDocid + ".1",
488
                                         null, getAccessBlock(anotheruser, true,
489
                false, false, false, true),
490
                                         null, null, null, null);
491
            newdocid = generateDocid();
492
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
493

  
494
            m.logout();
495

  
496
            // write a document with no access rules from a
497
            // different userid which refers to this document
498
            m.login(anotheruser, anotherpassword);
499
            testdocument = getTestEmlDoc("Testing insert", null, null,
500
                                         "ecogrid://knb/" + onlineDocid + ".1",
501
                                         null, null, null, null, null, null);
502
            newdocid = generateDocid();
503
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
504
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
505

  
506
            m.logout();
507
            m.login(anotheruser, anotherpassword);
508

  
509
            // write a document with access rules from a
510
            // different userid which refers to this document
511
            testdocument = getTestEmlDoc("Another insert", null, null,
512
                                         "ecogrid://knb/" + onlineDocid + ".1",
513
                                         null, getAccessBlock(anotheruser, true,
514
                false, false, true, false),
515
                                         null, null, null, null);
516
            newdocid = generateDocid();
517
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
518
            m.logout();
519

  
520
            /////////Case 6./////////////////////
521
            // upload an online document
522
            onlineDocid = generateDocid();
523
            m.login(username, password);
524
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
525

  
526
            testdocument = getTestEmlDoc("Testing insert", null, null,
527
                                         "ecogrid://knb/" + onlineDocid + ".1",
528
                                         null, getAccessBlock(anotheruser, true,
529
                false, false, false, true),
530
                                         null, null, null, null);
531
            newdocid = generateDocid();
532
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
533

  
534
            m.logout();
535

  
536
            // write a document with no access rules from a
537
            // different userid which refers to this document
538
            m.login(anotheruser, anotherpassword);
539
            testdocument = getTestEmlDoc("Testing insert", null, null,
540
                                         "ecogrid://knb/" + onlineDocid + ".1",
541
                                         null, null, null, null, null, null);
542
            newdocid = generateDocid();
543
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
544
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
545

  
546
            m.logout();
547
            m.login(anotheruser, anotherpassword);
548

  
549
            // write a document with access rules from a
550
            // different userid which refers to this document
551
            testdocument = getTestEmlDoc("Another insert", null, null,
552
                                         "ecogrid://knb/" + onlineDocid + ".1",
553
                                         null, getAccessBlock(anotheruser, true,
554
                true, false, false, false),
555
                                         null, null, null, null);
556
            newdocid = generateDocid();
557
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
558

  
559
            m.logout();
560
        }
561
        catch (MetacatAuthException mae) {
562
            fail("Authorization failed:\n" + mae.getMessage());
563
        }
564
        catch (MetacatInaccessibleException mie) {
565
            fail("Metacat Inaccessible:\n" + mie.getMessage());
566
        }
567
        catch (Exception e) {
568
            fail("General exception:\n" + e.getMessage());
569
        }
570
    }
571

  
572

  
573

  
574

  
575
    public void onlineDataCasesTest_4() {
576
        try {
577
            /////////Case 7./////////////////////
578
            // upload an online document
579
            onlineDocid = generateDocid();
580
            m.login(username, password);
581
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
582

  
583
            testdocument = getTestEmlDoc("Testing insert", null, null,
584
                                         "ecogrid://knb/" + onlineDocid + ".1",
585
                                         null, null, null, null,
586
                                         getAccessBlock(anotheruser, true,
587
                true, false, false, false), null);
588
            newdocid = generateDocid();
589
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
590

  
591
            m.logout();
592

  
593
            // write a document with no access rules from a
594
            // different userid which refers to this document
595
            m.login(anotheruser, anotherpassword);
596
            testdocument = getTestEmlDoc("Testing insert", null, null,
597
                                         "ecogrid://knb/" + onlineDocid + ".1",
598
                                         null, null, null, null, null, null);
599
            newdocid = generateDocid();
600
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
601
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
602

  
603
            m.logout();
604
            m.login(anotheruser, anotherpassword);
605

  
606
            // try to read the online data file
607
            readDocid(onlineDocid + ".1", SUCCESS, false);
608

  
609
            // write a document with access rules from a
610
            // different userid which refers to this document
611
            testdocument = getTestEmlDoc("Another insert", null, null,
612
                                         "ecogrid://knb/" + onlineDocid + ".1",
613
                                         null, getAccessBlock(anotheruser, true,
614
                false, false, false, true),
615
                                         null, null, null, null);
616
            newdocid = generateDocid();
617
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
618

  
619
            m.logout();
620

  
621
            /////////Case 8./////////////////////
622
            // upload an online document
623
            onlineDocid = generateDocid();
624
            m.login(username, password);
625
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
626

  
627
            testdocument = getTestEmlDoc("Testing insert", null, null,
628
                                         "ecogrid://knb/" + onlineDocid + ".1",
629
                                         null, null, null, null,
630
                                         getAccessBlock(anotheruser, true,
631
                false, true, false, false), null);
632
            newdocid = generateDocid();
633
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
634

  
635
            m.logout();
636

  
637
            // write a document with no access rules from a
638
            // different userid which refers to this document
639
            m.login(anotheruser, anotherpassword);
640

  
641
            testdocument = getTestEmlDoc("Testing insert", null, null,
642
                                         "ecogrid://knb/" + onlineDocid + ".1",
643
                                         null, null, null, null, null, null);
644
            newdocid = generateDocid();
645
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
646
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
647

  
648
            m.logout();
649
            m.login(anotheruser, anotherpassword);
650

  
651
            // try to read the online data file
652
            readDocid(onlineDocid + ".1", FAILURE, true);
653

  
654
            // write a document with access rules from a
655
            // different userid which refers to this document
656
            testdocument = getTestEmlDoc("Another insert", null, null,
657
                                         "ecogrid://knb/" + onlineDocid + ".1",
658
                                         null, getAccessBlock(anotheruser, true,
659
                false, false, false, true),
660
                                         null, null, null, null);
661
            newdocid = generateDocid();
662
            insertDocid(newdocid + ".1", testdocument, FAILURE, true);
663

  
664
            m.logout();
665

  
666
            /////////Case 9./////////////////////
667
            // upload an online document
668
            onlineDocid = generateDocid();
669
            m.login(username, password);
670
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
671

  
672
            testdocument = getTestEmlDoc("Testing insert", null, null,
673
                                         "ecogrid://knb/" + onlineDocid + ".1",
674
                                         null, null, null, null,
675
                                         getAccessBlock(anotheruser, true,
676
                false, false, true, false), null);
677
            newdocid = generateDocid();
678
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
679

  
680
            m.logout();
681

  
682
            // write a document with no access rules from a
683
            // different userid which refers to this document
684
            m.login(anotheruser, anotherpassword);
685
            testdocument = getTestEmlDoc("Testing insert", null, null,
686
                                         "ecogrid://knb/" + onlineDocid + ".1",
687
                                         null, null, null, null, null, null);
688
            newdocid = generateDocid();
689
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
690
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
691

  
692
            m.logout();
693
            m.login(anotheruser, anotherpassword);
694

  
695
            // try to read the online data file
696
            readDocid(onlineDocid + ".1", FAILURE, true);
697

  
698
            // write a document with access rules from a
699
            // different userid which refers to this document
700
            testdocument = getTestEmlDoc("Another insert", null, null,
701
                                         "ecogrid://knb/" + onlineDocid + ".1",
702
                                         null, getAccessBlock(anotheruser, true,
703
                false, false, true, false),
704
                                         null, null, null, null);
705
            newdocid = generateDocid();
706
            //ERRRRRRRRRRRRRRRROR
707
            //insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
708

  
709
            /////////Case 10./////////////////////
710
            // upload an online document
711
            onlineDocid = generateDocid();
712
            m.login(username, password);
713
            uploadDocid(onlineDocid + ".1", onlinetestdatafile1, SUCCESS, false);
714

  
715
            testdocument = getTestEmlDoc("Testing insert", null, null,
716
                                         "ecogrid://knb/" + onlineDocid + ".1",
717
                                         null, null, null, null,
718
                                         getAccessBlock(anotheruser, true,
719
                false, false, false, true), null);
720
            newdocid = generateDocid();
721
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
722

  
723
            m.logout();
724

  
725
            // write a document with no access rules from a
726
            // different userid which refers to this document
727
            m.login(anotheruser, anotherpassword);
728
            testdocument = getTestEmlDoc("Testing insert", null, null,
729
                                         "ecogrid://knb/" + onlineDocid + ".1",
730
                                         null, null, null, null, null, null);
731
            newdocid = generateDocid();
732
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
733
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
734

  
735
            m.logout();
736
            m.login(anotheruser, anotherpassword);
737

  
738
            // try to read the online data file
739
            readDocid(onlineDocid + ".1", SUCCESS, false);
740

  
741
            // write a document with access rules from a
742
            // different userid which refers to this document
743
            testdocument = getTestEmlDoc("Another insert", null, null,
744
                                         "ecogrid://knb/" + onlineDocid + ".1",
745
                                         null, getAccessBlock(anotheruser, true,
746
                true, false, false, false),
747
                                         null, null, null, null);
748
            newdocid = generateDocid();
749
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
750

  
751
            m.logout();
752

  
753
        }
754
        catch (MetacatAuthException mae) {
755
            fail("Authorization failed:\n" + mae.getMessage());
756
        }
757
        catch (MetacatInaccessibleException mie) {
758
            fail("Metacat Inaccessible:\n" + mie.getMessage());
759
        }
760
        catch (Exception e) {
761
            fail("General exception:\n" + e.getMessage());
762
        }
763
    }
764

  
765

  
766

  
767 288
    /**
768 289
     * Run an initial test that always passes to check that the test
769 290
     * harness is working.
......
772 293
        assertTrue(1 == 1);
773 294
    }
774 295

  
775
    /**
776
     * Test the login() function with valid credentials
777
     */
778
    public void login() {
779
        // Try a valid login
780
        try {
781
            String response = m.login(username, password);
782
            System.err.println("Login response: " + response);
783
            assertTrue(response != null);
784
            assertTrue(response.indexOf("<login>") != -1);
785
            String sessionId = m.getSessionId();
786
            System.err.println("Session ID: " + m.getSessionId());
787
            assertTrue(sessionId != null);
788
            assertTrue(response.indexOf(m.getSessionId()) != -1);
789
        }
790
        catch (MetacatAuthException mae) {
791
            fail("Authorization failed:\n" + mae.getMessage());
792
        }
793
        catch (MetacatInaccessibleException mie) {
794
            fail("Metacat Inaccessible:\n" + mie.getMessage());
795
        }
796
    }
797

  
798
    /**
799
     * Test the insert() function with a known document
800
     */
801
    public void insert() {
802
        try {
803
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1,
804
                                         null, null, null, null,
805
                                         null, null, null, null);
806
            String identifier = newdocid + ".1";
807
            m.login(username, password);
808
            String response = m.insert(identifier,
809
                                       new StringReader(testdocument), null);
810
            assertTrue(response.indexOf("<success>") != -1);
811
            assertTrue(response.indexOf(identifier) != -1);
812
            System.err.println(response);
813
        }
814
        catch (MetacatAuthException mae) {
815
            fail("Authorization failed:\n" + mae.getMessage());
816
        }
817
        catch (MetacatInaccessibleException mie) {
818
            fail("Metacat Inaccessible:\n" + mie.getMessage());
819
        }
820
        catch (InsufficientKarmaException ike) {
821
            assertTrue(1 == 1);
822
            fail("Insufficient karma:\n" + ike.getMessage());
823
        }
824
        catch (MetacatException me) {
825
            fail("Metacat Error:\n" + me.getMessage());
826
        }
827
        catch (Exception e) {
828
            fail("General exception:\n" + e.getMessage());
829
        }
830
    }
831

  
832
    /**
833
     * The read() function
834
     */
835
    public void read() {
836
        try {
837
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1, null,
838
                                         null, null, null, null, null, null, null);
839

  
840
            m.login(username, password);
841
            Reader r = m.read(newdocid + ".1");
842
            String doc = IOUtil.getAsString(r, true);
843
            assertTrue(doc.equals(testdocument));
844
        }
845
        catch (MetacatAuthException mae) {
846
            fail("Authorization failed:\n" + mae.getMessage());
847
        }
848
        catch (MetacatInaccessibleException mie) {
849
            fail("Metacat Inaccessible:\n" + mie.getMessage());
850
        }
851
        catch (Exception e) {
852
            fail("General exception:\n" + e.getMessage());
853
        }
854
    }
855

  
856
    /**
857
     * Test the update() function with a known document
858
     */
859
    public void update() {
860
        try {
861
            testdocument = getTestEmlDoc("Testing update", testEmlInlineBlock1, null,
862
                                         null, null, null, null, null, null, null);
863
            String identifier = newdocid + ".2";
864
            m.login(username, password);
865
            String response = m.update(identifier,
866
                                       new StringReader(testdocument), null);
867
            assertTrue(response.indexOf("<success>") != -1);
868
            assertTrue(response.indexOf(identifier) != -1);
869
            System.err.println(response);
870

  
871
        }
872
        catch (MetacatAuthException mae) {
873
            fail("Authorization failed:\n" + mae.getMessage());
874
        }
875
        catch (MetacatInaccessibleException mie) {
876
            fail("Metacat Inaccessible:\n" + mie.getMessage());
877
        }
878
        catch (InsufficientKarmaException ike) {
879
            fail("Insufficient karma:\n" + ike.getMessage());
880
        }
881
        catch (MetacatException me) {
882
            fail("Metacat Error:\n" + me.getMessage());
883
        }
884
        catch (Exception e) {
885
            fail("General exception:\n" + e.getMessage());
886
        }
887
    }
888

  
889
    /**
890
     * Test the delete() function with a known document
891
     */
892
    public void delete() {
893
        try {
894
            String identifier = newdocid + ".2";
895
            m.login(username, password);
896
            String response = m.delete(identifier);
897
            assertTrue(response.indexOf("<success>") != -1);
898
            System.err.println(response);
899

  
900
        }
901
        catch (MetacatAuthException mae) {
902
            fail("Authorization failed:\n" + mae.getMessage());
903
        }
904
        catch (MetacatInaccessibleException mie) {
905
            fail("Metacat Inaccessible:\n" + mie.getMessage());
906
        }
907
        catch (InsufficientKarmaException ike) {
908
            fail("Insufficient karma:\n" + ike.getMessage());
909
        }
910
        catch (MetacatException me) {
911
            fail("Metacat Error:\n" + me.getMessage());
912
        }
913
        catch (Exception e) {
914
            fail("General exception:\n" + e.getMessage());
915
        }
916
    }
917

  
918 296
    /** *********
919 297
     * Test the case when no access is specified and owner is logged in
920 298
     * No online or inline data is involved
299
     * -> an user inserts a document and is able to read it, update it,
300
     *    set permissions on it and delete it
301
     * -> another user is not able to do anything with the document
302
     *    when no access is specified for that user
303
     * -> test what all the other user can do when read only, write only and
304
     *    change permissions only permissions are specified
305
     *
921 306
     */
922 307
    public void documentTest() {
923 308
        try {
......
931 316
                                         null, null,
932 317
                                         null, null, null, null, null, null);
933 318
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
319

  
320
            // read the document
934 321
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
935 322

  
936 323
            // update the document
......
940 327
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
941 328

  
942 329
            /////////////////////////////
330
            // check what the another user can do
331
            m.logout();
332
            m.login(anotheruser, anotherpassword);
333

  
334
            // check if the user mentioned is able to read/update/delete the document
335
            readDocidWhichEqualsDoc(newdocid + ".2", testdocument, FAILURE, true);
336
            updateDocid(newdocid + ".3", testdocument, FAILURE, true);
337
            deleteDocid(newdocid + ".2", FAILURE, true);
338

  
339
            /////////////////////////////
943 340
            // update the document access control - read only
341
            m.logout();
342
            m.login(username, password);
343

  
944 344
            testdocument = getTestEmlDoc("Testing update access block",
945 345
                                         null, null, null,
946 346
                                         null, getAccessBlock(anotheruser, true,
947
                true, false, false, false),
347
                                         true, false, false, false),
948 348
                                         null, null, null, null);
949 349
            updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
950 350
            readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, false);
......
958 358
            testdocument = getTestEmlDoc("Testing update from another user",
959 359
                                         null, null, null,
960 360
                                         null, getAccessBlock(anotheruser, true,
961
                true, false, false, false),
361
                                         true, false, false, false),
962 362
                                         null, null, null, null);
963 363
            updateDocid(newdocid + ".4", testdocument, FAILURE, true);
964 364

  
965 365
            // or the permissions
966
            testdocument = getTestEmlDoc(
967
                "Testing perm update from another user",
968
                null, null, null,
969
                null, getAccessBlock(anotheruser, true,
970
                                     false, false, false, true),
971
                null, null, null, null);
366
            testdocument = getTestEmlDoc("Testing update access block",
367
                                         null, null, null,
368
                                         null, getAccessBlock(anotheruser, true,
369
                                         false, false, false, true),
370
                                         null, null, null, null);
972 371
            updateDocid(newdocid + ".4", testdocument, FAILURE, true);
372

  
373
            // or delete the document
374
            deleteDocid(newdocid + ".3", FAILURE, true);
375

  
973 376
            m.logout();
974 377
            m.login(username, password);
975 378

  
......
978 381
            testdocument = getTestEmlDoc("Testing update access block",
979 382
                                         null, null, null,
980 383
                                         null, getAccessBlock(anotheruser, true,
981
                false, true, false, false),
384
                                         false, true, false, false),
982 385
                                         null, null, null, null);
983 386
            updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
984 387
            readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, false);
......
989 392
            readDocidWhichEqualsDoc(newdocid + ".4", testdocument, FAILURE, true);
990 393

  
991 394
            // should be able to update the document
992
            testdocument = getTestEmlDoc("Testing update access block",
993
                                         null, null, null,
994
                                         null, getAccessBlock(anotheruser, true,
995
                false, true, false, false),
996
                                         null, null, null, null);
395

  
997 396
            //System.out.println(testdocument);
998 397
            // ERRRRRRRRRRRRROR
999
            //updateDocid(newdocid + ".6", testdocument, SUCCESS, false);
398
            //updateDocid(newdocid + ".5", testdocument, SUCCESS, false);
1000 399

  
1001 400
            // but not the permissions
1002
            testdocument = getTestEmlDoc("Testing update from another user",
401
            testdocument = getTestEmlDoc("Testing update access block",
1003 402
                                         null, null, null,
1004 403
                                         null, getAccessBlock(anotheruser, true,
1005
                false, true, false, true),
404
                                         false, true, false, true),
1006 405
                                         null, null, null, null);
1007 406
            updateDocid(newdocid + ".5", testdocument, FAILURE, true);
1008 407

  
408
            // try to delete the document
409
            //deleteDocid(newdocid + ".5", FAILURE, true);
410
            deleteDocid(newdocid + ".4", FAILURE, true);
411

  
1009 412
            m.logout();
1010 413
            m.login(username, password);
1011 414

  
......
1033 436
            updateDocid(newdocid + ".6", testdocument, FAILURE, true);
1034 437

  
1035 438
            // but can chg the permissions
1036
            testdocument = getTestEmlDoc("Testing update from another user",
439
            testdocument = getTestEmlDoc("Testing update access block",
1037 440
                                         null, null, null,
1038 441
                                         null, getAccessBlock(anotheruser, true,
1039
                false, false, false, true),
442
                                         false, false, false, true),
1040 443
                                         null, null, null, null);
1041 444
            // ERRRRRRRROR
1042 445
            //updateDocid(newdocid + ".6", testdocument, SUCCESS, false);
1043 446

  
447
            // try to delete the document
448
            //deleteDocid(newdocid + ".6", FAILURE, true);
449
            deleteDocid(newdocid + ".5", FAILURE, true);
450

  
1044 451
            m.logout();
1045 452
            m.login(username, password);
1046 453

  
454

  
1047 455
            /////////////////////////////////
1048
            // update the document access control - all
456
            // update the document access control - read & write
1049 457
            testdocument = getTestEmlDoc("Testing update access block",
1050 458
                                         null, null, null,
1051 459
                                         null, getAccessBlock(anotheruser, true,
1052
                false, false, false, true),
460
                                         true, true, false, false),
1053 461
                                         null, null, null, null);
1054 462
            updateDocid(newdocid + ".7", testdocument, SUCCESS, false);
1055 463
            readDocidWhichEqualsDoc(newdocid + ".7", testdocument, SUCCESS, false);
......
1059 467
            m.login(anotheruser, anotherpassword);
1060 468
            readDocidWhichEqualsDoc(newdocid + ".7", testdocument, SUCCESS, false);
1061 469

  
1062
            // should not be able to update the document
1063
            testdocument = getTestEmlDoc("Testing update from another user",
1064
                                         null, null, null,
1065
                                         null, getAccessBlock(anotheruser, true,
1066
                false, false, false, true),
1067
                                         null, null, null, null);
1068
            updateDocid(newdocid + ".8", testdocument, SUCCESS, false);
1069
            readDocidWhichEqualsDoc(newdocid + ".8", testdocument, SUCCESS, false);
470
            // should be able to update the document
471
            //updateDocid(newdocid + ".8", testdocument, SUCCESS, false);
1070 472

  
1071
            // but can chg the permissions
1072
            testdocument = getTestEmlDoc("Testing update from another user",
473
            // but cant chg the permissions
474
            testdocument = getTestEmlDoc("Testing update access block",
1073 475
                                         null, null, null,
1074 476
                                         null, getAccessBlock(anotheruser, true,
1075
                true, false, false, false),
477
                                         false, false, false, true),
1076 478
                                         null, null, null, null);
1077
            updateDocid(newdocid + ".9", testdocument, SUCCESS, false);
1078
            readDocidWhichEqualsDoc(newdocid + ".9", testdocument, SUCCESS, false);
479
            updateDocid(newdocid + ".9", testdocument, FAILURE, true);
1079 480

  
1080
            m.logout();
481
            // try to delete the document
482
            // deleteDocid(newdocid + ".8", FAILURE, true);
483
            deleteDocid(newdocid + ".7", FAILURE, true);
1081 484

  
1082
            // delete the document
1083
            m.login(username, password);
1084
            deleteDocid(newdocid + ".9", SUCCESS);
1085 485
            m.logout();
1086
        }
1087
        catch (MetacatAuthException mae) {
1088
            fail("Authorization failed:\n" + mae.getMessage());
1089
        }
1090
        catch (MetacatInaccessibleException mie) {
1091
            fail("Metacat Inaccessible:\n" + mie.getMessage());
1092
        }
1093
        catch (Exception e) {
1094
            fail("General exception:\n" + e.getMessage());
1095
        }
1096

  
1097
    }
1098

  
1099
    /** *********
1100
     * Test the case when no access is specified and owner is logged in
1101
     * Only inline data is involved
1102
     */
1103
    public void documentWithInlineDataTest() {
1104
        try {
1105
            newdocid = generateDocid();
1106

  
1107
            // login
1108 486
            m.login(username, password);
1109 487

  
1110
            // insert a document
1111
            testdocument = getTestEmlDoc("Testing insert", testEmlInlineBlock1,
1112
                                         null, null, null, null,
1113
                                         null, null, null, null);
1114
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
1115
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
1116 488

  
1117
            // update the document
1118
            testdocument = getTestEmlDoc("Testing update", testEmlInlineBlock1,
1119
                                         null, null, null, null,
1120
                                         null, null, null, null);
1121
            updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
1122
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
1123

  
1124
            // update by modifying inline data
1125
            testdocument = getTestEmlDoc("Testing update inline",
1126
                                         testEmlInlineBlock2,
1127
                                         null, null, null, null,
1128
                                         null, null, null, null);
1129
            updateDocid(newdocid + ".3", testdocument, SUCCESS, false);
1130
            readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true);
1131

  
1132
            // update by removing inline data
1133
            testdocument = getTestEmlDoc("Testing update inline",
1134
                                         null,
1135
                                         null, null, null, null,
1136
                                         null, null, null, null);
1137
            updateDocid(newdocid + ".4", testdocument, SUCCESS, false);
1138
            readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true);
1139

  
1140
            // update by introducing inline data
1141
            testdocument = getTestEmlDoc("Testing update inline",
1142
                                         testEmlInlineBlock1,
1143
                                         null, null, null, null,
1144
                                         null, null, null, null);
1145
            updateDocid(newdocid + ".5", testdocument, SUCCESS, false);
1146
            readDocidWhichEqualsDoc(newdocid + ".5", testdocument, SUCCESS, true);
1147

  
1148
            //  read document and check if it is same as the document which was written
1149
            //  the second time
1150

  
1151

  
1152
            /////////////////////////////
1153
            // update the document access control - read only
489
            /////////////////////////////////
490
            // update the document access control - read & change permissions
1154 491
            testdocument = getTestEmlDoc("Testing update access block",
1155
                                         testEmlInlineBlock2,
1156 492
                                         null, null, null,
1157
                                         getAccessBlock(anotheruser, true,
1158
                true, false, false, false),
493
                                         null, getAccessBlock(anotheruser, true,
494
                                         true, false, true, false),
1159 495
                                         null, null, null, null);
1160
            updateDocid(newdocid + ".6", testdocument, SUCCESS, false);
1161
            readDocidWhichEqualsDoc(newdocid + ".6", testdocument, SUCCESS, true);
496
            updateDocid(newdocid + ".9", testdocument, SUCCESS, false);
497
            readDocidWhichEqualsDoc(newdocid + ".9", testdocument, SUCCESS, false);
1162 498

  
1163 499
            // check if the user mentioned is able to read the document
1164 500
            m.logout();
1165 501
            m.login(anotheruser, anotherpassword);
1166
            readDocidWhichEqualsDoc(newdocid + ".6", testdocument, SUCCESS, true);
1167

  
1168
            // should not be able to update the document or the inline data
502
            readDocidWhichEqualsDoc(newdocid + ".9", testdocument, SUCCESS, false);
503
            // should not be able to update the document
1169 504
            testdocument = getTestEmlDoc("Testing update from another user",
1170
                                         testEmlInlineBlock1, null, null, null,
1171
                                         getAccessBlock(anotheruser, true,
1172
                true, false, false, false),
505
                                         null, null, null,
506
                                         null, getAccessBlock(anotheruser, true,
507
                                         false, false, true, false),
1173 508
                                         null, null, null, null);
1174
            updateDocid(newdocid + ".7", testdocument, FAILURE, true);
509
            updateDocid(newdocid + ".10", testdocument, FAILURE, true);
1175 510

  
1176
            // or the permissions
511
            // but can chg the permissions
1177 512
            testdocument = getTestEmlDoc("Testing update access block",
1178
                                         testEmlInlineBlock2,
1179
                                         null, null, null, null,
1180
                                         null, null, null, null);
1181
            updateDocid(newdocid + ".7", testdocument, FAILURE, true);
1182

  
1183
            m.logout();
1184
            m.login(username, password);
1185

  
1186
            /////////////////////////////
1187
            // update the document access control - write only
1188
            testdocument = getTestEmlDoc("Testing update access block",
1189
                                         testEmlInlineBlock2,
1190 513
                                         null, null, null,
1191
                                         getAccessBlock(anotheruser, true,
1192
                false, true, false, false),
514
                                         null, getAccessBlock(anotheruser, true,
515
                                         false, false, false, true),
1193 516
                                         null, null, null, null);
1194
            updateDocid(newdocid + ".7", testdocument, SUCCESS, false);
1195
            readDocidWhichEqualsDoc(newdocid + ".7", testdocument, SUCCESS, false);
517
            //updateDocid(newdocid + ".10", testdocument, SUCCESS, false);
1196 518

  
1197
            // check if the user mentioned is able to read the document
1198
            m.logout();
1199
            m.login(anotheruser, anotherpassword);
1200
            readDocidWhichEqualsDoc(newdocid + ".7", testdocument, FAILURE, true);
519
            // try to delete the document
520
            // deleteDocid(newdocid + ".10", FAILURE, true);
521
            deleteDocid(newdocid + ".9", FAILURE, true);
1201 522

  
1202
            // should be able to update the document or the inline data
1203
            testdocument = getTestEmlDoc("Testing update from another user",
1204
                                         testEmlInlineBlock1, null, null, null,
1205
                                         getAccessBlock(anotheruser, true,
1206
                false, true, false, false),
1207
                                         null, null, null, null);
1208
            // ERRRRROR
1209
            //updateDocid(newdocid + ".8", testdocument, SUCCESS, false);
1210

  
1211
            // but not the permissions
1212
            testdocument = getTestEmlDoc("Testing update access block",
1213
                                         testEmlInlineBlock2,
1214
                                         null, null, null, null,
1215
                                         null, null, null, null);
1216
            updateDocid(newdocid + ".9", testdocument, FAILURE, true);
1217

  
1218 523
            m.logout();
1219 524
            m.login(username, password);
1220 525

  
1221
            /////////////////////////////
1222
            // update the document access control - change permission only
1223
            testdocument = getTestEmlDoc("Testing update access block",
1224
                                         testEmlInlineBlock2,
1225
                                         null, null, null,
1226
                                         getAccessBlock(anotheruser, true,
1227
                false, false, true, false),
1228
                                         null, null, null, null);
1229
            updateDocid(newdocid + ".9", testdocument, SUCCESS, false);
1230
            readDocidWhichEqualsDoc(newdocid + ".9", testdocument, SUCCESS, false);
1231 526

  
1232
            // check if the user mentioned is able to read the document
1233
            m.logout();
1234
            m.login(anotheruser, anotherpassword);
1235
            readDocidWhichEqualsDoc(newdocid + ".9", testdocument, FAILURE, true);
1236 527

  
1237
            // should be able to update the document or the inline data
1238
            testdocument = getTestEmlDoc("Testing update from another user",
1239
                                         testEmlInlineBlock1, null, null, null,
1240
                                         getAccessBlock(anotheruser, true,
1241
                false, false, true, false),
1242
                                         null, null, null, null);
1243
            updateDocid(newdocid + ".10", testdocument, FAILURE, true);
1244

  
1245
            // or the permissions
528
            /////////////////////////////////
529
            // update the document access control - read & change permissions
1246 530
            testdocument = getTestEmlDoc("Testing update access block",
1247
                                         testEmlInlineBlock2,
1248
                                         null, null, null, null,
1249
                                         null, null, null, null);
1250
            // ERRROR
1251
            //updateDocid(newdocid + ".10", testdocument, SUCCESS, false);
1252

  
1253
            m.logout();
1254
            m.login(username, password);
1255

  
1256
            /////////////////////////////
1257
            // update the document access control - change permission only
1258
            testdocument = getTestEmlDoc("Testing update access block",
1259
                                         testEmlInlineBlock2,
1260 531
                                         null, null, null,
1261
                                         getAccessBlock(anotheruser, true,
1262
                false, false, false, true),
532
                                         null, getAccessBlock(anotheruser, true,
533
                                         true, false, true, false),
1263 534
                                         null, null, null, null);
1264 535
            updateDocid(newdocid + ".11", testdocument, SUCCESS, false);
1265 536
            readDocidWhichEqualsDoc(newdocid + ".11", testdocument, SUCCESS, false);
......
1267 538
            // check if the user mentioned is able to read the document
1268 539
            m.logout();
1269 540
            m.login(anotheruser, anotherpassword);
1270
            readDocidWhichEqualsDoc(newdocid + ".11", testdocument, SUCCESS, false);
541
            readDocidWhichEqualsDoc(newdocid + ".11", testdocument,  SUCCESS, false);
1271 542

  
1272
            // should be able to update the document or the inline data
543
            // should not be able to update the document
1273 544
            testdocument = getTestEmlDoc("Testing update from another user",
1274
                                         testEmlInlineBlock1, null, null, null,
1275
                                         getAccessBlock(anotheruser, true,
1276
                false, false, false, true),
545
                                         null, null, null,
546
                                         null, getAccessBlock(anotheruser, true,
547
                                         false, false, true, false),
1277 548
                                         null, null, null, null);
1278
            updateDocid(newdocid + ".12", testdocument, SUCCESS, false);
1279

  
1280
            // or the permissions
1281
            testdocument = getTestEmlDoc("Testing update access block",
1282
                                         testEmlInlineBlock2,
1283
                                         null, null, null, null,
549
            updateDocid(newdocid + ".12", testdocument, FAILURE, true);
550
            // but can chg the permissions
551
            testdocument = getTestEmlDoc("Testing update from another user",
552
                                         null, null, null,
553
                                         null, getAccessBlock(anotheruser, true,
554
                                         false, false, false, true),
1284 555
                                         null, null, null, null);
1285
            updateDocid(newdocid + ".13", testdocument, SUCCESS, false);
556
            // ERRRRRRRRRRRRRRRR
557
            // updateDocid(newdocid + ".12", testdocument, SUCCESS, false);
1286 558

  
1287
            m.logout();
1288
            m.login(username, password);
559
            // try to delete the document
560
            //deleteDocid(newdocid + ".12", FAILURE, true);
561
            deleteDocid(newdocid + ".11", FAILURE, true);
1289 562

  
1290
            // delete the document
1291
            deleteDocid(newdocid + ".13", SUCCESS);
1292 563
            m.logout();
1293
        }
1294
        catch (MetacatAuthException mae) {
1295
            fail("Authorization failed:\n" + mae.getMessage());
1296
        }
1297
        catch (MetacatInaccessibleException mie) {
1298
            fail("Metacat Inaccessible:\n" + mie.getMessage());
1299
        }
1300
        catch (Exception e) {
1301
            fail("General exception:\n" + e.getMessage());
1302
        }
1303

  
1304
    }
1305

  
1306
    /** *********
1307
     * Test the case when no access is specified and owner is logged in
1308
     * Only online data is involved
1309
     */
1310
    public void documentWithOnlineDataTest() {
1311
        try {
1312
            newdocid = generateDocid();
1313

  
1314
            // login
1315 564
            m.login(username, password);
1316 565

  
1317
            // upload online document
1318
            onlineDocid = generateDocid();
1319
            uploadDocid(onlineDocid + ".1", onlinetestdatafile2, SUCCESS, false);
1320 566

  
1321
            // try to access the online document from other userid
1322
            m.logout();
1323
            m.login(anotheruser, anotherpassword);
1324
            readDocid(onlineDocid + ".1", FAILURE, true);
1325
            // **************** ERRRRRRRRRROR
1326
            //uploadDocid(onlineDocid + ".2", onlinetestdatafile2, FAILURE, true);
1327

  
1328
            m.logout();
1329
            m.login(username, password);
1330

  
1331
            // insert a document
1332
            testdocument = getTestEmlDoc("Testing insert", null, null,
1333
                                         "ecogrid://knb/" + onlineDocid + ".1",
1334
                                         null, null, null, null, null, null);
1335
            insertDocid(newdocid + ".1", testdocument, SUCCESS, false);
1336
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false);
1337

  
1338
            // update the document
1339
            testdocument = getTestEmlDoc("Testing update", null, null,
1340
                                         "ecogrid://knb/" + onlineDocid + ".1",
1341
                                         null, null, null, null, null, null);
1342
            updateDocid(newdocid + ".2", testdocument, SUCCESS, false);
1343
            readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true);
1344

  
1345
            // update the online data
1346
            uploadDocid(onlineDocid + ".2", onlinetestdatafile2, SUCCESS, false);
1347

  
1348
            //  read document and check if it is same as the document which was written
1349
            //  the second time
1350

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff