Project

General

Profile

Revision dfab8a93

IDdfab8a932cb9eef5e608cbcc4e6ffaae9590e6d9
Parent 594277ce
Child 7a72947b

Added by Patrick Plitzner over 7 years ago

  • added test for baseUnit() method

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacadeTest.java
9 9
 */
10 10
package eu.etaxonomy.cdm.api.facade;
11 11

  
12
import static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertNull;
14

  
12 15
import java.lang.reflect.Field;
13 16
import java.net.URI;
14 17
import java.text.ParseException;
......
59 62
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
60 63
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
61 64
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
65
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
62 66
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
63 67
import eu.etaxonomy.cdm.model.reference.Reference;
64 68
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
......
95 99
    Double distanceToGround = 22.0;
96 100
    Double distanceToSurface = 0.3;
97 101
    Double distanceToSurfaceMax = 0.7;
98
    
102

  
99 103
    ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
100 104
    Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
101 105
    String gatheringEventDescription = "A nice gathering description";
......
428 432
            Assert.fail("An error should not occur in NewInstance()");
429 433
        }
430 434
    }
431
    
435

  
432 436
    @Test
433 437
    public void testGetSetType() {
434 438
        Assert.assertEquals("Type must be same", SpecimenOrObservationType.PreservedSpecimen, specimenFacade.getType());
......
436 440
        specimenFacade.setType(newType);
437 441
        Assert.assertEquals("New type must be Fossil", newType, specimenFacade.getType());
438 442
        Assert.assertEquals("DerivedUnit recordBasis must be set to Fossil", newType, specimenFacade.innerDerivedUnit().getRecordBasis());
439
        
443

  
440 444
    }
441 445

  
442 446
    @Test
......
541 545
        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationText());
542 546

  
543 547
        specimenFacade.setAbsoluteElevationRange(30, 35);
544
        Assert.assertEquals("Odd range should not throw an exception anymore", 
548
        Assert.assertEquals("Odd range should not throw an exception anymore",
545 549
        		String.format("30%s35 m", UTF8.EN_DASH_SPATIUM),specimenFacade.absoluteElevationToString());
546
        
550

  
547 551
        specimenFacade.setAbsoluteElevationRange(41, null);
548 552
        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
549 553
        Assert.assertEquals("", Integer.valueOf(41),specimenFacade.getAbsoluteElevation());
......
569 573
        Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());
570 574
        Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());
571 575
        Assert.assertEquals("", elevText,specimenFacade.absoluteElevationToString());
572
        
576

  
573 577
        specimenFacade.setAbsoluteElevationRange(30, 35);
574 578
        Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());
575 579
        Assert.assertEquals("", Integer.valueOf(30), specimenFacade.getAbsoluteElevation());
576 580
        Assert.assertEquals("", Integer.valueOf(35),specimenFacade.getAbsoluteElevationMaximum());
577 581

  
578
        
582

  
579 583
        specimenFacade.setAbsoluteElevationRange(41, null);
580 584
        Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());
581 585
        Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());
582 586
        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
583
        
587

  
584 588

  
585 589
        specimenFacade.setAbsoluteElevationText(null);
586 590
        Assert.assertNull("", specimenFacade.getAbsoluteElevationText());
......
589 593
        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
590 594
    }
591 595

  
592
    
596

  
593 597
    /**
594 598
     */
595 599
    @Test
......
649 653
        Assert.assertSame("Gathering event of facade and of specimen must be the same",
650 654
                specimenFieldUnit.getGatheringEvent(), emptyFacade.getGatheringEvent(false));
651 655
    }
652
    
656

  
653 657
    @Test
654 658
    public void testGetSetDistanceToWaterText() {
655 659
        Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
......
661 665
        Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
662 666
        Assert.assertEquals("", distanceToSurfaceMax,specimenFacade.getDistanceToWaterSurfaceMax());
663 667
        Assert.assertEquals("", distText,specimenFacade.distanceToWaterSurfaceToString());
664
        
668

  
665 669
        specimenFacade.setDistanceToWaterSurfaceRange(0.6, 1.4);
666 670
        Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());
667 671
        Assert.assertEquals("", Double.valueOf(0.6), specimenFacade.getDistanceToWaterSurface());
......
671 675
        Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());
672 676
        Assert.assertEquals("", Double.valueOf(41.2), specimenFacade.getDistanceToWaterSurface());
673 677
        Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceMax());
674
        
678

  
675 679
        specimenFacade.setDistanceToWaterSurfaceText(null);
676 680
        Assert.assertNull("", specimenFacade.getDistanceToWaterSurfaceText());
677 681
        Assert.assertEquals("ToString should change by setting text to null", "41.2 m",specimenFacade.distanceToWaterSurfaceToString());
......
1480 1484
    @Test
1481 1485
    public void testAddGetRemoveSource() {
1482 1486
        Assert.assertEquals("No sources should exist yet", 0, specimenFacade.getSources().size());
1483
        
1487

  
1484 1488
        Reference<?> reference = ReferenceFactory.newBook();
1485 1489
        IdentifiableSource source1 = specimenFacade.addSource(OriginalSourceType.PrimaryTaxonomicSource, reference, "54", "myName");
1486 1490
        Assert.assertEquals("One source should exist now", 1, specimenFacade.getSources().size());
......
1579 1583
                specimenFacade);
1580 1584
    }
1581 1585

  
1582
// 	not required anymore #3597   
1586
// 	not required anymore #3597
1583 1587
//    @Test // #######DerivationEvent
1584 1588
//    public void testOnlyImageGallerySupported() {
1585 1589
//        specimenFacade = null;
......
1645 1649
        commitAndStartNewTransaction(null);
1646 1650
    }
1647 1651

  
1652
    @Test
1653
    public void testBaseUnit() throws DerivedUnitFacadeNotSupportedException{
1654
        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);
1655
        assertEquals("baseUnit is incorrect", specimen, facade.baseUnit());
1656

  
1657
        facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, fieldUnit);
1658
        assertEquals("baseUnit is incorrect", fieldUnit, facade.baseUnit());
1659

  
1660
        facade = DerivedUnitFacade.NewInstance(specimen);
1661
        facade.getFieldUnit(true);
1662
        assertEquals("baseUnit is incorrect", specimen, facade.baseUnit());
1663
    }
1664

  
1648 1665
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)