Change WaterbodyOrCountry name to Country #3700
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / facade / DerivedUnitFacadeTest.java
index 1cff957926ce68c296c2ee1831acd7647d1943e3..8058b29b0f1da4a9c699cf136a0dddb4e8aedd9c 100644 (file)
@@ -27,12 +27,13 @@ import org.unitils.dbunit.annotation.DataSet;
 import org.unitils.dbunit.annotation.ExpectedDataSet;\r
 import org.unitils.spring.annotation.SpringBeanByType;\r
 \r
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;\r
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
 import eu.etaxonomy.cdm.api.service.ITermService;\r
 import eu.etaxonomy.cdm.api.service.IUserService;\r
+import eu.etaxonomy.cdm.common.UTF8;\r
 import eu.etaxonomy.cdm.model.agent.AgentBase;\r
 import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;\r
 import eu.etaxonomy.cdm.model.common.Language;\r
 import eu.etaxonomy.cdm.model.common.LanguageString;\r
@@ -40,15 +41,12 @@ import eu.etaxonomy.cdm.model.common.OriginalSourceType;
 import eu.etaxonomy.cdm.model.common.TimePeriod;\r
 import eu.etaxonomy.cdm.model.common.User;\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
-import eu.etaxonomy.cdm.model.description.Sex;\r
 import eu.etaxonomy.cdm.model.description.SpecimenDescription;\r
-import eu.etaxonomy.cdm.model.description.Stage;\r
 import eu.etaxonomy.cdm.model.description.TextData;\r
 import eu.etaxonomy.cdm.model.location.NamedArea;\r
 import eu.etaxonomy.cdm.model.location.Point;\r
 import eu.etaxonomy.cdm.model.location.ReferenceSystem;\r
-import eu.etaxonomy.cdm.model.location.TdwgArea;\r
-import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;\r
+import eu.etaxonomy.cdm.model.location.Country;\r
 import eu.etaxonomy.cdm.model.media.Media;\r
 import eu.etaxonomy.cdm.model.name.BotanicalName;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
@@ -56,16 +54,18 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.occurrence.Collection;\r
 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
-import eu.etaxonomy.cdm.model.occurrence.FieldObservation;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;\r
 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;\r
-import eu.etaxonomy.cdm.model.occurrence.Specimen;\r
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;\r
 import eu.etaxonomy.cdm.model.reference.Reference;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;\r
 \r
 \r
+\r
 /**\r
  * @author a.mueller\r
  * @date 17.05.2010\r
@@ -85,16 +85,18 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     private IUserService userService;\r
 \r
 \r
-    Specimen specimen;\r
+    DerivedUnit specimen;\r
     DerivationEvent derivationEvent;\r
-    FieldObservation fieldObservation;\r
+    FieldUnit fieldUnit;\r
     GatheringEvent gatheringEvent;\r
     Integer absoluteElevation = 10;\r
     Integer absoluteElevationMaximum = 14;\r
     AgentBase<?> collector = Team.NewInstance();\r
     String collectingMethod = "Collection Method";\r
-    Integer distanceToGround = 22;\r
-    Integer distanceToSurface = 50;\r
+    Double distanceToGround = 22.0;\r
+    Double distanceToSurface = 0.3;\r
+    Double distanceToSurfaceMax = 0.7;\r
+    \r
     ReferenceSystem referenceSystem = ReferenceSystem.WGS84();\r
     Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);\r
     String gatheringEventDescription = "A nice gathering description";\r
@@ -104,8 +106,8 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     String fieldNotes = "such a beautiful specimen";\r
 \r
     Integer individualCount = 1;\r
-    Stage lifeStage = Stage.NewInstance("A wonderful stage", "stage", "st");\r
-    Sex sex = Sex.NewInstance("FemaleMale", "FM", "FM");\r
+    DefinedTerm lifeStage = DefinedTerm.NewStageInstance("A wonderful stage", "stage", "st");\r
+    DefinedTerm sex = DefinedTerm.NewSexInstance("FemaleMale", "FM", "FM");\r
     LanguageString locality = LanguageString.NewInstance("My locality",\r
             Language.DEFAULT());\r
 \r
@@ -120,15 +122,15 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
 \r
     DerivedUnitFacade specimenFacade;\r
 \r
-    Specimen collectionSpecimen;\r
+    DerivedUnit collectionSpecimen;\r
     GatheringEvent existingGatheringEvent;\r
     DerivationEvent firstDerivationEvent;\r
-    FieldObservation firstFieldObject;\r
+    FieldUnit firstFieldObject;\r
     Media media1 = Media.NewInstance();\r
 \r
     DerivedUnitFacade emptyFacade;\r
 \r
-    NamedArea country = WaterbodyOrCountry.GERMANY();\r
+    NamedArea country = Country.GERMANY();\r
 \r
     // ****************************** SET UP **********************************/\r
 \r
