Project

General

Profile

« Previous | Next » 

Revision 9127

Added by Jing Tao almost 10 years ago

Add more test cases for the method getHeadVersion.

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
250 250
    public void testGetHeadPID() {
251 251
        
252 252
        try {
253
            //insert test documents with a series id
253
            //case-1  P1(S1) <-> P2(S1), S1 = P2 (Type 1)
254 254
            Session session = getTestSession();
255 255
            Identifier guid = new Identifier();
256 256
            guid.setValue(generateDocumentId());
......
291 291
            non_exist_sid.setValue("no-sid-exist-123qwe");
292 292
            assertTrue(IdentifierManager.getInstance().getHeadPID(non_exist_sid) == null);
293 293
            
294
            //case-2
294
            //case-2 P1(S1) ? P2(S1), S1 = P2
295 295
            // http://jenkins-1.dataone.org/documentation/unstable/API-Documentation-development/design/ContentMutability.html
296 296
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
297 297
            Identifier pid1_case2 = new Identifier();
......
316 316
            }
317 317
            
318 318
            
319
            //case-3
319
            //case-3  P1(S1) <- P2(S1), S1 = P2, Discouraged, but not error condition, S1 = P2 (P1 and P2 are type 1 ends, not an ideal chain )
320 320
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
321 321
            Identifier pid1_case3 = new Identifier();
322 322
            pid1_case3.setValue(generateDocumentId());
......
339 339
            head = IdentifierManager.getInstance().getHeadPID(sid_case3);
340 340
            assertTrue(head.equals(pid2_case3));
341 341
            
342
            //case-4
342
            //case-4 P1(S1) <-> P2(S1) <-> P3(S2), S1 = P2 (Type 2), S2 = P3 (Type 1)
343 343
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
344 344
            Identifier pid1_case4 = new Identifier();
345 345
            pid1_case4.setValue(generateDocumentId());
......
383 383
            assertTrue(head.equals(pid3_case4));
384 384
            
385 385
            
386
            //case-5
386
            //case-5 P1(S1) <- P2(S1) <- P3(S2), S1 = P2 (P1 and P2 are type 1 ends, not an ideal chain), S2 = P3 (Type 1)
387 387
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
388 388
            Identifier pid1_case5 = new Identifier();
389 389
            pid1_case5.setValue(generateDocumentId());
......
420 420
            assertTrue(head.equals(pid3_case5));
421 421
            
422 422
            
423
            //case-6
423
            //case-6 P1(S1) <-> P2(S1) <-> P3(), S1 = P2 (Type 2)
424 424
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
425 425
            Identifier pid1_case6 = new Identifier();
426 426
            pid1_case6.setValue(generateDocumentId());
......
458 458
            assertTrue(head.equals(pid2_case6));
459 459
            
460 460
            
461
            //case-7
461
            //case-7 P1(S1) <-> P2(S1) <-> P3() <-> P4(S2), S1 = P2 (Type 2), S2 = P4 (Type 1)
462 462
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
463 463
            Identifier pid1_case7 = new Identifier();
464 464
            pid1_case7.setValue(generateDocumentId());
......
510 510
            assertTrue(head.equals(pid2_case7));
511 511
            head = IdentifierManager.getInstance().getHeadPID(sid2_case7);
512 512
            assertTrue(head.equals(pid4_case7));
513
            
514
            
515
            //case-8  P1(S1) <-> P2(S1) -> ?? <- P4(S1), S1 = P4, (Type 1) (Error, but will happen)
516
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
517
            Identifier pid1_case8 = new Identifier();
518
            pid1_case8.setValue(generateDocumentId());
519
            Identifier sid_case8 = new Identifier();
520
            sid_case8.setValue("sid."+System.nanoTime());
521
            SystemMetadata sysmeta_case8 = createSystemMetadata(pid1_case8, session.getSubject(), object);
522
            sysmeta_case8.setSeriesId(sid_case8);
523
            CNodeService.getInstance(request).create(session, pid1_case8, object, sysmeta_case8);
524
            
525
            Thread.sleep(1000);
526
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
527
            Identifier pid2_case8 = new Identifier();
528
            pid2_case8.setValue(generateDocumentId());
529
            SystemMetadata sysmeta2_case8 = createSystemMetadata(pid2_case8, session.getSubject(), object);
530
            sysmeta2_case8.setSeriesId(sid_case8);
531
            sysmeta2_case8.setObsoletes(pid1_case8);
532
            CNodeService.getInstance(request).create(session, pid2_case8, object, sysmeta2_case8);
533
            
534
            sysmeta_case8.setObsoletedBy(pid2_case8);
535
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case8, sysmeta_case8);
536
            
