Project

General

Profile

« Previous | Next » 

Revision 9084

Added by Jing Tao almost 10 years ago

View differences:

test/edu/ucsb/nceas/metacat/dataone/SIDTest.java
123 123
	    testCase3();
124 124
	    testCase4();
125 125
	    testCase5();
126
	    testCase6();
127
	    testCase7();
128
	    testCase8();
129
	    testCase9();
130
	    testCase10();
131
	    testCase11();
132
	    testCase12();
133
	    testCase13();
126 134
	    testCase14();
127 135
	}
128 136
	
......
324 332
        //System.out.println("The head is "+head.getValue());
325 333
        assertTrue(head2.equals(p3));
326 334
    }
335
    
336
    /**
337
     * case 6. P1(S1) <-> P2(S1) <-> P3(), S1 = P2 (use Rule 3)
338
     */
339
    private void testCase6() throws Exception {
340
        Identifier s1 = new Identifier();
341
        s1.setValue("S1");
342
        Identifier s2 = new Identifier();
343
        s2.setValue("S2");
344
        Identifier p1 = new Identifier();
345
        p1.setValue("P1");
346
        Identifier p2 = new Identifier();
347
        p2.setValue("P2");
348
        Identifier p3 = new Identifier();
349
        p3.setValue("P3");
350
       
351
        
352
        SystemMetadata p1Sys = new SystemMetadata();
353
        p1Sys.setIdentifier(p1);
354
        p1Sys.setSeriesId(s1);
355
        p1Sys.setObsoletedBy(p2);
356
        p1Sys.setDateUploaded(new Date(100));
357
        
358
        SystemMetadata p2Sys = new SystemMetadata();
359
        p2Sys.setIdentifier(p2);
360
        p2Sys.setSeriesId(s1);
361
        p2Sys.setObsoletes(p1);
362
        p2Sys.setObsoletedBy(p3);
363
        p2Sys.setDateUploaded(new Date(200));
364
        
365
        SystemMetadata p3Sys = new SystemMetadata();
366
        p3Sys.setIdentifier(p3);
367
        //p3Sys.setSeriesId(s2);
368
        p3Sys.setObsoletes(p2);
369

  
370
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
371
        chain.add(p1Sys);
372
        chain.add(p2Sys);
373
        chain.add(p3Sys);
374
      
375
        System.out.println("Case 6:");
376
        Identifier head = getHeadVersion(s1, chain);
377
        //System.out.println("The head is "+head.getValue());
378
        assertTrue(head.equals(p2));
379
    }
380
    
381
    /**
382
     * case 7. P1(S1) <-> P2(S1) <-> P3() <-> P4(S2), S1 = P2 (Rule 3), S2 = P4 (Rule 1)
383
     */
384
    private void testCase7() throws Exception {
385
        Identifier s1 = new Identifier();
386
        s1.setValue("S1");
387
        Identifier s2 = new Identifier();
388
        s2.setValue("S2");
389
        Identifier p1 = new Identifier();
390
        p1.setValue("P1");
391
        Identifier p2 = new Identifier();
392
        p2.setValue("P2");
393
        Identifier p3 = new Identifier();
394
        p3.setValue("P3");
395
        Identifier p4 = new Identifier();
396
        p4.setValue("P4");
397
       
398
        
399
        SystemMetadata p1Sys = new SystemMetadata();
400
        p1Sys.setIdentifier(p1);
401
        p1Sys.setSeriesId(s1);
402
        p1Sys.setObsoletedBy(p2);
403
        p1Sys.setDateUploaded(new Date(100));
404
        
405
        SystemMetadata p2Sys = new SystemMetadata();
406
        p2Sys.setIdentifier(p2);
407
        p2Sys.setSeriesId(s1);
408
        p2Sys.setObsoletes(p1);
409
        p2Sys.setObsoletedBy(p3);
410
        p2Sys.setDateUploaded(new Date(200));
411
        
412
        SystemMetadata p3Sys = new SystemMetadata();
413
        p3Sys.setIdentifier(p3);
414
        //p3Sys.setSeriesId(s2);
415
        p3Sys.setObsoletes(p2);
416
        p3Sys.setObsoletedBy(p4);
417
        
418
        SystemMetadata p4Sys = new SystemMetadata();
419
        p4Sys.setIdentifier(p4);
420
        p4Sys.setSeriesId(s2);
421
        p4Sys.setObsoletes(p3);
422

  
423
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
424
        chain.add(p1Sys);
425
        chain.add(p2Sys);
426
        chain.add(p3Sys);
427
        chain.add(p4Sys);
428
      
429
        System.out.println("Case 7:");
430
        Identifier head = getHeadVersion(s1, chain);
431
        //System.out.println("The head is "+head.getValue());
432
        assertTrue(head.equals(p2));
433
        Identifier head2 = getHeadVersion(s2, chain);
434
        //System.out.println("The head is "+head.getValue());
435
        assertTrue(head2.equals(p4));
436
    }