@@ -139,20 +141,21 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Before\r
     public void setUp() throws Exception {\r
 \r
-        specimen = Specimen.NewInstance();\r
+        specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
 \r
         derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());\r
         specimen.setDerivedFrom(derivationEvent);\r
-        fieldObservation = FieldObservation.NewInstance();\r
-        fieldObservation.addDerivationEvent(derivationEvent);\r
+        fieldUnit = FieldUnit.NewInstance();\r
+        fieldUnit.addDerivationEvent(derivationEvent);\r
         gatheringEvent = GatheringEvent.NewInstance();\r
-        fieldObservation.setGatheringEvent(gatheringEvent);\r
+        fieldUnit.setGatheringEvent(gatheringEvent);\r
         gatheringEvent.setAbsoluteElevation(absoluteElevation);\r
         gatheringEvent.setAbsoluteElevationMax(absoluteElevationMaximum);\r
         gatheringEvent.setActor(collector);\r
         gatheringEvent.setCollectingMethod(collectingMethod);\r
         gatheringEvent.setDistanceToGround(distanceToGround);\r
         gatheringEvent.setDistanceToWaterSurface(distanceToSurface);\r
+        gatheringEvent.setDistanceToWaterSurfaceMax(distanceToSurfaceMax);\r
         gatheringEvent.setExactLocation(exactLocation);\r
         gatheringEvent.setDescription(gatheringEventDescription);\r
         gatheringEvent.setCountry(country);\r
@@ -160,11 +163,11 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         gatheringEvent.setTimeperiod(gatheringPeriod);\r
         gatheringEvent.setLocality(locality);\r
 \r
-        fieldObservation.setFieldNumber(fieldNumber);\r
-        fieldObservation.setFieldNotes(fieldNotes);\r
-        fieldObservation.setIndividualCount(individualCount);\r
-        fieldObservation.setSex(sex);\r
-        fieldObservation.setLifeStage(lifeStage);\r
+        fieldUnit.setFieldNumber(fieldNumber);\r
+        fieldUnit.setFieldNotes(fieldNotes);\r
+        fieldUnit.setIndividualCount(individualCount);\r
+        fieldUnit.setSex(sex);\r
+        fieldUnit.setLifeStage(lifeStage);\r
 \r
         specimen.setAccessionNumber(accessionNumber);\r
         specimen.setCatalogNumber(catalogNumber);\r
@@ -175,9 +178,9 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         specimenFacade = DerivedUnitFacade.NewInstance(specimen);\r
 \r
         // existing specimen with 2 derivation events in line\r
-        collectionSpecimen = Specimen.NewInstance();\r
-        Specimen middleSpecimen = Specimen.NewInstance();\r
-        firstFieldObject = FieldObservation.NewInstance();\r
+        collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();\r
+        DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();\r
+        firstFieldObject = FieldUnit.NewInstance();\r
 \r
                //TODO maybe we should define concrete event types here\r
         DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();\r
@@ -193,7 +196,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         firstFieldObject.setGatheringEvent(existingGatheringEvent);\r
 \r
         // empty facade\r
-        emptyFacade = DerivedUnitFacade.NewInstance(DerivedUnitType.Specimen);\r
+        emptyFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);\r
 \r
     }\r
 \r
@@ -207,14 +210,14 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         UUID imageFeatureUuid = Feature.IMAGE().getUuid();\r
         Feature imageFeature = (Feature) termService.find(imageFeatureUuid);\r
 \r