537
            Thread.sleep(1000);
538
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
539
            Identifier pid3_case8 = new Identifier();
540
            pid3_case8.setValue(generateDocumentId());
541
            SystemMetadata sysmeta3_case8 = createSystemMetadata(pid3_case8, session.getSubject(), object);
542
            sysmeta3_case8.setObsoletes(pid2_case8);
543
            sysmeta3_case8.setSeriesId(sid_case8);
544
            CNodeService.getInstance(request).create(session, pid3_case8, object, sysmeta3_case8);
545
            
546
            sysmeta2_case8.setObsoletedBy(pid3_case8);
547
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case8, sysmeta2_case8);
548
            
549
            Thread.sleep(1000);
550
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
551
            Identifier pid4_case8 = new Identifier();
552
            pid4_case8.setValue(generateDocumentId());
553
            //Identifier sid2_case7 = new Identifier();
554
            //sid2_case7.setValue("sid."+System.nanoTime());
555
            SystemMetadata sysmeta4_case8 = createSystemMetadata(pid4_case8, session.getSubject(), object);
556
            sysmeta4_case8.setObsoletes(pid3_case8);
557
            sysmeta4_case8.setSeriesId(sid_case8);
558
            CNodeService.getInstance(request).create(session, pid4_case8, object, sysmeta4_case8);
559
            
560
            //delete pid3_case8 
561
            CNodeService.getInstance(request).delete(session, pid3_case8);
562
            try {
563
                CNodeService.getInstance(request).getSystemMetadata(session, pid3_case8);
564
                fail("The pid "+pid3_case8.getValue()+" should be deleted.");
565
            } catch (NotFound e) {
566
                //e.printStackTrace();
567
                assertTrue(true);
568
            }
569
            System.out.println("case 8: =======");
570
            head = IdentifierManager.getInstance().getHeadPID(sid_case8);
571
            assertTrue(head.equals(pid4_case8));
572
            
573
            
574
            //case-9  P1(S1) <-> P2(S1) ?? <- P4(S1), S1 = P4 (P2 and P4 are type 1 ends, not an ideal chain)
575
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
576
            Identifier pid1_case9 = new Identifier();
577
            pid1_case9.setValue(generateDocumentId());
578
            Identifier sid_case9 = new Identifier();
579
            sid_case9.setValue("sid."+System.nanoTime());
580
            SystemMetadata sysmeta_case9 = createSystemMetadata(pid1_case9, session.getSubject(), object);
581
            sysmeta_case9.setSeriesId(sid_case9);
582
            CNodeService.getInstance(request).create(session, pid1_case9, object, sysmeta_case9);
583
            
584
            Thread.sleep(1000);
585
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
586
            Identifier pid2_case9 = new Identifier();
587
            pid2_case9.setValue(generateDocumentId());
588
            SystemMetadata sysmeta2_case9 = createSystemMetadata(pid2_case9, session.getSubject(), object);
589
            sysmeta2_case9.setSeriesId(sid_case9);
590
            sysmeta2_case9.setObsoletes(pid1_case9);
591
            CNodeService.getInstance(request).create(session, pid2_case9, object, sysmeta2_case9);
592
            
593
            sysmeta_case9.setObsoletedBy(pid2_case9);
594
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case9, sysmeta_case9);
595
            //check
596
            SystemMetadata meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case9);
597
            assertTrue(meta.getObsoletedBy().equals(pid2_case9));
598
            
599
            Thread.sleep(1000);