437
    
438
    /**
439
     * case 8. P1(S1) <-> P2(S1) ->  ??  <- P4(S1), S1 = P4, (Rule 1) (Error, but will happen)
440
     */
441
    private void testCase8() throws Exception {
442
        Identifier s1 = new Identifier();
443
        s1.setValue("S1");
444
        Identifier s2 = new Identifier();
445
        s2.setValue("S2");
446
        Identifier p1 = new Identifier();
447
        p1.setValue("P1");
448
        Identifier p2 = new Identifier();
449
        p2.setValue("P2");
450
        Identifier p3 = new Identifier();
451
        p3.setValue("P3");
452
        Identifier p4 = new Identifier();
453
        p4.setValue("P4");
454
       
455
        
456
        SystemMetadata p1Sys = new SystemMetadata();
457
        p1Sys.setIdentifier(p1);
458
        p1Sys.setSeriesId(s1);
459
        p1Sys.setObsoletedBy(p2);
460
        p1Sys.setDateUploaded(new Date(100));
461
        
462
        SystemMetadata p2Sys = new SystemMetadata();
463
        p2Sys.setIdentifier(p2);
464
        p2Sys.setSeriesId(s1);
465
        p2Sys.setObsoletes(p1);
466
        p2Sys.setObsoletedBy(p3);
467
        p2Sys.setDateUploaded(new Date(200));
468
        
469
        
470
        SystemMetadata p4Sys = new SystemMetadata();
471
        p4Sys.setIdentifier(p4);
472
        p4Sys.setSeriesId(s1);
473
        p4Sys.setObsoletes(p3);
474

  
475
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
476
        chain.add(p1Sys);
477
        chain.add(p2Sys);
478
        chain.add(p4Sys);
479
      
480
        System.out.println("Case 8:");
481
        Identifier head = getHeadVersion(s1, chain);
482
        //System.out.println("The head is "+head.getValue());
483
        assertTrue(head.equals(p4));
484
    }
485
    
486
    /**
487
     * case 9. P1(S1) <-> P2(S1)  ??  <- P4(S1), S1 = P4 (Rule 2) (??: object was not synchronized)
488
     */
489
    private void testCase9() throws Exception {
490
        Identifier s1 = new Identifier();
491
        s1.setValue("S1");
492
        Identifier s2 = new Identifier();
493
        s2.setValue("S2");
494
        Identifier p1 = new Identifier();
495
        p1.setValue("P1");
496
        Identifier p2 = new Identifier();
497
        p2.setValue("P2");
498
        Identifier p3 = new Identifier();
499
        p3.setValue("P3");
500
        Identifier p4 = new Identifier();
501
        p4.setValue("P4");
502
       
503
        
504
        SystemMetadata p1Sys = new SystemMetadata();
505
        p1Sys.setIdentifier(p1);
506
        p1Sys.setSeriesId(s1);
507
        p1Sys.setObsoletedBy(p2);
508
        p1Sys.setDateUploaded(new Date(100));
509
        
510
        SystemMetadata p2Sys = new SystemMetadata();
511
        p2Sys.setIdentifier(p2);
512
        p2Sys.setSeriesId(s1);
513
        p2Sys.setObsoletes(p1);
514
        p2Sys.setDateUploaded(new Date(200));
515
        
516
        
517
        SystemMetadata p4Sys = new SystemMetadata();
518
        p4Sys.setIdentifier(p4);
519
        p4Sys.setSeriesId(s1);
520
        p4Sys.setObsoletes(p3);
521
        p4Sys.setDateUploaded(new Date(400));
522

  
523
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
524
        chain.add(p1Sys);
525
        chain.add(p2Sys);
526
        chain.add(p4Sys);
527
      
528
        System.out.println("Case 9:");
529
        Identifier head = getHeadVersion(s1, chain);
530
        //System.out.println("The head is "+head.getValue());
531
        assertTrue(head.equals(p4));
532
    }
