Project

General

Profile

« Previous | Next » 

Revision 88b4ec59

Added by Patrick Plitzner over 9 years ago

  • extracted deepDelete tests to own java class
    • reduced exception logged in DeleteResult

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceTest.java
74 74
 */
75 75
public class OccurrenceServiceTest extends CdmTransactionalIntegrationTest {
76 76

  
77
    private static final UUID FIELD_UNIT_UUID = UUID.fromString("b5f58da5-4442-4001-9d13-33f41518b72a");
78
    private static final UUID DERIVED_UNIT_UUID = UUID.fromString("448be6e7-f19c-4a10-9a0a-97aa005f817d");
79
    private static final UUID DNA_SAMPLE_UUID = UUID.fromString("bee4212b-aff1-484e-845f-065c7d6216af");
80
    private static final UUID SEQUENCE_UUID = UUID.fromString("0b867369-de8c-4837-a708-5b7d9f6091be");
81
    private static final UUID TAXON_UUID = UUID.fromString("e93b3840-326c-446e-89f1-a7611f17c0e8");
82
    private static final UUID TAXON_DESCRIPTION_UUID = UUID.fromString("a87a893e-2ea8-427d-a26b-dbd2515d6b8a");
83
    private static final UUID BOTANICAL_NAME_UUID = UUID.fromString("a604774e-d66a-4d47-b9d1-d0e38a8c787a");
84

  
85 77
    @SuppressWarnings("unused")
86 78
    private static final Logger logger = Logger.getLogger(OccurrenceServiceTest.class);
87 79

  
......
244 236
    @Test
245 237
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testDeleteIndividualAssociatedAndTypeSpecimen.xml")
246 238
    public void testDeleteIndividualAssociatedAndTypeSpecimen(){
247
//        //how the XML was generated
239
        final UUID taxonDEscriptionUuid = UUID.fromString("a87a893e-2ea8-427d-a26b-dbd2515d6b8a");
240
        final UUID botanicalNameUuid = UUID.fromString("a604774e-d66a-4d47-b9d1-d0e38a8c787a");
241
        final UUID fieldUnitUuid = UUID.fromString("67e81ca8-ff91-4df6-bf48-e4600c7f15a2");
242
        final UUID derivedUnitUuid = UUID.fromString("d229713b-0123-4f15-bffc-76ae45c37564");
243

  
244
        //        //how the XML was generated
248 245
//        FieldUnit fieldUnit = FieldUnit.NewInstance();
249
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
246
//        fieldUnit.setUuid(fieldUnitUuid);
250 247
//        //sub derivates (DerivedUnit, DnaSample)
251 248
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
252
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
249
//        derivedUnit.setUuid(derivedUnitUuid);
253 250
//
254 251
//        //derivation events
255
//        DerivationEvent derivationEventFUtoDU = DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
252
//        DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
256 253
//
257 254
//        occurrenceService.save(fieldUnit);
258 255
//        occurrenceService.save(derivedUnit);
......
269 266
//        // IndividualsAssociations and a "described" voucher specimen, and an
270 267
//        // empty one)
271 268
//        Taxon taxon = Taxon.NewInstance(name, null);
272
//        taxon.setUuid(TAXON_UUID);
269
//        taxon.setUuid(taxonUuid);
273 270
//        TaxonDescription taxonDescription = TaxonDescription.NewInstance();
274 271
//        taxonDescription.setUuid(TAXON_DESCRIPTION_UUID);
275 272
//        //add voucher
......
307 304
//            e.printStackTrace();
308 305
//        }
309 306

  
310
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
311
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
312
        BotanicalName name = (BotanicalName) nameService.load(BOTANICAL_NAME_UUID);
313
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(TAXON_DESCRIPTION_UUID);
307
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(fieldUnitUuid);
308
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(derivedUnitUuid);
309
        BotanicalName name = (BotanicalName) nameService.load(botanicalNameUuid);
310
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(taxonDEscriptionUuid);
314 311
        //check initial state (IndividualsAssociation)
315 312
        DescriptionElementBase descriptionElement = taxonDescription.getElements().iterator().next();
316 313
        assertTrue("wrong type of description element", descriptionElement.isInstanceOf(IndividualsAssociation.class));
317 314
        assertEquals("associated specimen is incorrect", associatedFieldUnit, ((IndividualsAssociation)descriptionElement).getAssociatedSpecimenOrObservation());
318 315
        //check initial state (Type Designation)
319 316
        Set<TypeDesignationBase> typeDesignations = name.getTypeDesignations();
320
        TypeDesignationBase typeDesignation = typeDesignations.iterator().next();
317
        TypeDesignationBase<?> typeDesignation = typeDesignations.iterator().next();
321 318
        assertTrue("wrong type of type designation", typeDesignation.isInstanceOf(SpecimenTypeDesignation.class));
322 319
        assertEquals("type specimen is incorrect", typeSpecimen, ((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen());
323 320

  
......
348 345
    }
349 346

  
350 347
    @Test
351
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testDeleteDerivateHierarchyStepByStep.xml")
352
    public void testDeepDelete_FieldUnit(){
353
        String assertMessage = "Incorrect number of specimens after deletion.";
354
        DeleteResult deleteResult = null;
355
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
356
        config.setDeleteMolecularData(true);
357
        config.setDeleteChildren(true);
358

  
359
        FieldUnit fieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
360
        DnaSample dnaSample = (DnaSample) occurrenceService.load(DNA_SAMPLE_UUID);
361

  
362
        //check initial state
363
        assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
364
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
365
        assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
366
        assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
367
        assertEquals("incorrect number of amplification results", 1, dnaSample.getAmplificationResults().size());
368
        assertEquals("number of sequences incorrect", 1, dnaSample.getSequences().size());
369
        assertEquals("incorrect number of single reads", 1, dnaSample.getAmplificationResults().iterator().next().getSingleReads().size());
370

  
371
        //delete field unit
372
        deleteResult = occurrenceService.deleteDerivateHierarchy(fieldUnit, config);
373
        assertTrue(deleteResult.toString(), deleteResult.isOk());
374
        assertEquals(assertMessage, 0, occurrenceService.count(SpecimenOrObservationBase.class));
375
        assertEquals(assertMessage, 0, occurrenceService.count(FieldUnit.class));
376
        assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
377
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
378
    }
379

  
380
    @Test
381
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testDeleteDerivateHierarchyStepByStep.xml")
382
    public void testDeepDelete_DerivedUnit(){
383
        String assertMessage = "Incorrect number of specimens after deletion.";
384
        DeleteResult deleteResult = null;
385
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
386
        config.setDeleteMolecularData(true);
387
        config.setDeleteChildren(true);
388

  
389
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
390
        DnaSample dnaSample = (DnaSample) occurrenceService.load(DNA_SAMPLE_UUID);
391

  
392
        //check initial state
393
        assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
394
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
395
        assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
396
        assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
397
        assertEquals("incorrect number of amplification results", 1, dnaSample.getAmplificationResults().size());
398
        assertEquals("number of sequences incorrect", 1, dnaSample.getSequences().size());
399
        assertEquals("incorrect number of single reads", 1, dnaSample.getAmplificationResults().iterator().next().getSingleReads().size());
400

  
401
        //delete derived unit
402
        deleteResult = occurrenceService.deleteDerivateHierarchy(derivedUnit, config);
403
        assertTrue(deleteResult.toString(), deleteResult.isOk());
404
        assertEquals(assertMessage, 1, occurrenceService.count(SpecimenOrObservationBase.class));
405
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
406
        assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
407
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
408
    }
409

  
410
    @Test
411
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testDeleteDerivateHierarchyStepByStep.xml")
412
    public void testDeepDelete_DnaSample(){
413
        String assertMessage = "Incorrect number of specimens after deletion.";
414
        DeleteResult deleteResult = null;
415
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
416
        config.setDeleteMolecularData(true);
417
        config.setDeleteChildren(true);
418

  
419
        DnaSample dnaSample = (DnaSample) occurrenceService.load(DNA_SAMPLE_UUID);
420

  
421
        //check initial state
422
        assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
423
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
424
        assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
425
        assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
426
        assertEquals("incorrect number of amplification results", 1, dnaSample.getAmplificationResults().size());
427
        assertEquals("number of sequences incorrect", 1, dnaSample.getSequences().size());
428
        assertEquals("incorrect number of single reads", 1, dnaSample.getAmplificationResults().iterator().next().getSingleReads().size());
429

  
430
        //delete dna sample
431
        deleteResult = occurrenceService.deleteDerivateHierarchy(dnaSample, config);
432
        assertTrue(deleteResult.toString(), deleteResult.isOk());
433
        assertEquals(assertMessage, 2, occurrenceService.count(SpecimenOrObservationBase.class));
434
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
435
        assertEquals(assertMessage, 1, occurrenceService.count(DerivedUnit.class));
436
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
437
    }
438

  
439

  
440
    @Test
441
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testDeleteDerivateHierarchyStepByStep.xml")
442
    public void testDeleteDerivateHierarchyStepByStep(){
443
//        //how the XML was generated
444
//        FieldUnit fieldUnit = FieldUnit.NewInstance();
445
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
446
//        //sub derivates (DerivedUnit, DnaSample)
447
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
448
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
449
//        DnaSample dnaSample = DnaSample.NewInstance();
450
//        dnaSample.setUuid(DNA_SAMPLE_UUID);
451
//
452
//        //derivation events
453
//        DerivationEvent derivationEventFUtoDU = DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
454
//        DerivationEvent derivationEventDUtoDNA = DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
455
//
456
//        //DNA (Sequence, SingleRead, Amplification)
457
//        Sequence sequence = Sequence.NewInstance(dnaSample, "ATTCG", 5);
458
//        sequence.setUuid(SEQUENCE_UUID);
459
//        SingleRead singleRead = SingleRead.NewInstance();
460
//        sequence.addSingleRead(singleRead);
461
//        dnaSample.addSequence(sequence);
462
//        AmplificationResult amplificationResult = AmplificationResult.NewInstance(dnaSample);
463
//        amplificationResult.addSingleRead(singleRead);
464
//        occurrenceService.save(fieldUnit);
465
//        occurrenceService.save(derivedUnit);
466
//        occurrenceService.save(dnaSample);
467
//
468
//        commitAndStartNewTransaction(null);
469
//
470
//        setComplete();
471
//        endTransaction();
472
//
473
//
474
//        try {
475
//            writeDbUnitDataSetFile(new String[] {
476
//                    "SpecimenOrObservationBase",
477
//                    "SpecimenOrObservationBase_DerivationEvent",
478
//                    "DerivationEvent",
479
//                    "Sequence",
480
//                    "Sequence_SingleRead",
481
//                    "SingleRead",
482
//                    "AmplificationResult"
483
//            }, "testDeleteDerivateHierarchyStepByStep");
484
//        } catch (FileNotFoundException e) {
485
//            e.printStackTrace();
486
//        }
487

  
488

  
489
        String assertMessage = "Incorrect number of specimens after deletion.";
490
        DeleteResult deleteResult = null;
491
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
492

  
493
        FieldUnit fieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
494
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
495
        DnaSample dnaSample = (DnaSample) occurrenceService.load(DNA_SAMPLE_UUID);
496
        Sequence consensusSequence = sequenceService.load(SEQUENCE_UUID);
497

  
498
        //check initial state
499
        assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
500
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
501
        assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
502
        assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
503
        assertEquals("incorrect number of amplification results", 1, dnaSample.getAmplificationResults().size());
504
        assertEquals("number of sequences incorrect", 1, dnaSample.getSequences().size());
505
        assertEquals("incorrect number of single reads", 1, dnaSample.getAmplificationResults().iterator().next().getSingleReads().size());
506

  
507
        //delete single read -> should fail
508
        SingleRead singleRead = dnaSample.getAmplificationResults().iterator().next().getSingleReads().iterator().next();
509
        deleteResult = occurrenceService.deleteDerivateHierarchy(singleRead, config);
510
        assertFalse(deleteResult.toString(), deleteResult.isOk());
511
        //delete sequence -> should fail
512
        deleteResult = occurrenceService.deleteDerivateHierarchy(consensusSequence, config);
513
        assertFalse(deleteResult.toString(), deleteResult.isOk());
514

  
515
        //allow deletion of molecular data
516
        config.setDeleteMolecularData(true);
517

  
518
        deleteResult = occurrenceService.deleteDerivateHierarchy(singleRead, config);
519
        assertTrue(deleteResult.toString(), deleteResult.isOk());
520
        assertTrue(consensusSequence.getSingleReads().isEmpty());
521

  
522
        //delete sequence -> should fail
523
        deleteResult = occurrenceService.deleteDerivateHierarchy(consensusSequence, config);
524
        assertTrue(deleteResult.toString(), deleteResult.isOk());
525
        assertEquals("number of sequences incorrect", 0, dnaSample.getSequences().size());
526

  
527

  
528
        //delete dna sample
529
        deleteResult = occurrenceService.deleteDerivateHierarchy(dnaSample, config);
530
        assertTrue(deleteResult.toString(), deleteResult.isOk());
531
        assertEquals(assertMessage, 2, occurrenceService.count(SpecimenOrObservationBase.class));
532
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
533
        assertEquals(assertMessage, 1, occurrenceService.count(DerivedUnit.class));
534
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
535

  
536
        //delete derived unit
537
        deleteResult = occurrenceService.deleteDerivateHierarchy(derivedUnit, config);
538
        assertTrue(deleteResult.toString(), deleteResult.isOk());
539
        assertEquals(assertMessage, 1, occurrenceService.count(SpecimenOrObservationBase.class));
540
        assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
541
        assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
542
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
543

  
544
        //delete field unit
545
        deleteResult = occurrenceService.deleteDerivateHierarchy(fieldUnit, config);
546
        deleteResult = occurrenceService.deleteDerivateHierarchy(fieldUnit, config);
547
        assertTrue(deleteResult.toString(), deleteResult.isOk());
548
        assertEquals(assertMessage, 0, occurrenceService.count(SpecimenOrObservationBase.class));
549
        assertEquals(assertMessage, 0, occurrenceService.count(FieldUnit.class));
550
        assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
551
        assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
552
    }
553

  
554
    @Test
555
    @DataSet
348
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testListAssociatedAndTypedTaxa.xml")
556 349
    public void testListAssociatedAndTypedTaxa(){
350
        UUID fieldUnitUuid = UUID.fromString("b359ff20-98de-46bf-aa43-3e10bb072cd4");
351
        UUID typeSpecimenUuid = UUID.fromString("0f8608c7-ffe7-40e6-828c-cb3382580878");
352
        UUID taxonDescriptionUuid = UUID.fromString("d77db2d4-45a1-4aa1-ab34-f33395f54965");
353
        UUID taxonUuid = UUID.fromString("b0de794c-8cb7-4369-8f83-870ca37abbe0");
557 354
//        //how the XML was generated
558 355
//        FieldUnit associatedFieldUnit = FieldUnit.NewInstance();
356
//        associatedFieldUnit.setUuid(fieldUnitUuid);
559 357
//        //sub derivates (DerivedUnit, DnaSample)
560 358
//        DerivedUnit typeSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
561
//        DerivedUnit voucherSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.HumanObservation);
562
//        DnaSample dnaSample = DnaSample.NewInstance();
563
//        //description for voucher specimen (with InidividualsAssociation to type specimen just to make it complex ;) )
564
//        SpecimenDescription voucherSpecimenDescription = SpecimenDescription.NewInstance(voucherSpecimen);
565
//        voucherSpecimenDescription.addElement(IndividualsAssociation.NewInstance(typeSpecimen));
359
//        typeSpecimen.setUuid(typeSpecimenUuid);
566 360
//
567 361
//        //derivation events
568 362
//        DerivationEvent.NewSimpleInstance(associatedFieldUnit, typeSpecimen, DerivationEventType.ACCESSIONING());
569
//        DerivationEvent.NewSimpleInstance(associatedFieldUnit, voucherSpecimen, DerivationEventType.ACCESSIONING());
570
//        DerivationEvent.NewSimpleInstance(typeSpecimen, dnaSample, DerivationEventType.DNA_EXTRACTION());
571 363
//
572
//        //DNA (Sequence, SingleRead, Amplification)
573
//        Sequence consensusSequence = Sequence.NewInstance(dnaSample, "ATTCG", 5);
574
//        SingleRead singleRead = SingleRead.NewInstance();
575
//        consensusSequence.addSingleRead(singleRead);
576
//        dnaSample.addSequence(consensusSequence);
577
//        Amplification amplification = Amplification.NewInstance(dnaSample);
578
//        amplification.addSingleRead(singleRead);
579 364
//        occurrenceService.save(associatedFieldUnit);
580 365
//        occurrenceService.save(typeSpecimen);
581
//        occurrenceService.save(dnaSample);
582 366
//
583 367
//        //create name with type specimen
584 368
//        BotanicalName name = BotanicalName.PARSED_NAME("Campanula patual sec L.");
......
589 373
//        // IndividualsAssociations and a "described" voucher specimen, and an
590 374
//        // empty one)
591 375
//        Taxon taxon = Taxon.NewInstance(name, null);
376
//        taxon.setUuid(taxonUuid);
592 377
//        TaxonDescription taxonDescription = TaxonDescription.NewInstance();
378
//        taxonDescription.setUuid(taxonDescriptionUuid);
593 379
//        //add voucher
594
//        taxonDescription.setDescribedSpecimenOrObservation(voucherSpecimen);
595 380
//        taxonDescription.addElement(IndividualsAssociation.NewInstance(associatedFieldUnit));
596 381
//        taxon.addDescription(taxonDescription);
597 382
//        //add type designation to name
......
600 385
//        taxon.addDescription(TaxonDescription.NewInstance());
601 386
//        taxonService.saveOrUpdate(taxon);
602 387
//
388
//        commitAndStartNewTransaction(null);
603 389
//
604
//        commitAndStartNewTransaction(new String[]{"SpecimenOrObservationBase",
605
//                "SpecimenOrObservationBase_DerivationEvent",
606
//                "DerivationEvent",
607
//                "Sequence",
608
//                "Sequence_SingleRead",
609
//                "SingleRead",
610
//                "Amplification",
611
//                "Amplification_SingleRead",
612
//                "DescriptionElementBase",
613
//                "DescriptionBase",
614
//                "TaxonBase",
615
//                "TypeDesignationBase",
616
//                "TaxonNameBase",
617
//                "TaxonNameBase_TypeDesignationBase",
618
//                "HomotypicalGroup"});
390
//        setComplete();
391
//        endTransaction();
392
//
393
//        try {
394
//            writeDbUnitDataSetFile(new String[]{
395
//                                   "SpecimenOrObservationBase",
396
//                    "SpecimenOrObservationBase_DerivationEvent",
397
//                    "DerivationEvent",
398
//                    "Sequence",
399
//                    "Sequence_SingleRead",
400
//                    "SingleRead",
401
//                    "AmplificationResult",
402
//                    "DescriptionElementBase",
403
//                    "DescriptionBase",
404
//                    "TaxonBase",
405
//                    "TypeDesignationBase",
406
//                    "TaxonNameBase",
407
//                    "TaxonNameBase_TypeDesignationBase",
408
//                    "HomotypicalGroup"}, "testListAssociatedAndTypedTaxa");
409
//        } catch (FileNotFoundException e) {
410
//            // TODO Auto-generated catch block
411
//            e.printStackTrace();
412
//        }
619 413
//
620 414
//        System.out.println("associatedFieldUnit.getUuid() " + associatedFieldUnit.getUuid());
621 415
//        System.out.println("typeSpecimen.getUuid() "+typeSpecimen.getUuid());
622
//        System.out.println("voucherSpecimen.getUuid() "+voucherSpecimen.getUuid());
623 416
//        System.out.println("taxonDescription.getUuid() "+taxonDescription.getUuid());
417
//        System.out.println("taxon.getUuid() "+taxon.getUuid());
624 418

  
625 419

  
626
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
627
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
628
        Taxon taxon = (Taxon) taxonService.load(TAXON_UUID);
629
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(TAXON_DESCRIPTION_UUID);
420
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(fieldUnitUuid);
421
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(typeSpecimenUuid);
422
        Taxon taxon = (Taxon) taxonService.load(taxonUuid);
423
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(taxonDescriptionUuid);
630 424
        //check for FieldUnit (IndividualsAssociation)
631 425
        java.util.Collection<IndividualsAssociation> individualsAssociations = occurrenceService.listIndividualsAssociations(associatedFieldUnit, null, null, null,null);
632 426
        assertEquals("Number of individuals associations is incorrect", 1, individualsAssociations.size());
......
643 437
        SpecimenTypeDesignation specimenTypeDesignation = typeDesignations.iterator().next();
644 438
        Set<TaxonNameBase> typifiedNames = specimenTypeDesignation.getTypifiedNames();
645 439
        assertEquals("number of typified names is incorrect", 1, typifiedNames.size());
646
        Set taxonBases = typifiedNames.iterator().next().getTaxonBases();
440
        Set<?> taxonBases = typifiedNames.iterator().next().getTaxonBases();
647 441
        assertEquals("number of taxa incorrect", 1, taxonBases.size());
648 442
        Object next = taxonBases.iterator().next();
649 443
        assertTrue(next instanceof CdmBase && ((CdmBase)next).isInstanceOf(Taxon.class));
......
653 447
    @Test
654 448
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testIsDeletableWithSpecimenDescription.xml")
655 449
    public void testIsDeletableWithSpecimenDescription(){
450
        UUID derivedUnitUuid = UUID.fromString("68095c8e-025d-49f0-8bb2-ed36378b75c3");
451
        UUID specimenDescriptionUuid = UUID.fromString("4094f947-ce84-47b1-bad5-e57e33239d3c");
656 452
//        //how the XML was generated
657 453
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
658
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
454
//        derivedUnit.setUuid(derivedUnitUuid);
659 455
//        SpecimenDescription specimenDescription = SpecimenDescription.NewInstance();
456
//        specimenDescription.setUuid(specimenDescriptionUuid);
660 457
//        derivedUnit.addDescription(specimenDescription);
661 458
//        occurrenceService.save(derivedUnit);
662 459
//
......
687 484
//        }
688 485

  
689 486

  
690
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
691
        SpecimenDescription specimenDescription = (SpecimenDescription) derivedUnit.getDescriptions().iterator().next();
487
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnitUuid);
488
        SpecimenDescription specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescriptionUuid);
692 489

  
693 490
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
694 491
        DeleteResult deleteResult = null;
......
706 503
    @Test
707 504
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testIsDeletableWithDescribedSpecimenInTaxonDescription.xml")
708 505
    public void testIsDeletableWithDescribedSpecimenInTaxonDescription(){
506
        UUID fieldUnitUuid = UUID.fromString("d656a004-38ee-404c-810a-87ffb0ab16c2");
709 507
//        //how the XML was generated
710 508
//        FieldUnit fieldUnit = FieldUnit.NewInstance();
711
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
509
//        fieldUnit.setUuid(fieldUnitUuid);
712 510
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
713
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
714 511
//
715 512
//        //derivation events
716 513
//        DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
......
721 518
//        // create taxon with name and two taxon descriptions
722 519
//        //(one with a "described" voucher specimen, and an empty one)
723 520
//        Taxon taxon = Taxon.NewInstance(BotanicalName.PARSED_NAME("Campanula patual sec L."), null);
724
//        taxon.setUuid(TAXON_UUID);
725
//        TaxonDescription taxonDescription = TaxonDescription.NewInstance();
726
//        taxonDescription.setUuid(TAXON_DESCRIPTION_UUID);
521
//        taxonDescription.setUuid(taxonDescriptionUuid);
727 522
//        //add voucher
728 523
//        taxonDescription.setDescribedSpecimenOrObservation(derivedUnit);
729 524
//        taxon.addDescription(taxonDescription);
......
759 554
//            e.printStackTrace();
760 555
//        }
761 556

  
762
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
763

  
764
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(TAXON_DESCRIPTION_UUID);
557
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(fieldUnitUuid);
765 558

  
766 559
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
767 560
        DeleteResult deleteResult = null;
......
779 572
    @Test
780 573
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testIsDeletableWithIndividualsAssociationTaxonDescription.xml")
781 574
    public void testIsDeletableWithIndividualsAssociationTaxonDescription(){
575
        UUID fieldUnitUuid = UUID.fromString("7978b978-5100-4c7a-82ef-3a23e0f3c723");
576
        UUID taxonDescriptionUuid = UUID.fromString("d4b0d561-6e7e-4fd8-bf3c-925530f949eb");
782 577
//        //how the XML was generated
783 578
//        FieldUnit fieldUnit = FieldUnit.NewInstance();
784
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
579
//        fieldUnit.setUuid(fieldUnitUuid);
785 580
//
786 581
//        occurrenceService.save(fieldUnit);
787 582
//
......
789 584
//        // IndividualsAssociations and a "described" voucher specimen, and an
790 585
//        // empty one)
791 586
//        Taxon taxon = Taxon.NewInstance(BotanicalName.PARSED_NAME("Campanula patual sec L."), null);
792
//        taxon.setUuid(TAXON_UUID);
793 587
//        TaxonDescription taxonDescription = TaxonDescription.NewInstance();
794
//        taxonDescription.setUuid(TAXON_DESCRIPTION_UUID);
588
//        taxonDescription.setUuid(taxonDescriptionUuid);
795 589
//        //add voucher
796 590
//        taxonDescription.addElement(IndividualsAssociation.NewInstance(fieldUnit));
797 591
//        taxon.addDescription(taxonDescription);
......
827 621
//            e.printStackTrace();
828 622
//        }
829 623

  
830
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
831
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(TAXON_DESCRIPTION_UUID);
624
        FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(fieldUnitUuid);
625
        TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(taxonDescriptionUuid);
832 626
        IndividualsAssociation individualsAssociation = (IndividualsAssociation) taxonDescription.getElements().iterator().next();
833 627

  
834 628
        SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
......
849 643
    @Test
850 644
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testIsDeletableWithTypeDesignation.xml")
851 645
    public void testIsDeletableWithTypeDesignation(){
646
        UUID derivedUnitUuid = UUID.fromString("f7fd1dc1-3c93-42a7-8279-cde5bfe37ea0");
647
        UUID botanicalNameUuid = UUID.fromString("7396430c-c932-4dd3-a45a-40c2808b132e");
852 648
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
853
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
649
////        derivedUnit.setUuid(derivedUnitUuid);
854 650
//
855 651
//        occurrenceService.save(derivedUnit);
856 652
//
857 653
//        //create name with type specimen
858 654
//        BotanicalName name = BotanicalName.PARSED_NAME("Campanula patual sec L.");
859
//        name.setUuid(BOTANICAL_NAME_UUID);
655
////        name.setUuid(botanicalNameUuid);
860 656
//        SpecimenTypeDesignation typeDesignation = SpecimenTypeDesignation.NewInstance();
861 657
//        typeDesignation.setTypeSpecimen(derivedUnit);
862 658
//        //add type designation to name
......
893 689

  
894 690

  
895 691

  
896
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
692
        DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(derivedUnitUuid);
897 693

  
898 694
        //create name with type specimen
899
        BotanicalName name = (BotanicalName) nameService.load(BOTANICAL_NAME_UUID);
695
        BotanicalName name = (BotanicalName) nameService.load(botanicalNameUuid);
900 696
        SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation) name.getTypeDesignations().iterator().next();
901 697

  
902 698
        //add type designation to name
......
921 717
    @Test
922 718
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurrenceServiceTest.testIsDeletableWithChildren.xml")
923 719
    public void testIsDeletableWithChildren(){
720
        UUID fieldUnitUuid = UUID.fromString("92ada058-4c14-4131-8ecd-b82dc1dd2882");
721
        UUID derivedUnitUuid = UUID.fromString("896dffdc-6809-4914-8950-5501fee1c0fd");
722
        UUID dnaSampleUuid = UUID.fromString("7efd1d66-ac7f-4202-acdf-a72cbb9c3a21");
924 723
//        //how the XML was generated
925 724
//        FieldUnit fieldUnit = FieldUnit.NewInstance();
926
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
725
////        fieldUnit.setUuid(fieldUnitUuid);
927 726
//        //sub derivates (DerivedUnit, DnaSample)
928 727
//        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
929
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
728
////        derivedUnit.setUuid(derivedUnitUuid);
930 729
//        DnaSample dnaSample = DnaSample.NewInstance();
931
//        dnaSample.setUuid(DNA_SAMPLE_UUID);
730
////        dnaSample.setUuid(dnaSampleUuid);
932 731
//
933 732
//        //derivation events
934
//        DerivationEvent derivationEventFUtoDU = DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
935
//        DerivationEvent derivationEventDUtoDNA = DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
733
//        DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
734
//        DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
936 735
//
937 736
//        occurrenceService.save(fieldUnit);
938 737
//        occurrenceService.save(derivedUnit);
......
964 763
//        } catch (FileNotFoundException e) {
965 764
//            e.printStackTrace();
966 765
//        }
967

  
968
        FieldUnit fieldUnit = (FieldUnit) occurrenceService.load(FIELD_UNIT_UUID);
766
        FieldUnit fieldUnit = (FieldUnit) occurrenceService.load(fieldUnitUuid);
969 767
        //sub derivates (DerivedUnit, DnaSample)
970
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(DERIVED_UNIT_UUID);
971
        DnaSample dnaSample = (DnaSample) occurrenceService.load(DNA_SAMPLE_UUID);
768
        DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnitUuid);
769
        DnaSample dnaSample = (DnaSample) occurrenceService.load(dnaSampleUuid);
770
//        Sequence sequence = dnaSample.getSequences().iterator().next();
771

  
972 772
        //derivation events
973 773
        DerivationEvent fieldUnitToDerivedUnitEvent = fieldUnit.getDerivationEvents().iterator().next();
974 774
        DerivationEvent derivedUnitToDnaSampleEvent = derivedUnit.getDerivationEvents().iterator().next();
......
978 778
        DeleteResult deleteResult = null;
979 779
        //check deletion of DnaSample
980 780
        deleteResult = occurrenceService.isDeletable(dnaSample, config);
981
        assertFalse(deleteResult.toString(), deleteResult.isOk());
982
        //allow deletion of molecular data
983
        config.setDeleteMolecularData(true);
984
        deleteResult = occurrenceService.isDeletable(dnaSample, config);
985 781
        assertTrue(deleteResult.toString(), deleteResult.isOk());
986
        assertTrue(deleteResult.toString(), deleteResult.getRelatedObjects().contains(derivedUnitToDnaSampleEvent));
987 782

  
988 783
        //check deletion of Specimen
989 784
        deleteResult = occurrenceService.isDeletable(derivedUnit, config);
990 785
        assertFalse(deleteResult.toString(), deleteResult.isOk());
991 786
        assertTrue(deleteResult.toString(), deleteResult.getRelatedObjects().contains(derivedUnitToDnaSampleEvent));
992
        assertTrue(deleteResult.toString(), deleteResult.getRelatedObjects().contains(fieldUnitToDerivedUnitEvent));
993 787

  
994 788
        //delete DnaSample
995 789
        occurrenceService.deleteDerivateHierarchy(dnaSample, config);
996 790

  
997 791
        deleteResult = occurrenceService.isDeletable(derivedUnit, config);
998 792
        assertTrue(deleteResult.toString(), deleteResult.isOk());
999
        assertTrue(deleteResult.toString(), deleteResult.getRelatedObjects().contains(fieldUnitToDerivedUnitEvent));
1000 793

  
1001 794
        //check deletion of fieldUnit
1002 795
        deleteResult = occurrenceService.isDeletable(fieldUnit, config);
......
1017 810
    public void createTestDataSet() throws FileNotFoundException {
1018 811
        //how the XML was generated
1019 812
        FieldUnit fieldUnit = FieldUnit.NewInstance();
1020
        fieldUnit.setUuid(FIELD_UNIT_UUID);
813
//        fieldUnit.setUuid(FIELD_UNIT_UUID);
1021 814
        //sub derivates (DerivedUnit, DnaSample)
1022 815
        DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
1023
        derivedUnit.setUuid(DERIVED_UNIT_UUID);
816
//        derivedUnit.setUuid(DERIVED_UNIT_UUID);
1024 817
        DnaSample dnaSample = DnaSample.NewInstance();
1025
        dnaSample.setUuid(DNA_SAMPLE_UUID);
818
//        dnaSample.setUuid(DNA_SAMPLE_UUID);
1026 819

  
1027 820
        //derivation events
1028
        DerivationEvent derivationEventFUtoDU = DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
1029
        DerivationEvent derivationEventDUtoDNA = DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
821
        DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
822
        DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
1030 823

  
1031 824
        //DNA (Sequence, SingleRead, Amplification)
1032 825
        Sequence sequence = Sequence.NewInstance(dnaSample, "ATTCG", 5);
1033
        sequence.setUuid(SEQUENCE_UUID);
826
//        sequence.setUuid(SEQUENCE_UUID);
1034 827
        SingleRead singleRead = SingleRead.NewInstance();
1035 828
        sequence.addSingleRead(singleRead);
1036 829
        dnaSample.addSequence(sequence);
......
1042 835

  
1043 836
        //create name with type specimen
1044 837
        BotanicalName name = BotanicalName.PARSED_NAME("Campanula patual sec L.");
1045
        name.setUuid(BOTANICAL_NAME_UUID);
838
//        name.setUuid(BOTANICAL_NAME_UUID);
1046 839
        SpecimenTypeDesignation typeDesignation = SpecimenTypeDesignation.NewInstance();
1047 840
        typeDesignation.setTypeSpecimen(derivedUnit);
1048 841
        //add type designation to name
......
1052 845
        // IndividualsAssociations and a "described" voucher specimen, and an
1053 846
        // empty one)
1054 847
        Taxon taxon = Taxon.NewInstance(name, null);
1055
        taxon.setUuid(TAXON_UUID);
848
//        taxon.setUuid(TAXON_UUID);
1056 849
        TaxonDescription taxonDescription = TaxonDescription.NewInstance();
1057
        taxonDescription.setUuid(TAXON_DESCRIPTION_UUID);
850
//        taxonDescription.setUuid(TAXON_DESCRIPTION_UUID);
1058 851
        //add voucher
1059 852
        taxonDescription.addElement(IndividualsAssociation.NewInstance(fieldUnit));
1060 853
        taxon.addDescription(taxonDescription);

Also available in: Unified diff