-        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(DerivedUnitType.Specimen);\r
+        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);\r
         facade.innerDerivedUnit().setUuid(UUID.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));\r
         facade.setFieldNumber("12345");\r
         Media media = Media.NewInstance(URI.create("www.abc.de"), 200, null,"jpeg");\r
 \r
         try {\r
             SpecimenDescription imageGallery = SpecimenDescription.NewInstance();\r
-            imageGallery.addDescribedSpecimenOrObservation(facade.innerFieldObservation());\r
+            imageGallery.setDescribedSpecimenOrObservation(facade.innerFieldUnit());\r
             imageGallery.setImageGallery(true);\r
             TextData textData = TextData.NewInstance();\r
             textData.setFeature(imageFeature);\r
@@ -229,12 +232,12 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         this.service.save(facade.innerDerivedUnit());\r
 \r
          setComplete(); endTransaction();\r
-         try {if (true){printDataSet(System.out, new\r
-         String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"\r
-         ,"DERIVATIONEVENT",\r
-         "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",\r
-         "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}\r
-         } catch(Exception e) { logger.warn(e);}\r
+//         try {if (true){printDataSet(System.out, new\r
+//         String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"\r
+//         ,"DERIVATIONEVENT",\r
+//         "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",\r
+//         "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}\r
+//         } catch(Exception e) { logger.warn(e);}\r
 \r
     }\r
 \r
@@ -248,14 +251,13 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         // UUID specimenUUID =\r
         // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");\r
         // Specimen specimen = (Specimen)service.find(specimenUUID);\r
-        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(DerivedUnitType.Specimen);\r
+        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);\r
         Media media = Media.NewInstance(URI.create("www.derivedUnitImage.de"),200, null, "png");\r
 \r
         try {\r
             SpecimenDescription imageGallery = SpecimenDescription\r
                     .NewInstance();\r
-            imageGallery.addDescribedSpecimenOrObservation(facade\r
-                    .innerDerivedUnit());\r
+            imageGallery.setDescribedSpecimenOrObservation(facade.innerDerivedUnit());\r
             imageGallery.setImageGallery(true);\r
             TextData textData = TextData.NewInstance();\r
             imageGallery.addElement(textData);\r
@@ -272,7 +274,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         // try {if (true){printDataSet(System.out, new\r
         // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"\r
         // ,"DERIVATIONEVENT",\r
-        // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",\r
+        // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",\r
         // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}\r
         // } catch(Exception e) { logger.warn(e);}\r
 \r
@@ -285,23 +287,20 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     public void testGetFieldObjectImageGalleryBooleanPersisted() {\r
         UUID specimenUUID = UUID\r
                 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");\r
-        Specimen specimen = (Specimen) service.load(specimenUUID);\r
+        DerivedUnit specimen = (DerivedUnit) service.load(specimenUUID);\r
         Assert.assertNotNull("Specimen should exist (persisted)", specimen);\r
         try {\r
             DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);\r
-            SpecimenDescription imageGallery = facade\r
-                    .getFieldObjectImageGallery(true);\r
+            SpecimenDescription imageGallery = facade.getFieldObjectImageGallery(true);\r
             Assert.assertNotNull("Image gallery should exist", imageGallery);\r
             Assert.assertEquals("UUID should be equal to the persisted uuid",\r
                     UUID.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),\r
                     imageGallery.getUuid());\r
-            Assert.assertEquals("The image gallery should be flagged as such",\r
-                    true, imageGallery.isImageGallery());\r
+            Assert.assertEquals("The image gallery should be flagged as such",true, imageGallery.isImageGallery());\r
             Assert.assertEquals(\r
                     "There should be one TextData in image gallery", 1,\r
                     imageGallery.getElements().size());\r
-            List<Media> media = imageGallery.getElements().iterator().next()\r
-                    .getMedia();\r
+            List<Media> media = imageGallery.getElements().iterator().next().getMedia();\r
             Assert.assertEquals("There should be 1 media", 1, media.size());\r
         } catch (DerivedUnitFacadeNotSupportedException e) {\r
             e.printStackTrace();\r
@@ -314,7 +313,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
 //     @Ignore // TODO generally works causes has id problems with following tests when running in suite\r
        public void testGetDerivedUnitImageGalleryBooleanPersisted() {\r
                UUID specimenUUID = UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");\r
-               Specimen specimen = (Specimen) service.load(specimenUUID);\r
+               DerivedUnit specimen = (DerivedUnit) service.load(specimenUUID);\r
                Assert.assertNotNull("Specimen should exist (persisted)", specimen);\r
                try {\r
                        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);\r
@@ -338,7 +337,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
 \r
        @Test\r
        public void testGetDerivedUnitImageGalleryBoolean() {\r
-               Specimen specimen = Specimen.NewInstance();\r
+               DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
                try {\r
                        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);\r
                        SpecimenDescription imageGallery = facade.getDerivedUnitImageGallery(true);\r
@@ -362,8 +361,8 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         // ???\r
         // Assert.assertNotNull("The derivation event should have been created",\r
         // specimenFacade.getSpecimen().getDerivedFrom());\r
-        // Assert.assertNotNull("The field observation should have been created",\r
-        // specimenFacade.getFieldObservation());\r
+        // Assert.assertNotNull("The field unit should have been created",\r
+        // specimenFacade.getFieldUnit());\r
         // Assert.assertNotNull("The gathering event should have been created",\r
         // specimenFacade.getGatheringEvent());\r
     }\r
@@ -379,8 +378,8 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
                 specimenFacade.innerDerivedUnit());\r
         Assert.assertSame("Derivation event should be same", derivationEvent,\r
                 specimenFacade.innerDerivedUnit().getDerivedFrom());\r
-        Assert.assertSame("Field observation should be same", fieldObservation,\r
-                specimenFacade.innerFieldObservation());\r
+        Assert.assertSame("Field unit should be same", fieldUnit,\r
+                specimenFacade.innerFieldUnit());\r
         Assert.assertSame("Gathering event should be same", gatheringEvent,\r
                 specimenFacade.innerGatheringEvent());\r
 \r
@@ -388,30 +387,29 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
 \r
     @Test\r
     public void testGatheringEventIsConnectedToDerivedUnit() {\r
-        Specimen specimen = Specimen.NewInstance();\r
+       DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
         DerivedUnitFacade specimenFacade;\r
         try {\r
             specimenFacade = DerivedUnitFacade.NewInstance(specimen);\r
-            specimenFacade.setDistanceToGround(2);\r
-            FieldObservation specimenFieldObservation = (FieldObservation) specimen\r
-                    .getDerivedFrom().getOriginals().iterator().next();\r
+            specimenFacade.setDistanceToGround(2.0);\r
+            FieldUnit specimenFieldUnit = (FieldUnit) specimen.getDerivedFrom().getOriginals().iterator().next();\r
             Assert.assertSame(\r
                     "Facade gathering event and specimen gathering event should be the same",\r
                     specimenFacade.innerGatheringEvent(),\r
-                    specimenFieldObservation.getGatheringEvent());\r
+                    specimenFieldUnit.getGatheringEvent());\r
         } catch (DerivedUnitFacadeNotSupportedException e) {\r
             Assert.fail("An error should not occur in NewInstance()");\r
         }\r
     }\r
 \r
     @Test\r
-    public void testNoGatheringEventAndFieldObservation() {\r
-        Specimen specimen = Specimen.NewInstance();\r
+    public void testNoGatheringEventAndFieldUnit() {\r
+       DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
         DerivedUnitFacade specimenFacade;\r
         try {\r
             specimenFacade = DerivedUnitFacade.NewInstance(specimen);\r
-            Assert.assertNull("No field observation should exists",\r
-                    specimenFacade.innerFieldObservation());\r
+            Assert.assertNull("No field unit should exists",\r
+                    specimenFacade.innerFieldUnit());\r
         } catch (DerivedUnitFacadeNotSupportedException e) {\r
             Assert.fail("An error should not occur in NewInstance()");\r
         }\r
@@ -420,7 +418,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Test\r
     public void testInititializeTextDataWithSupportTest() {\r
         // TODO\r
-        Specimen specimen = Specimen.NewInstance();\r
+       DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();\r
         DerivedUnitFacade specimenFacade;\r
         try {\r
             specimenFacade = DerivedUnitFacade.NewInstance(specimen);\r
@@ -447,14 +445,14 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Test\r
     public void testAddGetRemoveCollectingArea() {\r
         String tdwgLabel = "GER";\r
-        NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgLabel);\r
+        NamedArea tdwgArea = termService.getAreaByTdwgAbbreviation(tdwgLabel);\r
         NamedArea newCollectingArea = NamedArea.NewInstance("A nice area",\r
                 "nice", "n");\r
         specimenFacade.addCollectingArea(newCollectingArea);\r
         Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade\r
                 .getCollectingAreas().size());\r
         Assert.assertSame("Areas should be same", newCollectingArea,\r
-                specimenFacade.innerFieldObservation().getGatheringEvent()\r
+                specimenFacade.innerFieldUnit().getGatheringEvent()\r
                         .getCollectingAreas().iterator().next());\r
         specimenFacade.addCollectingArea(tdwgArea);\r
         Assert.assertEquals("Exactly 2 areas must exist", 2, specimenFacade\r
@@ -478,16 +476,13 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Test\r
     public void testAddCollectingAreas() {\r
         NamedArea firstArea = NamedArea.NewInstance("A nice area", "nice", "n");\r
-        Assert.assertEquals("No area must exist", 0, specimenFacade\r
-                .getCollectingAreas().size());\r
+        Assert.assertEquals("No area must exist", 0, specimenFacade.getCollectingAreas().size());\r
         specimenFacade.addCollectingArea(firstArea);\r
-        Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade\r
-                .getCollectingAreas().size());\r
+        Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade.getCollectingAreas().size());\r
 \r
         String tdwgLabel = "GER";\r
-        NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgLabel);\r
-        NamedArea secondArea = NamedArea\r
-                .NewInstance("A nice area", "nice", "n");\r
+        NamedArea tdwgArea = termService.getAreaByTdwgAbbreviation(tdwgLabel);\r
+        NamedArea secondArea = NamedArea.NewInstance("A nice area", "nice", "n");\r
 \r
         java.util.Collection<NamedArea> areaCollection = new HashSet<NamedArea>();\r
         areaCollection.add(secondArea);\r
@@ -499,12 +494,11 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     }\r
 \r
     /**\r
-     * Test method for\r
+     * Test method for getting and setting absolute elevation.\r
      * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}\r
      * .\r
      */\r
     @Test\r
-    @Ignore // #######DerivationEvent --------------------------- 2\r
     public void testGetSetAbsoluteElevation() {\r
         Assert.assertEquals("Absolute elevation must be same",absoluteElevation, specimenFacade.getAbsoluteElevation());\r
         specimenFacade.setAbsoluteElevation(400);\r
@@ -534,11 +528,11 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         specimenFacade.setAbsoluteElevationRange(30, 36);\r
         Assert.assertEquals("", Integer.valueOf(36),specimenFacade.getAbsoluteElevationMaximum());\r
         Assert.assertEquals("", Integer.valueOf(30),specimenFacade.getAbsoluteElevation());\r
-        Assert.assertEquals("", "30 - 36",specimenFacade.absoluteElevationToString());\r
+        Assert.assertEquals("", "30" + UTF8.EN_DASH_SPATIUM + "36",specimenFacade.absoluteElevationToString());\r
         Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationText());\r
 \r
         specimenFacade.setAbsoluteElevationRange(30, 35);\r
-        Assert.assertEquals("Odd range should not throw an exception anymore", "30 - 35",specimenFacade.absoluteElevationToString());\r
+        Assert.assertEquals("Odd range should not throw an exception anymore", String.format("30%s35", UTF8.EN_DASH_SPATIUM),specimenFacade.absoluteElevationToString());\r
         \r
         specimenFacade.setAbsoluteElevationRange(41, null);\r
         Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());\r
@@ -554,6 +548,38 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
 \r
     }\r
 \r