533
    
534
    /**
535
     * case 10: P1(S1) <-> P2(S1) ->  XX  <- P4(S1), S1 = P4, (Rule 1) (XX: object P3 was deleted)
536
     */
537
    private void testCase10() throws Exception {
538
        Identifier s1 = new Identifier();
539
        s1.setValue("S1");
540
        Identifier s2 = new Identifier();
541
        s2.setValue("S2");
542
        Identifier p1 = new Identifier();
543
        p1.setValue("P1");
544
        Identifier p2 = new Identifier();
545
        p2.setValue("P2");
546
        Identifier p3 = new Identifier();
547
        p3.setValue("P3");
548
        Identifier p4 = new Identifier();
549
        p4.setValue("P4");
550
       
551
        
552
        SystemMetadata p1Sys = new SystemMetadata();
553
        p1Sys.setIdentifier(p1);
554
        p1Sys.setSeriesId(s1);
555
        p1Sys.setObsoletedBy(p2);
556
        p1Sys.setDateUploaded(new Date(100));
557
        
558
        SystemMetadata p2Sys = new SystemMetadata();
559
        p2Sys.setIdentifier(p2);
560
        p2Sys.setSeriesId(s1);
561
        p2Sys.setObsoletes(p1);
562
        p2Sys.setObsoletedBy(p3);
563
        p2Sys.setDateUploaded(new Date(200));
564
        
565
        
566
        SystemMetadata p4Sys = new SystemMetadata();
567
        p4Sys.setIdentifier(p4);
568
        p4Sys.setSeriesId(s1);
569
        p4Sys.setObsoletes(p3);
570
        p4Sys.setDateUploaded(new Date(400));
571

  
572
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
573
        chain.add(p1Sys);
574
        chain.add(p2Sys);
575
        chain.add(p4Sys);
576
      
577
        System.out.println("Case 10:");
578
        Identifier head = getHeadVersion(s1, chain);
579
        //System.out.println("The head is "+head.getValue());
580
        assertTrue(head.equals(p4));
581
    }
582
    
583
    /**
584
     * case 11: P1(S1) <-> P2(S1) <-> [archived:P3(S1)], S1 = P3, (Rule 1) 
585
     */
586
    private void testCase11() throws Exception {
587
        Identifier s1 = new Identifier();
588
        s1.setValue("S1");
589
        Identifier s2 = new Identifier();
590
        s2.setValue("S2");
591
        Identifier p1 = new Identifier();
592
        p1.setValue("P1");
593
        Identifier p2 = new Identifier();
594
        p2.setValue("P2");
595
        Identifier p3 = new Identifier();
596
        p3.setValue("P3");
597
        Identifier p4 = new Identifier();
598
        p4.setValue("P4");
599
       
600
        
601
        SystemMetadata p1Sys = new SystemMetadata();
602
        p1Sys.setIdentifier(p1);
603
        p1Sys.setSeriesId(s1);
604
        p1Sys.setObsoletedBy(p2);
605
        p1Sys.setDateUploaded(new Date(100));
606
        
607
        SystemMetadata p2Sys = new SystemMetadata();
608
        p2Sys.setIdentifier(p2);
609
        p2Sys.setSeriesId(s1);
610
        p2Sys.setObsoletes(p1);
611
        p2Sys.setObsoletedBy(p3);
612
        p2Sys.setDateUploaded(new Date(200));
613
        
614
        
615
        SystemMetadata p3Sys = new SystemMetadata();
616
        p3Sys.setIdentifier(p3);
617
        p3Sys.setSeriesId(s1);
618
        p3Sys.setObsoletes(p2);
619
        p3Sys.setArchived(true);
620
        p3Sys.setDateUploaded(new Date(300));
621
        
622

  
623
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
624
        chain.add(p1Sys);
625
        chain.add(p2Sys);
626
        chain.add(p3Sys);
627
      
628
        System.out.println("Case 11:");
629
        Identifier head = getHeadVersion(s1, chain);
630
        //System.out.println("The head is "+head.getValue());
631
        assertTrue(head.equals(p3));
632
    }