600
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
601
            Identifier pid3_case9 = new Identifier();
602
            pid3_case9.setValue(generateDocumentId());
603
            SystemMetadata sysmeta3_case9 = createSystemMetadata(pid3_case9, session.getSubject(), object);
604
            sysmeta3_case9.setObsoletes(pid2_case9);
605
            sysmeta3_case9.setSeriesId(sid_case9);
606
            CNodeService.getInstance(request).create(session, pid3_case9, object, sysmeta3_case9);
607
            
608
            //sysmeta2_case8.setObsoletedBy(pid3_case8);
609
            //CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case8, sysmeta2_case8);
610
            
611
            Thread.sleep(1000);
612
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
613
            Identifier pid4_case9 = new Identifier();
614
            pid4_case9.setValue(generateDocumentId());
615
            //Identifier sid2_case7 = new Identifier();
616
            //sid2_case7.setValue("sid."+System.nanoTime());
617
            SystemMetadata sysmeta4_case9 = createSystemMetadata(pid4_case9, session.getSubject(), object);
618
            sysmeta4_case9.setObsoletes(pid3_case9);
619
            sysmeta4_case9.setSeriesId(sid_case9);
620
            CNodeService.getInstance(request).create(session, pid4_case9, object, sysmeta4_case9);
621
            
622
            //delete pid3_case8 
623
            CNodeService.getInstance(request).delete(session, pid3_case9);
624
            try {
625
                CNodeService.getInstance(request).getSystemMetadata(session, pid3_case9);
626
                fail("The pid "+pid3_case9.getValue()+" should be deleted.");
627
            } catch (NotFound e) {
628
                //e.printStackTrace();
629
                assertTrue(true);
630
            }
631
            System.out.println("case 9: =======");
632
            head = IdentifierManager.getInstance().getHeadPID(sid_case9);
633
            assertTrue(head.equals(pid4_case9));
634
            
635
            
636
            //case-10   P1(S1) <-> P2(S1) -> XX <- P4(S1), S1 = P4, (Type 1) 
637
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
638
            Identifier pid1_case10 = new Identifier();
639
            pid1_case10.setValue(generateDocumentId());
640
            Identifier sid_case10 = new Identifier();
641
            sid_case10.setValue("sid."+System.nanoTime());
642
            SystemMetadata sysmeta_case10 = createSystemMetadata(pid1_case10, session.getSubject(), object);
643
            sysmeta_case10.setSeriesId(sid_case10);
644
            CNodeService.getInstance(request).create(session, pid1_case10, object, sysmeta_case10);
645
            
646
            Thread.sleep(1000);
647
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
648
            Identifier pid2_case10 = new Identifier();
649
            pid2_case10.setValue(generateDocumentId());
650
            SystemMetadata sysmeta2_case10 = createSystemMetadata(pid2_case10, session.getSubject(), object);
651
            sysmeta2_case10.setSeriesId(sid_case10);
652
            sysmeta2_case10.setObsoletes(pid1_case10);
653
            CNodeService.getInstance(request).create(session, pid2_case10, object, sysmeta2_case10);
654
            
655
            sysmeta_case10.setObsoletedBy(pid2_case10);
656
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case10, sysmeta_case10);
657
            //check
658
            meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case10);
659
            assertTrue(meta.getObsoletedBy().equals(pid2_case10));
660
            
661
            Thread.sleep(1000);
662
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
663
            Identifier pid3_case10 = new Identifier();
664
            pid3_case10.setValue(generateDocumentId());
665
            SystemMetadata sysmeta3_case10 = createSystemMetadata(pid3_case10, session.getSubject(), object);
666
            sysmeta3_case10.setObsoletes(pid2_case10);
667
            sysmeta3_case10.setSeriesId(sid_case10);
668
            CNodeService.getInstance(request).create(session, pid3_case10, object, sysmeta3_case10);
669
            
670
            sysmeta2_case10.setObsoletedBy(pid3_case10);
671
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case10, sysmeta2_case10);
672
            
673
            Thread.sleep(1000);
674
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
675
            Identifier pid4_case10 = new Identifier();