+    @Test\r
+    public void testGetSetAbsoluteElevationText() {\r
+        Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());\r
+        Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());\r
+        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationText());\r
+\r
+        String elevText = "approx. 30 - 35";\r
+        specimenFacade.setAbsoluteElevationText(elevText);\r
+        Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());\r
+        Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());\r
+        Assert.assertEquals("", elevText,specimenFacade.absoluteElevationToString());\r
+        \r
+        specimenFacade.setAbsoluteElevationRange(30, 35);\r
+        Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());\r
+        Assert.assertEquals("", Integer.valueOf(30), specimenFacade.getAbsoluteElevation());\r
+        Assert.assertEquals("", Integer.valueOf(35),specimenFacade.getAbsoluteElevationMaximum());\r
+\r
+        \r
+        specimenFacade.setAbsoluteElevationRange(41, null);\r
+        Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());\r
+        Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());\r
+        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());\r
+        \r
+\r
+        specimenFacade.setAbsoluteElevationText(null);\r
+        Assert.assertNull("", specimenFacade.getAbsoluteElevationText());\r
+        Assert.assertEquals("ToString should change by setting text to null", "41",specimenFacade.absoluteElevationToString());\r
+        Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());\r
+        Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());\r
+    }\r
+\r
+    \r
     /**\r
      */\r
     @Test\r