633
    
634
    /**
635
     * case 12. P1(S1) <-> P2(S1) -> ??, S1 = P2, (Rule 4) (Error, but will happen)
636
     * @throws Exception
637
     */
638
    private void testCase12() throws Exception {
639
        Identifier s1 = new Identifier();
640
        s1.setValue("S1");
641
        Identifier s2 = new Identifier();
642
        s2.setValue("S2");
643
        Identifier p1 = new Identifier();
644
        p1.setValue("P1");
645
        Identifier p2 = new Identifier();
646
        p2.setValue("P2");
647
        Identifier p3 = new Identifier();
648
        p3.setValue("P3");
649
        
650
        SystemMetadata p1Sys = new SystemMetadata();
651
        p1Sys.setIdentifier(p1);
652
        p1Sys.setSeriesId(s1);
653
        p1Sys.setObsoletedBy(p2);
654
        p1Sys.setDateUploaded(new Date(100));
655
        
656
        SystemMetadata p2Sys = new SystemMetadata();
657
        p2Sys.setIdentifier(p2);
658
        p2Sys.setSeriesId(s1);
659
        p2Sys.setObsoletes(p1);
660
        p2Sys.setObsoletedBy(p3);
661
        p2Sys.setDateUploaded(new Date(200));
662
        
663

  
664
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
665
        chain.add(p1Sys);
666
        chain.add(p2Sys);
667

  
668
        System.out.println("Case 12:");
669
        Identifier head = getHeadVersion(s1, chain);
670
        //System.out.println("The head is "+head.getValue());
671
        assertTrue(head.equals(p2));
672
    }
673
    
674
    /**
675
     * case 13. P1(S1) <- P2(S1) -> ??, S1 = P2
676
     * @throws Exception
677
     */
678
    private void testCase13() throws Exception {
679
        Identifier s1 = new Identifier();
680
        s1.setValue("S1");
681
        Identifier s2 = new Identifier();
682
        s2.setValue("S2");
683
        Identifier p1 = new Identifier();
684
        p1.setValue("P1");
685
        Identifier p2 = new Identifier();
686
        p2.setValue("P2");
687
        Identifier p3 = new Identifier();
688
        p3.setValue("P3");
689
        
690
        SystemMetadata p1Sys = new SystemMetadata();
691
        p1Sys.setIdentifier(p1);
692
        p1Sys.setSeriesId(s1);
693
        p1Sys.setDateUploaded(new Date(100));
694
        
695
        SystemMetadata p2Sys = new SystemMetadata();
696
        p2Sys.setIdentifier(p2);
697
        p2Sys.setSeriesId(s1);
698
        p2Sys.setObsoletes(p1);
699
        p2Sys.setObsoletedBy(p3);
700
        p2Sys.setDateUploaded(new Date(200));
701
        
702

  
703
        Vector<SystemMetadata> chain = new Vector<SystemMetadata>();
704
        chain.add(p1Sys);
705
        chain.add(p2Sys);
706
      
707
        
708
        System.out.println("Case 13:");
709
        Identifier head = getHeadVersion(s1, chain);
710
        //System.out.println("The head is "+head.getValue());
711
        assertTrue(head.equals(p2));
712
    }
327 713
	
328 714
	/**
329 715
	 * Case 14: P1(S1) <- P2(S1) -> P3(S2).
......
563 949
	                         break;
564 950
	                     } else if (sidOfObsoletedBy == null ) {
565 951
	                         //rule 3, If everything in {S1} is obsoleted, then select object that is obsoleted by another object that does not have the same SID (this case, no sid)
566
	                         System.out.println("rule 3-2 (close without sid");
952
	                         System.out.println("rule 3-2 (close without sid)");
567 953
	                         pid = sysmeta.getIdentifier();
568 954
	                         break;
569 955
	                     }

Also available in: Unified diff