676
            pid4_case10.setValue(generateDocumentId());
677
            //Identifier sid2_case7 = new Identifier();
678
            //sid2_case7.setValue("sid."+System.nanoTime());
679
            SystemMetadata sysmeta4_case10 = createSystemMetadata(pid4_case10, session.getSubject(), object);
680
            sysmeta4_case10.setObsoletes(pid3_case10);
681
            sysmeta4_case10.setSeriesId(sid_case10);
682
            CNodeService.getInstance(request).create(session, pid4_case10, object, sysmeta4_case10);
683
            
684
            //delete pid3_case10 
685
            CNodeService.getInstance(request).delete(session, pid3_case10);
686
            try {
687
                CNodeService.getInstance(request).getSystemMetadata(session, pid3_case10);
688
                fail("The pid "+pid3_case10.getValue()+" should be deleted.");
689
            } catch (NotFound e) {
690
                //e.printStackTrace();
691
                assertTrue(true);
692
            }
693
            System.out.println("case 10: =======");
694
            head = IdentifierManager.getInstance().getHeadPID(sid_case10);
695
            assertTrue(head.equals(pid4_case10));
696
            
697
            
698
            //case-11   P1(S1) <-> P2(S1) <-> [archived:P3(S1)], S1 = P3, (Type 1)
699
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
700
            Identifier pid1_case11 = new Identifier();
701
            pid1_case11.setValue(generateDocumentId());
702
            Identifier sid_case11 = new Identifier();
703
            sid_case11.setValue("sid."+System.nanoTime());
704
            SystemMetadata sysmeta_case11 = createSystemMetadata(pid1_case11, session.getSubject(), object);
705
            sysmeta_case11.setSeriesId(sid_case11);
706
            CNodeService.getInstance(request).create(session, pid1_case11, object, sysmeta_case11);
707
            
708
            Thread.sleep(1000);
709
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
710
            Identifier pid2_case11 = new Identifier();
711
            pid2_case11.setValue(generateDocumentId());
712
            SystemMetadata sysmeta2_case11 = createSystemMetadata(pid2_case11, session.getSubject(), object);
713
            sysmeta2_case11.setSeriesId(sid_case11);
714
            sysmeta2_case11.setObsoletes(pid1_case11);
715
            CNodeService.getInstance(request).create(session, pid2_case11, object, sysmeta2_case11);
716
            
717
            sysmeta_case11.setObsoletedBy(pid2_case11);
718
            CNodeService.getInstance(request).updateSystemMetadata(session, pid1_case11, sysmeta_case11);
719
            //check
720
            meta = CNodeService.getInstance(request).getSystemMetadata(session, pid1_case11);
721
            assertTrue(meta.getObsoletedBy().equals(pid2_case11));
722
            
723
            Thread.sleep(1000);
724
            object = new ByteArrayInputStream("test".getBytes("UTF-8"));
725
            Identifier pid3_case11 = new Identifier();
726
            pid3_case11.setValue(generateDocumentId());
727
            SystemMetadata sysmeta3_case11 = createSystemMetadata(pid3_case11, session.getSubject(), object);
728
            sysmeta3_case11.setObsoletes(pid2_case11);
729
            sysmeta3_case11.setSeriesId(sid_case11);
730
            CNodeService.getInstance(request).create(session, pid3_case11, object, sysmeta3_case11);
731
            
732
            sysmeta2_case11.setObsoletedBy(pid3_case11);
733
            CNodeService.getInstance(request).updateSystemMetadata(session, pid2_case11, sysmeta2_case11);
734
            
735
            //archive pid3_case11 
736
            CNodeService.getInstance(request).archive(session, pid3_case11);
737
            meta =  CNodeService.getInstance(request).getSystemMetadata(session, pid3_case11);
738
            assertTrue(meta.getArchived());
739
            System.out.println("case 11: =======");
740
            head = IdentifierManager.getInstance().getHeadPID(sid_case11);
741
            assertTrue(head.equals(pid3_case11));
513 742
         
514 743
        } catch (Exception e) {
515 744
            e.printStackTrace();

Also available in: Unified diff