@@ -588,11 +614,9 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
      */\r
     @Test\r
     public void testGetSetDistanceToGround() {\r
-        Assert.assertEquals("Distance to ground must be same",\r
-                distanceToGround, specimenFacade.getDistanceToGround());\r
-        specimenFacade.setDistanceToGround(5);\r
-        Assert.assertEquals("Distance to ground must be 5", Integer.valueOf(5),\r
-                specimenFacade.getDistanceToGround());\r
+        Assert.assertEquals("Distance to ground must be same",distanceToGround, specimenFacade.getDistanceToGround());\r
+        specimenFacade.setDistanceToGround(5.0);\r
+        Assert.assertEquals("Distance to ground must be 5", Double.valueOf(5), specimenFacade.getDistanceToGround());\r
     }\r
 \r
     /**\r
@@ -602,29 +626,49 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
      */\r
     @Test\r
     public void testGetDistanceToWaterSurface() {\r
-        Assert.assertEquals("Distance to surface must be same",\r
-                distanceToSurface, specimenFacade.getDistanceToWaterSurface());\r
-        specimenFacade.setDistanceToWaterSurface(6);\r
-        Assert.assertEquals("Distance to surface must be 6",\r
-                Integer.valueOf(6), specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("Distance to surface must be same", distanceToSurface, specimenFacade.getDistanceToWaterSurface());\r
+        specimenFacade.setDistanceToWaterSurface(6.0);\r
+        Assert.assertEquals("Distance to surface must be 6", Double.valueOf(6), specimenFacade.getDistanceToWaterSurface());\r
         // empty facade tests\r
-        Assert.assertNull("Empty facace must not have any gathering values",\r
-                emptyFacade.getDistanceToWaterSurface());\r
-        emptyFacade.setDistanceToWaterSurface(13);\r
-        Assert.assertNotNull(\r
-                "Field observation must exist if distance to water exists",\r
-                emptyFacade.getFieldObservation(false));\r
-        Assert.assertNotNull(\r
-                "Gathering event must exist if distance to water exists",\r
-                emptyFacade.getGatheringEvent(false));\r
-        FieldObservation specimenFieldObservation = (FieldObservation) emptyFacade\r
-                .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()\r
-                .next();\r
-        Assert.assertSame(\r
-                "Gathering event of facade and of specimen must be the same",\r
-                specimenFieldObservation.getGatheringEvent(),\r
-                emptyFacade.getGatheringEvent(false));\r
+        Assert.assertNull("Empty facace must not have any gathering values", emptyFacade.getDistanceToWaterSurface());\r
+        emptyFacade.setDistanceToWaterSurface(13.0);\r
+        Assert.assertNotNull("Field unit must exist if distance to water exists", emptyFacade.getFieldUnit(false));\r
+        Assert.assertNotNull("Gathering event must exist if distance to water exists", emptyFacade.getGatheringEvent(false));\r
+        FieldUnit specimenFieldUnit = (FieldUnit) emptyFacade\r
+                .innerDerivedUnit().getDerivedFrom().getOriginals().iterator().next();\r
+        Assert.assertSame("Gathering event of facade and of specimen must be the same",\r
+                specimenFieldUnit.getGatheringEvent(), emptyFacade.getGatheringEvent(false));\r
     }\r
+    \r
+    @Test\r
+    public void testGetSetDistanceToWaterText() {\r
+        Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("", distanceToSurfaceMax ,specimenFacade.getDistanceToWaterSurfaceMax());\r
+        Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceText());\r
+\r
+        String distText = "approx. 0.3 - 0.6";\r
+        specimenFacade.setDistanceToWaterSurfaceText(distText);\r
+        Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("", distanceToSurfaceMax,specimenFacade.getDistanceToWaterSurfaceMax());\r
+        Assert.assertEquals("", distText,specimenFacade.distanceToWaterSurfaceToString());\r
+        \r
+        specimenFacade.setDistanceToWaterSurfaceRange(0.6, 1.4);\r
+        Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());\r
+        Assert.assertEquals("", Double.valueOf(0.6), specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("", Double.valueOf(1.4),specimenFacade.getDistanceToWaterSurfaceMax());\r
+\r
+        specimenFacade.setDistanceToWaterSurfaceRange(41.2, null);\r
+        Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());\r
+        Assert.assertEquals("", Double.valueOf(41.2), specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceMax());\r
+        \r
+        specimenFacade.setDistanceToWaterSurfaceText(null);\r
+        Assert.assertNull("", specimenFacade.getDistanceToWaterSurfaceText());\r
+        Assert.assertEquals("ToString should change by setting text to null", "41.2",specimenFacade.distanceToWaterSurfaceToString());\r
+        Assert.assertEquals("", Double.valueOf(41.2), specimenFacade.getDistanceToWaterSurface());\r
+        Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceMax());\r
+    }\r
+\r
 \r
     /**\r
      * Test method for\r
@@ -684,13 +728,11 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
      */\r
     @Test\r
     public void testGetTimeperiod() {\r
-        Assert.assertNotNull("Gathering period must not be null",\r
-                specimenFacade.getGatheringPeriod());\r
-        Assert.assertEquals("Gathering period must be same", gatheringPeriod,\r
-                specimenFacade.getGatheringPeriod());\r
+        Assert.assertNotNull("Gathering period must not be null", specimenFacade.getGatheringPeriod());\r
+        Assert.assertFalse("Gathering period must not be empty", specimenFacade.getGatheringPeriod().isEmpty());\r
+        Assert.assertEquals("Gathering period must be same", gatheringPeriod, specimenFacade.getGatheringPeriod());\r
         specimenFacade.setGatheringPeriod(null);\r
-        Assert.assertNull("Gathering period must be null",\r
-                specimenFacade.getGatheringPeriod());\r
+        Assert.assertTrue("Gathering period must be null", specimenFacade.getGatheringPeriod().isEmpty());\r
     }\r
 \r
     @Test\r
