3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.facade
;
12 import java
.lang
.reflect
.Field
;
13 import java
.text
.ParseException
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.junit
.Assert
;
19 import org
.junit
.Before
;
20 import org
.junit
.BeforeClass
;
21 import org
.junit
.Test
;
23 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
26 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
29 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Sex
;
32 import eu
.etaxonomy
.cdm
.model
.description
.Stage
;
33 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
34 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
35 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
36 import eu
.etaxonomy
.cdm
.model
.location
.TdwgArea
;
37 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
38 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
39 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
40 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
41 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
42 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
43 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
44 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
45 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
46 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
47 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
49 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
56 public class DerivedUnitFacadeTest
{
57 @SuppressWarnings("unused")
58 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeTest
.class);
61 DerivationEvent derivationEvent
;
62 FieldObservation fieldObservation
;
63 GatheringEvent gatheringEvent
;
64 Integer absoluteElevation
= 10;
65 Integer absoluteElevationError
= 2;
66 AgentBase collector
= Team
.NewInstance();
67 String collectingMethod
= "Collection Method";
68 Integer distanceToGround
= 22;
69 Integer distanceToSurface
= 50;
70 ReferenceSystem referenceSystem
= ReferenceSystem
.WGS84();
71 Point exactLocation
= Point
.NewInstance(12.3, 10.567, referenceSystem
, 22);
72 String gatheringEventDescription
= "A nice gathering description";
73 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(1888, 1889);
75 String fieldNumber
= "15p23B";
76 String fieldNotes
= "such a beautiful specimen";
78 Integer individualCount
= 1;
79 Stage lifeStage
= Stage
.NewInstance("A wonderful stage", "stage", "st");
80 Sex sex
= Sex
.NewInstance("FemaleMale", "FM", "FM");
81 LanguageString locality
= LanguageString
.NewInstance("My locality", Language
.DEFAULT());
83 String accessionNumber
= "888462535";
84 String catalogNumber
= "UU879873590";
85 TaxonNameBase taxonName
= BotanicalName
.NewInstance(Rank
.GENUS(), "Abies", null, null, null, null, null, null, null);
86 String collectorsNumber
= "234589913A34";
87 Collection collection
= Collection
.NewInstance();
88 PreservationMethod preservationMethod
= PreservationMethod
.NewInstance("my prservation", null, null);
90 DerivedUnitFacade specimenFacade
;
92 Specimen collectionSpecimen
;
93 GatheringEvent existingGatheringEvent
;
94 DerivationEvent firstDerivationEvent
;
95 FieldObservation firstFieldObject
;
96 Media media1
= Media
.NewInstance();
98 DerivedUnitFacade emptyFacade
;
101 //****************************** SET UP *****************************************/
104 * @throws java.lang.Exception
107 public static void setUpBeforeClass() throws Exception
{
108 new DefaultTermInitializer().initialize();
112 * @throws java.lang.Exception
115 public void setUp() throws Exception
{
116 specimen
= Specimen
.NewInstance();
118 derivationEvent
= DerivationEvent
.NewInstance();
119 specimen
.setDerivedFrom(derivationEvent
);
120 fieldObservation
= FieldObservation
.NewInstance();
121 fieldObservation
.addDerivationEvent(derivationEvent
);
122 gatheringEvent
= GatheringEvent
.NewInstance();
123 fieldObservation
.setGatheringEvent(gatheringEvent
);
124 gatheringEvent
.setAbsoluteElevation(absoluteElevation
);
125 gatheringEvent
.setAbsoluteElevationError(absoluteElevationError
);
126 gatheringEvent
.setActor(collector
);
127 gatheringEvent
.setCollectingMethod(collectingMethod
);
128 gatheringEvent
.setDistanceToGround(distanceToGround
);
129 gatheringEvent
.setDistanceToWaterSurface(distanceToSurface
);
130 gatheringEvent
.setExactLocation(exactLocation
);
131 gatheringEvent
.setDescription(gatheringEventDescription
);
133 gatheringEvent
.setTimeperiod(gatheringPeriod
);
134 gatheringEvent
.setLocality(locality
);
136 fieldObservation
.setFieldNumber(fieldNumber
);
137 fieldObservation
.setFieldNotes(fieldNotes
);
138 fieldObservation
.setIndividualCount(individualCount
);
139 fieldObservation
.setSex(sex
);
140 fieldObservation
.setLifeStage(lifeStage
);
142 specimen
.setAccessionNumber(accessionNumber
);
143 specimen
.setCatalogNumber(catalogNumber
);
144 specimen
.setStoredUnder(taxonName
);
145 specimen
.setCollectorsNumber(collectorsNumber
);
146 specimen
.setCollection(collection
);
147 specimen
.setPreservation(preservationMethod
);
149 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
151 //existing specimen with 2 derivation events in line
152 collectionSpecimen
= Specimen
.NewInstance();
153 Specimen middleSpecimen
= Specimen
.NewInstance();
154 firstFieldObject
= FieldObservation
.NewInstance();
156 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance();
157 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance();
158 firstDerivationEvent
= DerivationEvent
.NewInstance();
160 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
162 lastDerivationEvent
.addOriginal(middleSpecimen
);
163 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
164 firstDerivationEvent
.addOriginal(firstFieldObject
);
165 existingGatheringEvent
= GatheringEvent
.NewInstance();
166 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
169 emptyFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
174 //****************************** TESTS *****************************************/
177 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
180 public void testNewInstance() {
181 Assert
.assertNotNull("The specimen should have been created", specimenFacade
.getDerivedUnit());
183 // Assert.assertNotNull("The derivation event should have been created", specimenFacade.getSpecimen().getDerivedFrom());
184 // Assert.assertNotNull("The field observation should have been created", specimenFacade.getFieldObservation());
185 // Assert.assertNotNull("The gathering event should have been created", specimenFacade.getGatheringEvent());
189 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
192 public void testNewInstanceSpecimen() {
193 Assert
.assertSame("Specimen should be same", specimen
, specimenFacade
.getDerivedUnit());
194 Assert
.assertSame("Derivation event should be same", derivationEvent
, specimenFacade
.getDerivedUnit().getDerivedFrom());
195 Assert
.assertSame("Field observation should be same", fieldObservation
, specimenFacade
.getFieldObservation());
196 Assert
.assertSame("Gathering event should be same", gatheringEvent
, specimenFacade
.getGatheringEvent());
201 public void testGatheringEventIsConnectedToDerivedUnit(){
202 Specimen specimen
= Specimen
.NewInstance();
203 DerivedUnitFacade specimenFacade
;
205 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
206 specimenFacade
.setDistanceToGround(2);
207 FieldObservation specimenFieldObservation
= (FieldObservation
)specimen
.getDerivedFrom().getOriginals().iterator().next();
208 Assert
.assertSame("Facade gathering event and specimen gathering event should be the same",specimenFacade
.getGatheringEvent(), specimenFieldObservation
.getGatheringEvent());
209 } catch (DerivedUnitFacadeNotSupportedException e
) {
210 Assert
.fail("An error should not occur in NewInstance()");
215 public void testNoGatheringEventAndFieldObservation(){
216 Specimen specimen
= Specimen
.NewInstance();
217 DerivedUnitFacade specimenFacade
;
219 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
220 Assert
.assertNull("No field observation should exists", specimenFacade
.getFieldObservation());
221 } catch (DerivedUnitFacadeNotSupportedException e
) {
222 Assert
.fail("An error should not occur in NewInstance()");
229 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}.
232 public void testAddGetRemoveCollectingArea() {
233 String tdwgLabel
= "GER";
234 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
235 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
236 specimenFacade
.addCollectingArea(newCollectingArea
);
237 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
238 Assert
.assertSame("Areas should be same", newCollectingArea
, specimenFacade
.getFieldObservation().getGatheringEvent().getCollectingAreas().iterator().next());
239 specimenFacade
.addCollectingArea(tdwgArea
);
240 Assert
.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
.getCollectingAreas().size());
241 specimenFacade
.removeCollectingArea(newCollectingArea
);
242 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
243 NamedArea remainingArea
= specimenFacade
.getCollectingAreas().iterator().next();
244 Assert
.assertEquals("Areas should be same", tdwgArea
, remainingArea
);
245 specimenFacade
.removeCollectingArea(tdwgArea
);
246 Assert
.assertEquals("No area should remain", 0, specimenFacade
.getCollectingAreas().size());
250 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}.
253 public void testAddCollectingAreas() {
254 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
255 Assert
.assertEquals("No area must exist", 0, specimenFacade
.getCollectingAreas().size());
256 specimenFacade
.addCollectingArea(firstArea
);
257 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
259 String tdwgLabel
= "GER";
260 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
261 NamedArea secondArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
263 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
264 areaCollection
.add(secondArea
);
265 areaCollection
.add(tdwgArea
);
266 specimenFacade
.addCollectingAreas(areaCollection
);
267 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
.getCollectingAreas().size());
274 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}.
277 public void testGetSetAbsoluteElevation() {
278 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
279 specimenFacade
.setAbsoluteElevation(400);
280 Assert
.assertEquals("Absolute elevation must be 400", Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
285 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}.
288 public void testGetSetAbsoluteElevationError() {
289 Assert
.assertEquals("Absolute elevation error must be same",absoluteElevationError
, specimenFacade
.getAbsoluteElevationError());
290 specimenFacade
.setAbsoluteElevationError(4);
291 Assert
.assertEquals("Absolute elevation error must be 4", Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationError());
295 public void testGetSetAbsoluteElevationRange(){
296 Integer expected
= absoluteElevation
- 2 ;
297 Assert
.assertEquals("", expected
,specimenFacade
.getAbsoluteElevationMinimum());
298 expected
= absoluteElevation
+ 2 ;
299 Assert
.assertEquals("", expected
,specimenFacade
.getAbsoluteElevationMaximum());
300 specimenFacade
.setAbsoluteElevationRange(30, 36);
301 Assert
.assertEquals("", Integer
.valueOf(36), specimenFacade
.getAbsoluteElevationMaximum());
302 Assert
.assertEquals("", Integer
.valueOf(30), specimenFacade
.getAbsoluteElevationMinimum());
304 specimenFacade
.setAbsoluteElevationRange(30, 35);
305 Assert
.fail("Odd distance needs to throw IllegalArgumentException");
306 } catch (IllegalArgumentException e
) {
307 Assert
.assertTrue("Exception needs to be thrown", true);
309 specimenFacade
.setAbsoluteElevationRange(41, null);
310 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevationMaximum());
311 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevationMinimum());
312 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
313 Assert
.assertNotNull("", specimenFacade
.getAbsoluteElevationError());
314 Assert
.assertEquals("", Integer
.valueOf(0), specimenFacade
.getAbsoluteElevationError());
315 specimenFacade
.setAbsoluteElevationRange(null, null);
316 Assert
.assertNull("", specimenFacade
.getAbsoluteElevation());
317 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationError());
326 public void testGetSetCollector() {
327 Assert
.assertNotNull("Collector must not be null", specimenFacade
.getCollector());
328 Assert
.assertEquals("Collector must be same",collector
, specimenFacade
.getCollector());
329 specimenFacade
.setCollector(null);
330 Assert
.assertNull("Collector must be null", specimenFacade
.getCollector());
334 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}.
337 public void testGetSetCollectingMethod() {
338 Assert
.assertEquals("Collecting method must be same", collectingMethod
, specimenFacade
.getCollectingMethod());
339 specimenFacade
.setCollectingMethod("new method");
340 Assert
.assertEquals("Collecting method must be 'new method'","new method", specimenFacade
.getCollectingMethod());
345 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}.
348 public void testGetSetDistanceToGround() {
349 Assert
.assertEquals("Distance to ground must be same",distanceToGround
, specimenFacade
.getDistanceToGround());
350 specimenFacade
.setDistanceToGround(5);
351 Assert
.assertEquals("Distance to ground must be 5", Integer
.valueOf(5), specimenFacade
.getDistanceToGround());
355 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}.
358 public void testGetDistanceToWaterSurface() {
359 Assert
.assertEquals("Distance to surface must be same", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
360 specimenFacade
.setDistanceToWaterSurface(6);
361 Assert
.assertEquals("Distance to surface must be 6", Integer
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
363 Assert
.assertNull("Empty facace must not have any gathering values" ,emptyFacade
.getDistanceToWaterSurface());
364 emptyFacade
.setDistanceToWaterSurface(13);
365 Assert
.assertNotNull("Field observation must exist if distance to water exists", emptyFacade
.getFieldObservation(false));
366 Assert
.assertNotNull("Gathering event must exist if distance to water exists", emptyFacade
.getGatheringEvent(false));
367 FieldObservation specimenFieldObservation
= (FieldObservation
)emptyFacade
.getDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
368 Assert
.assertSame("Gathering event of facade and of specimen must be the same", specimenFieldObservation
.getGatheringEvent(), emptyFacade
.getGatheringEvent(false));
372 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
375 public void testGetSetExactLocation() {
376 Assert
.assertNotNull("Exact location must not be null", specimenFacade
.getExactLocation());
377 Assert
.assertEquals("Exact location must be same", exactLocation
, specimenFacade
.getExactLocation());
378 specimenFacade
.setExactLocation(null);
379 Assert
.assertNull("Exact location must be null", specimenFacade
.getExactLocation());
383 public void testSetExactLocationByParsing(){
386 specimenFacade
.setExactLocationByParsing("112°34'20\"W", "34°30,34'N", null, null);
387 point1
= specimenFacade
.getExactLocation();
388 Assert
.assertNotNull("", point1
.getLatitude());
389 System
.out
.println(point1
.getLatitude().toString());
390 Assert
.assertTrue("", point1
.getLatitude().toString().startsWith("34.505"));
391 System
.out
.println(point1
.getLongitude().toString());
392 Assert
.assertTrue("", point1
.getLongitude().toString().startsWith("-112.5722"));
394 } catch (ParseException e
) {
395 Assert
.fail("No parsing error should occur");
401 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}.
404 public void testGetSetGatheringEventDescription() {
405 Assert
.assertEquals("Gathering event description must be same", gatheringEventDescription
, specimenFacade
.getGatheringEventDescription());
406 specimenFacade
.setGatheringEventDescription("new description");
407 Assert
.assertEquals("Gathering event description must be 'new description' now","new description", specimenFacade
.getGatheringEventDescription());
411 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
414 public void testGetTimeperiod() {
415 Assert
.assertNotNull("Gathering period must not be null", specimenFacade
.getGatheringPeriod());
416 Assert
.assertEquals("Gathering period must be same", gatheringPeriod
, specimenFacade
.getGatheringPeriod());
417 specimenFacade
.setGatheringPeriod(null);
418 Assert
.assertNull("Gathering period must be null", specimenFacade
.getGatheringPeriod());
422 public void testHasFieldObject() throws SecurityException
, NoSuchFieldException
, IllegalArgumentException
, IllegalAccessException
{
423 // this test depends on the current implementation of SpecimenFacade. In future
424 // field observation may not be initialized from the beginning. Than the following
425 // assert should be set to assertNull
426 Assert
.assertTrue("field object should not be null (depends on specimen facade initialization !!)", specimenFacade
.hasFieldObject());
428 Field fieldObservationField
= DerivedUnitFacade
.class.getDeclaredField("fieldObservation");
429 fieldObservationField
.setAccessible(true);
430 fieldObservationField
.set(specimenFacade
, null);
431 Assert
.assertFalse("The field observation should be null now", specimenFacade
.hasFieldObject());
433 specimenFacade
.setDistanceToGround(33);
434 Assert
.assertTrue("The field observation should have been created again", specimenFacade
.hasFieldObject());
438 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
441 public void testAddGetRemoveFieldObjectDefinition() {
442 Assert
.assertEquals("There should be no definition yet", 0, specimenFacade
.getFieldObjectDefinition().size());
443 specimenFacade
.addFieldObjectDefinition("Tres interesant", Language
.FRENCH());
444 Assert
.assertEquals("There should be exactly one definition", 1, specimenFacade
.getFieldObjectDefinition().size());
445 Assert
.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade
.getFieldObjectDefinition().get(Language
.FRENCH()).getText());
446 Assert
.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
447 specimenFacade
.addFieldObjectDefinition("Sehr interessant", Language
.GERMAN());
448 Assert
.assertEquals("There should be exactly 2 definition", 2, specimenFacade
.getFieldObjectDefinition().size());
449 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
450 Assert
.assertEquals("There should remain exactly 1 definition", 1, specimenFacade
.getFieldObjectDefinition().size());
451 Assert
.assertEquals("The remaining German definition should be 'Sehr interessant'", "Sehr interessant", specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
452 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
453 Assert
.assertEquals("There should remain no definition", 0, specimenFacade
.getFieldObjectDefinition().size());
457 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
460 public void testAddGetHasRemoveFieldObjectMedia() {
461 Assert
.assertFalse("There should be no image gallery yet", specimenFacade
.hasFieldObjectImageGallery());
462 Assert
.assertFalse("There should be no specimen image gallery either", specimenFacade
.hasDerivedUnitImageGallery());
464 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
465 Assert
.assertFalse("There should still not be an image gallery now", specimenFacade
.hasFieldObjectImageGallery());
466 Assert
.assertEquals("There should be no media yet in the gallery", 0, media
.size());
468 Media media1
= Media
.NewInstance();
469 specimenFacade
.addFieldObjectMedia(media1
);
470 Assert
.assertEquals("There should be exactly one specimen media", 1, specimenFacade
.getFieldObjectMedia().size());
471 Assert
.assertEquals("The only media should be media 1", media1
, specimenFacade
.getFieldObjectMedia().get(0));
472 Assert
.assertFalse("There should still no specimen image gallery exist", specimenFacade
.hasDerivedUnitImageGallery());
474 Media media2
= Media
.NewInstance();
475 specimenFacade
.addFieldObjectMedia(media2
);
476 Assert
.assertEquals("There should be exactly 2 specimen media", 2, specimenFacade
.getFieldObjectMedia().size());
477 Assert
.assertEquals("The first media should be media1", media1
, specimenFacade
.getFieldObjectMedia().get(0));
478 Assert
.assertEquals("The second media should be media2", media2
, specimenFacade
.getFieldObjectMedia().get(1));
480 specimenFacade
.removeFieldObjectMedia(media1
);
481 Assert
.assertEquals("There should be exactly one specimen media", 1, specimenFacade
.getFieldObjectMedia().size());
482 Assert
.assertEquals("The only media should be media2", media2
, specimenFacade
.getFieldObjectMedia().get(0));
484 specimenFacade
.removeFieldObjectMedia(media1
);
485 Assert
.assertEquals("There should still be exactly one specimen media", 1, specimenFacade
.getFieldObjectMedia().size());
487 specimenFacade
.removeFieldObjectMedia(media2
);
488 Assert
.assertEquals("There should remain no media in the gallery", 0, media
.size());
493 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
496 public void testGetSetEcology() {
497 Assert
.assertNotNull("An empty ecology data should be created when calling getEcology()", specimenFacade
.getEcologyAll());
498 Assert
.assertEquals("An empty ecology data should be created when calling getEcology()", 0, specimenFacade
.getEcologyAll().size());
499 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
500 Assert
.assertEquals("Ecology data should exist for 1 language", 1, specimenFacade
.getEcologyAll().size());
501 Assert
.assertEquals("Ecology data should be 'Tres jolie ici' for French", "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
502 Assert
.assertNull("Ecology data should be null for the default language", specimenFacade
.getEcology());
503 specimenFacade
.setEcology("Nice here");
504 Assert
.assertEquals("Ecology data should exist for 2 languages", 2, specimenFacade
.getEcologyAll().size());
505 Assert
.assertEquals("Ecology data should be 'Tres jolie ici'", "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
506 Assert
.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getEcology());
507 Assert
.assertEquals("Ecology data should be 'Nice here' for english", "Nice here", specimenFacade
.getEcology());
509 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
510 Assert
.assertEquals("Ecology data should exist for 2 languages", 2, specimenFacade
.getEcologyAll().size());
511 Assert
.assertEquals("Ecology data should be 'Vert et rouge'", "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
512 Assert
.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getEcology());
514 specimenFacade
.setEcology(null, Language
.FRENCH());
515 Assert
.assertEquals("Ecology data should exist for 1 languages", 1, specimenFacade
.getEcologyAll().size());
516 Assert
.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getEcology());
517 Assert
.assertNull("Ecology data should be 'null' for French", specimenFacade
.getEcology(Language
.FRENCH()));
519 specimenFacade
.removeEcology(null);
520 Assert
.assertEquals("There should be no ecology left", 0, specimenFacade
.getEcologyAll().size());
521 Assert
.assertNull("Ecology data should be 'null' for default language", specimenFacade
.getEcology());
526 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
529 public void testGetSetPlantDescription() {
530 Assert
.assertNotNull("An empty plant description data should be created when calling getPlantDescriptionAll()", specimenFacade
.getPlantDescriptionAll());
531 Assert
.assertEquals("An empty plant description data should be created when calling getPlantDescription()", 0, specimenFacade
.getPlantDescriptionAll().size());
532 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
533 Assert
.assertEquals("Plant description data should exist for 1 language", 1, specimenFacade
.getPlantDescriptionAll().size());
534 Assert
.assertEquals("Plant description data should be 'bleu' for French", "bleu", specimenFacade
.getPlantDescription(Language
.FRENCH()));
535 Assert
.assertNull("Plant description data should be null for the default language", specimenFacade
.getPlantDescription());
536 specimenFacade
.setPlantDescription("Nice here");
537 Assert
.assertEquals("Plant description data should exist for 2 languages", 2, specimenFacade
.getPlantDescriptionAll().size());
538 Assert
.assertEquals("Plant description data should be 'bleu'", "bleu", specimenFacade
.getPlantDescription(Language
.FRENCH()));
539 Assert
.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getPlantDescription());
540 Assert
.assertEquals("Plant description data should be 'Nice here' for english", "Nice here", specimenFacade
.getPlantDescription());
542 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
543 Assert
.assertEquals("Plant description data should exist for 2 languages", 2, specimenFacade
.getPlantDescriptionAll().size());
544 Assert
.assertEquals("Plant description data should be 'Vert et rouge'", "Vert et rouge", specimenFacade
.getPlantDescription(Language
.FRENCH()));
545 Assert
.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getPlantDescription());
547 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
548 Assert
.assertEquals("Plant description data should exist for 1 languages", 1, specimenFacade
.getPlantDescriptionAll().size());
549 Assert
.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getPlantDescription());
550 Assert
.assertNull("Plant description data should be 'null' for French", specimenFacade
.getPlantDescription(Language
.FRENCH()));
552 //test interference with ecology
553 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
554 Assert
.assertEquals("Ecology data should exist for 1 language", 1, specimenFacade
.getEcologyAll().size());
555 Assert
.assertEquals("Ecology data should be 'Tres jolie ici' for French", "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
556 Assert
.assertNull("Ecology data should be null for the default language", specimenFacade
.getEcology());
559 Assert
.assertEquals("Plant description data should exist for 1 languages", 1, specimenFacade
.getPlantDescriptionAll().size());
560 Assert
.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade
.getPlantDescription());
561 Assert
.assertNull("Plant description data should be 'null' for French", specimenFacade
.getPlantDescription(Language
.FRENCH()));
564 specimenFacade
.removePlantDescription(null);
565 Assert
.assertEquals("There should be no plant description left", 0, specimenFacade
.getPlantDescriptionAll().size());
566 Assert
.assertNull("Plant description data should be 'null' for default language", specimenFacade
.getPlantDescription());
571 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
574 public void testGetSetFieldNumber() {
575 Assert
.assertEquals("Field number must be same", fieldNumber
, specimenFacade
.getFieldNumber());
576 specimenFacade
.setFieldNumber("564AB");
577 Assert
.assertEquals("New field number must be '564AB'", "564AB", specimenFacade
.getFieldNumber());
579 Assert
.assertNull("Empty facace must not have any field value" ,emptyFacade
.getFieldNumber());
580 emptyFacade
.setFieldNumber("1256A");
581 Assert
.assertNotNull("Field observation must exist if field number exists", emptyFacade
.getFieldObservation(false));
582 FieldObservation specimenFieldObservation
= (FieldObservation
)emptyFacade
.getDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
583 Assert
.assertSame("Field observation of facade and of specimen must be the same", specimenFieldObservation
, emptyFacade
.getFieldObservation(false));
584 Assert
.assertEquals("1256A", emptyFacade
.getFieldNumber());
588 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
591 public void testGetSetFieldNotes() {
592 Assert
.assertEquals("Field notes must be same", fieldNotes
, specimenFacade
.getFieldNotes());
593 specimenFacade
.setFieldNotes("A completely new info");
594 Assert
.assertEquals("New field note must be 'A completely new info'", "A completely new info", specimenFacade
.getFieldNotes());
598 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}.
601 public void testSetGatheringEvent() {
602 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
603 newGatheringEvent
.setDistanceToGround(43);
604 Assert
.assertFalse("The initial distance to ground should not be 43", specimenFacade
.getDistanceToGround() == 43);
605 specimenFacade
.setGatheringEvent(newGatheringEvent
);
606 Assert
.assertTrue("The final distance to ground should be 43", specimenFacade
.getDistanceToGround() == 43);
607 Assert
.assertSame("The new gathering event should be 'newGatheringEvent'", newGatheringEvent
, specimenFacade
.getGatheringEvent());
611 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEvent()}.
614 public void testGetGatheringEvent() {
615 Assert
.assertNotNull("Gathering event must not be null", specimenFacade
.getGatheringEvent());
616 Assert
.assertEquals("Gathering event must be field observations gathering event", specimenFacade
.getFieldObservation().getGatheringEvent(), specimenFacade
.getGatheringEvent());
620 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}.
623 public void testGetSetIndividualCount(){
624 Assert
.assertEquals("Individual count must be same", individualCount
, specimenFacade
.getIndividualCount());
625 specimenFacade
.setIndividualCount(4);
626 Assert
.assertEquals("New individual count must be '4'", Integer
.valueOf(4), specimenFacade
.getIndividualCount());
632 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
635 public void testGetSetLifeStage(){
636 Assert
.assertNotNull("Life stage must not be null", specimenFacade
.getLifeStage());
637 Assert
.assertEquals("Life stage must be same", lifeStage
, specimenFacade
.getLifeStage());
638 specimenFacade
.setLifeStage(null);
639 Assert
.assertNull("Life stage must be null", specimenFacade
.getLifeStage());
643 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
646 public void testGetSetSex() {
647 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
648 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
649 specimenFacade
.setSex(null);
650 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
654 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
657 public void testGetSetLocality() {
658 Assert
.assertEquals("Locality must be same", locality
, specimenFacade
.getLocality());
659 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
660 Assert
.assertEquals("New locality must be 'A completely new place'", "A completely new place", specimenFacade
.getLocalityText());
661 Assert
.assertEquals("New locality language must be French", Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
662 specimenFacade
.setLocality("Another place");
663 Assert
.assertEquals("New locality must be 'Another place'", "Another place", specimenFacade
.getLocalityText());
664 Assert
.assertEquals("New locality language must be default", Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
668 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
671 public void testAddGetRemoveSpecimenDefinition() {
672 Assert
.assertEquals("There should be no definition yet", 0, specimenFacade
.getDerivedUnitDefinitions().size());
673 specimenFacade
.addDerivedUnitDefinition("Tres interesant", Language
.FRENCH());
674 Assert
.assertEquals("There should be exactly one definition", 1, specimenFacade
.getDerivedUnitDefinitions().size());
675 Assert
.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade
.getDerivedUnitDefinitions().get(Language
.FRENCH()).getText());
676 Assert
.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
677 specimenFacade
.addDerivedUnitDefinition("Sehr interessant", Language
.GERMAN());
678 Assert
.assertEquals("There should be exactly 2 definition", 2, specimenFacade
.getDerivedUnitDefinitions().size());
679 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
680 Assert
.assertEquals("There should remain exactly 1 definition", 1, specimenFacade
.getDerivedUnitDefinitions().size());
681 Assert
.assertEquals("The remaining German definition should be 'Sehr interessant'", "Sehr interessant", specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
682 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
683 Assert
.assertEquals("There should remain no definition", 0, specimenFacade
.getDerivedUnitDefinitions().size());
687 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}.
690 public void testAddGetRemoveDetermination() {
691 Assert
.assertEquals("There should be no determination yet", 0, specimenFacade
.getDeterminations().size());
692 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
693 specimenFacade
.addDetermination(determinationEvent1
);
694 Assert
.assertEquals("There should be exactly one determination", 1, specimenFacade
.getDeterminations().size());
695 Assert
.assertEquals("The only determination should be determination 1", determinationEvent1
, specimenFacade
.getDeterminations().iterator().next());
698 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
699 specimenFacade
.addDetermination(determinationEvent2
);
700 Assert
.assertEquals("There should be exactly 2 determinations", 2, specimenFacade
.getDeterminations().size());
701 specimenFacade
.removeDetermination(determinationEvent1
);
703 Assert
.assertEquals("There should remain exactly 1 determination", 1, specimenFacade
.getDeterminations().size());
704 Assert
.assertEquals("The remaining determinations should be determination 2", determinationEvent2
, specimenFacade
.getDeterminations().iterator().next());
706 specimenFacade
.removeDetermination(determinationEvent1
);
707 Assert
.assertEquals("There should remain exactly 1 determination", 1, specimenFacade
.getDeterminations().size());
709 specimenFacade
.removeDetermination(determinationEvent2
);
710 Assert
.assertEquals("There should remain no definition", 0, specimenFacade
.getDerivedUnitDefinitions().size());
715 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}.
718 public void testAddGetHasRemoveSpecimenMedia() {
719 Assert
.assertFalse("There should be no image gallery yet", specimenFacade
.hasDerivedUnitImageGallery());
720 Assert
.assertFalse("There should be also no field object image gallery yet", specimenFacade
.hasFieldObjectImageGallery());
722 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
723 Assert
.assertFalse("There should still not be an empty image gallery now", specimenFacade
.hasDerivedUnitImageGallery());
724 Assert
.assertEquals("There should be no media yet in the gallery", 0, media
.size());
726 Media media1
= Media
.NewInstance();
727 specimenFacade
.addDerivedUnitMedia(media1
);
728 Assert
.assertEquals("There should be exactly one specimen media", 1, specimenFacade
.getDerivedUnitMedia().size());
729 Assert
.assertEquals("The only media should be media 1", media1
, specimenFacade
.getDerivedUnitMedia().get(0));
730 Assert
.assertFalse("There should be still no field object image gallery", specimenFacade
.hasFieldObjectImageGallery());
732 Media media2
= Media
.NewInstance();
733 specimenFacade
.addDerivedUnitMedia(media2
);
734 Assert
.assertEquals("There should be exactly 2 specimen media", 2, specimenFacade
.getDerivedUnitMedia().size());
735 Assert
.assertEquals("The first media should be media1", media1
, specimenFacade
.getDerivedUnitMedia().get(0));
736 Assert
.assertEquals("The second media should be media2", media2
, specimenFacade
.getDerivedUnitMedia().get(1));
738 specimenFacade
.removeDerivedUnitMedia(media1
);
739 Assert
.assertEquals("There should be exactly one specimen media", 1, specimenFacade
.getDerivedUnitMedia().size());
740 Assert
.assertEquals("The only media should be media2", media2
, specimenFacade
.getDerivedUnitMedia().get(0));
742 specimenFacade
.removeDerivedUnitMedia(media1
);
743 Assert
.assertEquals("There should still be exactly one specimen media", 1, specimenFacade
.getDerivedUnitMedia().size());
745 specimenFacade
.removeDerivedUnitMedia(media2
);
746 Assert
.assertEquals("There should remain no media in the gallery", 0, media
.size());
750 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}.
753 public void testGetSetAccessionNumber() {
754 Assert
.assertEquals("Accession number must be same", accessionNumber
, specimenFacade
.getAccessionNumber());
755 specimenFacade
.setAccessionNumber("A12345693");
756 Assert
.assertEquals("New accession number must be 'A12345693'", "A12345693", specimenFacade
.getAccessionNumber());
760 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
763 public void testGetCatalogNumber() {
764 Assert
.assertEquals("Catalog number must be same", catalogNumber
, specimenFacade
.getCatalogNumber());
765 specimenFacade
.setCatalogNumber("B12345693");
766 Assert
.assertEquals("New catalog number must be 'B12345693'", "B12345693", specimenFacade
.getCatalogNumber());
770 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
773 public void testGetPreservation() {
775 Assert
.assertNotNull("Preservation method must not be null", specimenFacade
.getPreservationMethod());
776 Assert
.assertEquals("Preservation method must be same", preservationMethod
, specimenFacade
.getPreservationMethod());
777 specimenFacade
.setPreservationMethod(null);
778 Assert
.assertNull("Preservation method must be null", specimenFacade
.getPreservationMethod());
779 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
780 Assert
.fail("Method not supported should not be thrown for a specimen");
782 specimenFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Observation
);
784 specimenFacade
.setPreservationMethod(preservationMethod
);
785 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
787 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
790 specimenFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.LivingBeing
);
792 specimenFacade
.getPreservationMethod();
793 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
794 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
802 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
805 public void testGetStoredUnder() {
806 Assert
.assertNotNull("Stored under name must not be null", specimenFacade
.getStoredUnder());
807 Assert
.assertEquals("Stored under name must be same", taxonName
, specimenFacade
.getStoredUnder());
808 specimenFacade
.setStoredUnder(null);
809 Assert
.assertNull("Stored under name must be null", specimenFacade
.getStoredUnder());
813 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}.
816 public void testGetSetCollectorsNumber() {
817 Assert
.assertEquals("Collectors number must be same", collectorsNumber
, specimenFacade
.getCollectorsNumber());
818 specimenFacade
.setCollectorsNumber("C12345693");
819 Assert
.assertEquals("New collectors number must be 'C12345693'", "C12345693", specimenFacade
.getCollectorsNumber());
823 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
826 public void testGetTitleCache() {
827 Assert
.assertNotNull("The title cache should never return null if not protected", specimenFacade
.getTitleCache());
828 specimenFacade
.setTitleCache(null, false);
829 Assert
.assertNotNull("The title cache should never return null if not protected", specimenFacade
.getTitleCache());
833 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}.
836 public void testSetTitleCache() {
837 String testTitle
= "Absdwk aksjlf";
838 specimenFacade
.setTitleCache(testTitle
, true);
839 Assert
.assertEquals("Protected title cache should returns the test title", testTitle
, specimenFacade
.getTitleCache());
840 specimenFacade
.setTitleCache(testTitle
, false);
841 Assert
.assertFalse("Unprotected title cache should not return the test title", testTitle
.equals(specimenFacade
.getTitleCache()));
845 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDerivedUnit()}.
848 public void testGetSpecimen() {
849 Assert
.assertEquals("Specimen must be same", specimen
, specimenFacade
.getDerivedUnit());
853 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
856 public void testGetSetCollection() {
857 Assert
.assertNotNull("Collection must not be null", specimenFacade
.getCollection());
858 Assert
.assertEquals("Collection must be same", collection
, specimenFacade
.getCollection());
859 specimenFacade
.setCollection(null);
860 Assert
.assertNull("Collection must be null", specimenFacade
.getCollection());
864 public void testAddGetRemoveSource(){
865 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
.getSources().size());
866 ReferenceBase reference
= ReferenceFactory
.newBook();
867 IdentifiableSource source1
= specimenFacade
.addSource(reference
, "54", "myName");
868 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
869 IdentifiableSource source2
= IdentifiableSource
.NewInstance("1", "myTable");
870 specimenFacade
.addSource(source2
);
871 Assert
.assertEquals("One source should exist now", 2, specimenFacade
.getSources().size());
872 specimenFacade
.removeSource(source1
);
873 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
874 ReferenceBase reference2
= ReferenceFactory
.newJournal();
875 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(reference2
, null, null);
876 specimenFacade
.removeSource(sourceNotUsed
);
877 Assert
.assertEquals("One source should still exist", 1, specimenFacade
.getSources().size());
878 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next().getIdInSource()) ;
879 specimenFacade
.removeSource(source2
);
880 Assert
.assertEquals("No sources should exist anymore", 0, specimenFacade
.getSources().size());
884 public void testAddGetRemoveDuplicate(){
885 Assert
.assertEquals("No duplicates should be available yet", 0, specimenFacade
.getDuplicates().size());
886 Specimen newSpecimen1
= Specimen
.NewInstance();
887 specimenFacade
.addDuplicate(newSpecimen1
);
888 Assert
.assertEquals("There should be 1 duplicate now", 1, specimenFacade
.getDuplicates().size());
889 Specimen newSpecimen2
= Specimen
.NewInstance();
890 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance();
891 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
892 Assert
.assertSame("The derivation event should be 'newDerivationEvent'", newDerivationEvent
, newSpecimen2
.getDerivedFrom());
893 specimenFacade
.addDuplicate(newSpecimen2
);
894 Assert
.assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
895 Assert
.assertNotSame("The derivation event should not be 'newDerivationEvent' anymore", newDerivationEvent
, newSpecimen2
.getDerivedFrom());
896 Assert
.assertSame("The derivation event should not be the facades derivation event", derivationEvent
, newSpecimen2
.getDerivedFrom());
897 specimenFacade
.removeDuplicate(newSpecimen1
);
898 Assert
.assertEquals("There should be 1 duplicate now", 1, specimenFacade
.getDuplicates().size());
899 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now", newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
900 specimenFacade
.addDuplicate(specimenFacade
.getDerivedUnit());
901 Assert
.assertEquals("There should be still 1 duplicate because the facade specimen is not a duplicate", 1, specimenFacade
.getDuplicates().size());
903 Collection newCollection
= Collection
.NewInstance();
904 String catalogNumber
= "1234890";
905 String accessionNumber
= "345345";
906 String collectorsNumber
= "lkjewe";
907 TaxonNameBase storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
908 PreservationMethod method
= PreservationMethod
.NewInstance();
909 Specimen duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
, catalogNumber
, accessionNumber
, collectorsNumber
, storedUnder
, method
);
910 Assert
.assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
911 specimenFacade
.removeDuplicate(newSpecimen2
);
912 Assert
.assertEquals("There should be 1 duplicates now", 1, specimenFacade
.getDuplicates().size());
913 Collection sameCollection
= specimenFacade
.getDuplicates().iterator().next().getCollection();
914 Assert
.assertSame("Collections should be same", newCollection
, sameCollection
);
917 // ************************** Existing Specimen with multiple derivation events in line **************/
920 public void testExistingSpecimen(){
921 specimenFacade
= null;
923 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
924 } catch (DerivedUnitFacadeNotSupportedException e
) {
925 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
927 Assert
.assertSame("Gathering event should derive from the derivation line", existingGatheringEvent
, specimenFacade
.getGatheringEvent());
928 Assert
.assertEquals("Mediasize should be 0. Only Imagegallery media are supported", 0, specimenFacade
.getFieldObjectMedia().size());
932 public void testMultipleFieldObservationsNotSupported(){
933 specimenFacade
= null;
934 FieldObservation secondFieldObject
= FieldObservation
.NewInstance();
935 firstDerivationEvent
.addOriginal(secondFieldObject
);
937 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
938 Assert
.fail("Multiple field observations for one specimen should no be supported by the facade");
939 } catch (DerivedUnitFacadeNotSupportedException e
) {
942 Assert
.assertNull("Specimen facade should not be initialized", specimenFacade
);
946 public void testOnlyImageGallerySupported(){
947 specimenFacade
= null;
948 firstFieldObject
.addMedia(media1
);
950 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
951 Assert
.fail("Only image galleries are supported by the facade but not direct media");
952 } catch (DerivedUnitFacadeNotSupportedException e
) {
955 Assert
.assertNull("Specimen facade should not be initialized", specimenFacade
);
959 public void testEventPropagation(){
960 specimenFacade
.setDistanceToGround(24);