@@ -699,23 +741,22 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
             IllegalAccessException {\r
         // this test depends on the current implementation of SpecimenFacade. In\r
         // future\r
-        // field observation may not be initialized from the beginning. Than the\r
+        // field unit may not be initialized from the beginning. Than the\r
         // following\r
         // assert should be set to assertNull\r
-        Assert.assertTrue(\r
-                "field object should not be null (depends on specimen facade initialization !!)",\r
+        Assert.assertTrue("field object should not be null (depends on specimen facade initialization !!)",\r
                 specimenFacade.hasFieldObject());\r
 \r
-        Field fieldObservationField = DerivedUnitFacade.class\r
-                .getDeclaredField("fieldObservation");\r
-        fieldObservationField.setAccessible(true);\r
-        fieldObservationField.set(specimenFacade, null);\r
-        Assert.assertFalse("The field observation should be null now",\r
+        Field fieldUnitField = DerivedUnitFacade.class\r
+                .getDeclaredField("fieldUnit");\r
+        fieldUnitField.setAccessible(true);\r
+        fieldUnitField.set(specimenFacade, null);\r
+        Assert.assertFalse("The field unit should be null now",\r
                 specimenFacade.hasFieldObject());\r
 \r
-        specimenFacade.setDistanceToGround(33);\r
+        specimenFacade.setDistanceToGround(33.0);\r
         Assert.assertTrue(\r
-                "The field observation should have been created again",\r
+                "The field unit should have been created again",\r
                 specimenFacade.hasFieldObject());\r
     }\r
 \r
@@ -971,15 +1012,15 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
                 emptyFacade.getFieldNumber());\r
         emptyFacade.setFieldNumber("1256A");\r
         Assert.assertNotNull(\r
-                "Field observation must exist if field number exists",\r
-                emptyFacade.getFieldObservation(false));\r
-        FieldObservation specimenFieldObservation = (FieldObservation) emptyFacade\r
+                "Field unit must exist if field number exists",\r
+                emptyFacade.getFieldUnit(false));\r
+        FieldUnit specimenFieldUnit = (FieldUnit) emptyFacade\r
                 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()\r
                 .next();\r
         Assert.assertSame(\r
-                "Field observation of facade and of specimen must be the same",\r
-                specimenFieldObservation,\r
-                emptyFacade.getFieldObservation(false));\r
+                "Field unit of facade and of specimen must be the same",\r
+                specimenFieldUnit,\r
+                emptyFacade.getFieldUnit(false));\r
         Assert.assertEquals("1256A", emptyFacade.getFieldNumber());\r
     }\r
 \r
@@ -1005,12 +1046,12 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Ignore // #######DerivationEvent ---------------------------------------- 1\r
     public void testSetGatheringEvent() {\r
         GatheringEvent newGatheringEvent = GatheringEvent.NewInstance();\r
-        newGatheringEvent.setDistanceToGround(43);\r
+        newGatheringEvent.setDistanceToGround(43.0);\r
         Assert.assertFalse("The initial distance to ground should not be 43",\r
-                specimenFacade.getDistanceToGround() == 43);\r
+                specimenFacade.getDistanceToGround() == 43.0);\r
         specimenFacade.setGatheringEvent(newGatheringEvent);\r
         Assert.assertTrue("The final distance to ground should be 43",\r
-                specimenFacade.getDistanceToGround() == 43);\r
+                specimenFacade.getDistanceToGround() == 43.0);\r
         Assert.assertSame(\r
                 "The new gathering event should be 'newGatheringEvent'",\r
                 newGatheringEvent, specimenFacade.innerGatheringEvent());\r
@@ -1026,8 +1067,8 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         Assert.assertNotNull("Gathering event must not be null",\r
                 specimenFacade.innerGatheringEvent());\r
         Assert.assertEquals(\r
-                "Gathering event must be field observations gathering event",\r
-                specimenFacade.innerFieldObservation().getGatheringEvent(),\r
+                "Gathering event must be field unit's gathering event",\r
+                specimenFacade.innerFieldUnit().getGatheringEvent(),\r
                 specimenFacade.innerGatheringEvent());\r
     }\r
 \r
@@ -1322,8 +1363,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         } catch (MethodNotSupportedByDerivedUnitTypeException e) {\r
             Assert.fail("Method not supported should not be thrown for a specimen");\r
         }\r
-        specimenFacade = DerivedUnitFacade\r
-                .NewInstance(DerivedUnitType.Observation);\r
+        specimenFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.Observation);\r
         try {\r
             specimenFacade.setPreservationMethod(preservationMethod);\r
             Assert.fail("Method not supported should be thrown for an observation on set preservation method");\r
@@ -1331,8 +1371,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         } catch (MethodNotSupportedByDerivedUnitTypeException e) {\r
             // ok\r
         }\r
-        specimenFacade = DerivedUnitFacade\r
-                .NewInstance(DerivedUnitType.LivingBeing);\r
+        specimenFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.LivingSpecimen);\r
         try {\r
             specimenFacade.getPreservationMethod();\r
             Assert.fail("Method not supported should be thrown for a living being on get preservation method");\r
@@ -1453,10 +1492,10 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     @Test\r
     public void testAddGetRemoveDuplicate() {\r
         Assert.assertEquals("No duplicates should be available yet", 0,specimenFacade.getDuplicates().size());\r
-        Specimen newSpecimen1 = Specimen.NewInstance();\r
+        DerivedUnit newSpecimen1 = DerivedUnit.NewPreservedSpecimenInstance();\r
         specimenFacade.addDuplicate(newSpecimen1);\r
         Assert.assertEquals("There should be 1 duplicate now", 1,specimenFacade.getDuplicates().size());\r
-        Specimen newSpecimen2 = Specimen.NewInstance();\r
+        DerivedUnit newSpecimen2 = DerivedUnit.NewPreservedSpecimenInstance();\r
         DerivationEvent newDerivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());\r
         newSpecimen2.setDerivedFrom(newDerivationEvent);\r
         Assert.assertSame(\r
@@ -1486,7 +1525,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         String collectorsNumber = "lkjewe";\r
         TaxonNameBase<?,?> storedUnder = BotanicalName.NewInstance(Rank.SPECIES());\r
         PreservationMethod method = PreservationMethod.NewInstance();\r
-        Specimen duplicateSpecimen = specimenFacade.addDuplicate(newCollection,\r
+        DerivedUnit duplicateSpecimen = specimenFacade.addDuplicate(newCollection,\r
                 catalogNumber, accessionNumber, storedUnder,\r
                 method);\r
         Assert.assertEquals("There should be 2 duplicates now", 2,\r
@@ -1494,10 +1533,8 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         specimenFacade.removeDuplicate(newSpecimen2);\r
         Assert.assertEquals("There should be 1 duplicates now", 1,\r
                 specimenFacade.getDuplicates().size());\r
-        Collection sameCollection = specimenFacade.getDuplicates().iterator()\r
-                .next().getCollection();\r
-        Assert.assertSame("Collections should be same", newCollection,\r
-                sameCollection);\r
+        Collection sameCollection = specimenFacade.getDuplicates().iterator().next().getCollection();\r
+        Assert.assertSame("Collections should be same", newCollection, sameCollection);\r
     }\r
 \r
     // ************************** Existing Specimen with multiple derivation\r
@@ -1520,13 +1557,13 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
     }\r
 \r
     @Test\r
-    public void testMultipleFieldObservationsNotSupported() {\r
+    public void testMultipleFieldUnitNotSupported() {\r
         specimenFacade = null;\r
-        FieldObservation secondFieldObject = FieldObservation.NewInstance();\r
+        FieldUnit secondFieldObject = FieldUnit.NewInstance();\r
         firstDerivationEvent.addOriginal(secondFieldObject);\r
         try {\r
             specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);\r
-            Assert.fail("Multiple field observations for one specimen should no be supported by the facade");\r
+            Assert.fail("Multiple field units for one specimen should no be supported by the facade");\r
         } catch (DerivedUnitFacadeNotSupportedException e) {\r
             // ok\r
         }\r
@@ -1534,23 +1571,24 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
                 specimenFacade);\r
     }\r
 \r
-    @Test // #######DerivationEvent\r
-    public void testOnlyImageGallerySupported() {\r
-        specimenFacade = null;\r
-        firstFieldObject.addMedia(media1);\r
-        try {\r
-            specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);\r
-            Assert.fail("Only image galleries are supported by the facade but not direct media");\r
-        } catch (DerivedUnitFacadeNotSupportedException e) {\r
-            // ok\r
-        }\r
-        Assert.assertNull("Specimen facade should not be initialized",\r
-                specimenFacade);\r
-    }\r
+//     not required anymore #3597   \r
+//    @Test // #######DerivationEvent\r
+//    public void testOnlyImageGallerySupported() {\r
+//        specimenFacade = null;\r
+//        firstFieldObject.addMedia(media1);\r
+//        try {\r
+//            specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);\r
+//            Assert.fail("Only image galleries are supported by the facade but not direct media");\r
+//        } catch (DerivedUnitFacadeNotSupportedException e) {\r
+//            // ok\r
+//        }\r
+//        Assert.assertNull("Specimen facade should not be initialized",\r
+//                specimenFacade);\r
+//    }\r
 \r
     @Test // #######DerivationEvent\r
     public void testEventPropagation() {\r
-        specimenFacade.setDistanceToGround(24);\r
+        specimenFacade.setDistanceToGround(24.0);\r
 \r
     }\r
 \r
@@ -1591,7 +1629,7 @@ public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
         UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, password);\r
         SecurityContextHolder.getContext().setAuthentication(token);\r
 \r
-        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(DerivedUnitType.Specimen);\r
+        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);\r
         facade.setLocality("testLocality");\r
         facade.getTitleCache();\r
 //             facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);\r