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
;
14 import java
.text
.ParseException
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.junit
.Assert
;
21 import org
.junit
.Before
;
22 import org
.junit
.Ignore
;
23 import org
.junit
.Test
;
24 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
25 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
26 import org
.unitils
.dbunit
.annotation
.DataSet
;
27 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
28 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
30 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
34 import eu
.etaxonomy
.cdm
.common
.UTF8
;
35 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
36 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
37 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
38 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
39 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
40 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
41 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
42 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
43 import eu
.etaxonomy
.cdm
.model
.common
.User
;
44 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
45 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
46 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
47 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
48 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
49 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
50 import eu
.etaxonomy
.cdm
.model
.location
.WaterbodyOrCountry
;
51 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
52 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
53 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
54 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
55 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
63 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
64 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
65 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
75 public class DerivedUnitFacadeTest
extends CdmTransactionalIntegrationTest
{
76 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeTest
.class);
79 private IOccurrenceService service
;
82 private ITermService termService
;
85 private IUserService userService
;
89 DerivationEvent derivationEvent
;
90 FieldObservation fieldObservation
;
91 GatheringEvent gatheringEvent
;
92 Integer absoluteElevation
= 10;
93 Integer absoluteElevationMaximum
= 14;
94 AgentBase
<?
> collector
= Team
.NewInstance();
95 String collectingMethod
= "Collection Method";
96 Integer distanceToGround
= 22;
97 Integer distanceToSurface
= 50;
98 ReferenceSystem referenceSystem
= ReferenceSystem
.WGS84();
99 Point exactLocation
= Point
.NewInstance(12.3, 10.567, referenceSystem
, 22);
100 String gatheringEventDescription
= "A nice gathering description";
101 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(1888, 1889);
103 String fieldNumber
= "15p23B";
104 String fieldNotes
= "such a beautiful specimen";
106 Integer individualCount
= 1;
107 DefinedTerm lifeStage
= DefinedTerm
.NewStageInstance("A wonderful stage", "stage", "st");
108 DefinedTerm sex
= DefinedTerm
.NewSexInstance("FemaleMale", "FM", "FM");
109 LanguageString locality
= LanguageString
.NewInstance("My locality",
112 String accessionNumber
= "888462535";
113 String catalogNumber
= "UU879873590";
114 TaxonNameBase
<?
,?
> taxonName
= BotanicalName
.NewInstance(Rank
.GENUS(), "Abies",
115 null, null, null, null, null, null, null);
116 String collectorsNumber
= "234589913A34";
117 Collection collection
= Collection
.NewInstance();
118 PreservationMethod preservationMethod
= PreservationMethod
.NewInstance(
119 "my prservation", null, null);
121 DerivedUnitFacade specimenFacade
;
123 Specimen collectionSpecimen
;
124 GatheringEvent existingGatheringEvent
;
125 DerivationEvent firstDerivationEvent
;
126 FieldObservation firstFieldObject
;
127 Media media1
= Media
.NewInstance();
129 DerivedUnitFacade emptyFacade
;
131 NamedArea country
= WaterbodyOrCountry
.GERMANY();
133 // ****************************** SET UP **********************************/
137 * @throws java.lang.Exception
140 public void setUp() throws Exception
{
142 specimen
= Specimen
.NewInstance();
144 derivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
145 specimen
.setDerivedFrom(derivationEvent
);
146 fieldObservation
= FieldObservation
.NewInstance();
147 fieldObservation
.addDerivationEvent(derivationEvent
);
148 gatheringEvent
= GatheringEvent
.NewInstance();
149 fieldObservation
.setGatheringEvent(gatheringEvent
);
150 gatheringEvent
.setAbsoluteElevation(absoluteElevation
);
151 gatheringEvent
.setAbsoluteElevationMax(absoluteElevationMaximum
);
152 gatheringEvent
.setActor(collector
);
153 gatheringEvent
.setCollectingMethod(collectingMethod
);
154 gatheringEvent
.setDistanceToGround(distanceToGround
);
155 gatheringEvent
.setDistanceToWaterSurface(distanceToSurface
);
156 gatheringEvent
.setExactLocation(exactLocation
);
157 gatheringEvent
.setDescription(gatheringEventDescription
);
158 gatheringEvent
.setCountry(country
);
160 gatheringEvent
.setTimeperiod(gatheringPeriod
);
161 gatheringEvent
.setLocality(locality
);
163 fieldObservation
.setFieldNumber(fieldNumber
);
164 fieldObservation
.setFieldNotes(fieldNotes
);
165 fieldObservation
.setIndividualCount(individualCount
);
166 fieldObservation
.setSex(sex
);
167 fieldObservation
.setLifeStage(lifeStage
);
169 specimen
.setAccessionNumber(accessionNumber
);
170 specimen
.setCatalogNumber(catalogNumber
);
171 specimen
.setStoredUnder(taxonName
);
172 specimen
.setCollection(collection
);
173 specimen
.setPreservation(preservationMethod
);
175 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
177 // existing specimen with 2 derivation events in line
178 collectionSpecimen
= Specimen
.NewInstance();
179 Specimen middleSpecimen
= Specimen
.NewInstance();
180 firstFieldObject
= FieldObservation
.NewInstance();
182 //TODO maybe we should define concrete event types here
183 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance();
184 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance();
185 firstDerivationEvent
= DerivationEvent
.NewInstance();
187 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
189 lastDerivationEvent
.addOriginal(middleSpecimen
);
190 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
191 firstDerivationEvent
.addOriginal(firstFieldObject
);
192 existingGatheringEvent
= GatheringEvent
.NewInstance();
193 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
196 emptyFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
200 // ****************************** TESTS*****************************/
202 @Ignore //doesn't run in suite
204 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
206 public void testSetFieldObjectImageGallery() {
207 UUID imageFeatureUuid
= Feature
.IMAGE().getUuid();
208 Feature imageFeature
= (Feature
) termService
.find(imageFeatureUuid
);
210 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
211 facade
.innerDerivedUnit().setUuid(UUID
.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));
212 facade
.setFieldNumber("12345");
213 Media media
= Media
.NewInstance(URI
.create("www.abc.de"), 200, null,"jpeg");
216 SpecimenDescription imageGallery
= SpecimenDescription
.NewInstance();
217 imageGallery
.addDescribedSpecimenOrObservation(facade
.innerFieldObservation());
218 imageGallery
.setImageGallery(true);
219 TextData textData
= TextData
.NewInstance();
220 textData
.setFeature(imageFeature
);
221 imageGallery
.addElement(textData
);
222 textData
.addMedia(media
);
223 facade
.setFieldObjectImageGallery(imageGallery
);
225 } catch (DerivedUnitFacadeNotSupportedException e1
) {
226 e1
.printStackTrace();
227 Assert
.fail(e1
.getLocalizedMessage());
229 this.service
.save(facade
.innerDerivedUnit());
231 setComplete(); endTransaction();
232 try {if (true){printDataSet(System
.out
, new
233 String
[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
235 "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
236 "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
237 } catch(Exception e
) { logger
.warn(e
);}
243 // TODO generally works but has id problems when running together with above
244 // test ()setFieldObjectImageGallery. Therefore set to ignore.
245 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
247 public void testSetDerivedUnitImageGallery() {
248 // UUID specimenUUID =
249 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
250 // Specimen specimen = (Specimen)service.find(specimenUUID);
251 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
252 Media media
= Media
.NewInstance(URI
.create("www.derivedUnitImage.de"),200, null, "png");
255 SpecimenDescription imageGallery
= SpecimenDescription
257 imageGallery
.addDescribedSpecimenOrObservation(facade
258 .innerDerivedUnit());
259 imageGallery
.setImageGallery(true);
260 TextData textData
= TextData
.NewInstance();
261 imageGallery
.addElement(textData
);
262 textData
.addMedia(media
);
263 facade
.setDerivedUnitImageGallery(imageGallery
);
265 } catch (DerivedUnitFacadeNotSupportedException e1
) {
266 e1
.printStackTrace();
267 Assert
.fail(e1
.getLocalizedMessage());
269 this.service
.save(facade
.innerDerivedUnit());
271 // setComplete(); endTransaction();
272 // try {if (true){printDataSet(System.out, new
273 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
274 // ,"DERIVATIONEVENT",
275 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
276 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
277 // } catch(Exception e) { logger.warn(e);}
284 @Ignore // TODO generally works causes has id problems with following tests when running in suite
285 public void testGetFieldObjectImageGalleryBooleanPersisted() {
286 UUID specimenUUID
= UUID
287 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
288 Specimen specimen
= (Specimen
) service
.load(specimenUUID
);
289 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
291 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
292 SpecimenDescription imageGallery
= facade
293 .getFieldObjectImageGallery(true);
294 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
295 Assert
.assertEquals("UUID should be equal to the persisted uuid",
296 UUID
.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
297 imageGallery
.getUuid());
298 Assert
.assertEquals("The image gallery should be flagged as such",
299 true, imageGallery
.isImageGallery());
301 "There should be one TextData in image gallery", 1,
302 imageGallery
.getElements().size());
303 List
<Media
> media
= imageGallery
.getElements().iterator().next()
305 Assert
.assertEquals("There should be 1 media", 1, media
.size());
306 } catch (DerivedUnitFacadeNotSupportedException e
) {
314 // @Ignore // TODO generally works causes has id problems with following tests when running in suite
315 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
316 UUID specimenUUID
= UUID
.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
317 Specimen specimen
= (Specimen
) service
.load(specimenUUID
);
318 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
320 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
321 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
322 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
323 Assert
.assertEquals("UUID should be equal to the persisted uuid",
324 UUID
.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
325 imageGallery
.getUuid());
326 Assert
.assertEquals("The image gallery should be flagged as such",
327 true, imageGallery
.isImageGallery());
329 "There should be one TextData in image gallery", 1,
330 imageGallery
.getElements().size());
331 List
<Media
> media
= imageGallery
.getElements().iterator().next().getMedia();
332 Assert
.assertEquals("There should be 1 media", 1, media
.size());
333 } catch (DerivedUnitFacadeNotSupportedException e
) {
340 public void testGetDerivedUnitImageGalleryBoolean() {
341 Specimen specimen
= Specimen
.NewInstance();
343 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
344 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
345 Assert
.assertNotNull("Image Gallery should have been created",imageGallery
);
346 Assert
.assertEquals("The image gallery should be flagged as such",true, imageGallery
.isImageGallery());
347 } catch (DerivedUnitFacadeNotSupportedException e
) {
356 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
359 public void testNewInstance() {
360 Assert
.assertNotNull("The specimen should have been created",
361 specimenFacade
.innerDerivedUnit());
363 // Assert.assertNotNull("The derivation event should have been created",
364 // specimenFacade.getSpecimen().getDerivedFrom());
365 // Assert.assertNotNull("The field observation should have been created",
366 // specimenFacade.getFieldObservation());
367 // Assert.assertNotNull("The gathering event should have been created",
368 // specimenFacade.getGatheringEvent());
373 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
377 public void testNewInstanceSpecimen() {
378 Assert
.assertSame("Specimen should be same", specimen
,
379 specimenFacade
.innerDerivedUnit());
380 Assert
.assertSame("Derivation event should be same", derivationEvent
,
381 specimenFacade
.innerDerivedUnit().getDerivedFrom());
382 Assert
.assertSame("Field observation should be same", fieldObservation
,
383 specimenFacade
.innerFieldObservation());
384 Assert
.assertSame("Gathering event should be same", gatheringEvent
,
385 specimenFacade
.innerGatheringEvent());
390 public void testGatheringEventIsConnectedToDerivedUnit() {
391 Specimen specimen
= Specimen
.NewInstance();
392 DerivedUnitFacade specimenFacade
;
394 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
395 specimenFacade
.setDistanceToGround(2);
396 FieldObservation specimenFieldObservation
= (FieldObservation
) specimen
397 .getDerivedFrom().getOriginals().iterator().next();
399 "Facade gathering event and specimen gathering event should be the same",
400 specimenFacade
.innerGatheringEvent(),
401 specimenFieldObservation
.getGatheringEvent());
402 } catch (DerivedUnitFacadeNotSupportedException e
) {
403 Assert
.fail("An error should not occur in NewInstance()");
408 public void testNoGatheringEventAndFieldObservation() {
409 Specimen specimen
= Specimen
.NewInstance();
410 DerivedUnitFacade specimenFacade
;
412 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
413 Assert
.assertNull("No field observation should exists",
414 specimenFacade
.innerFieldObservation());
415 } catch (DerivedUnitFacadeNotSupportedException e
) {
416 Assert
.fail("An error should not occur in NewInstance()");
421 public void testInititializeTextDataWithSupportTest() {
423 Specimen specimen
= Specimen
.NewInstance();
424 DerivedUnitFacade specimenFacade
;
426 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
427 specimenFacade
.setEcology("Ecology");
428 String plantDescription
= specimenFacade
.getPlantDescription();
430 "No plantDescription should exist yet and no NPE should be thrown until now",
432 } catch (DerivedUnitFacadeNotSupportedException e
) {
433 Assert
.fail("An error should not occur in NewInstance()");
438 public void testGetSetCountry() {
439 logger
.warn("Not yet implemented");
444 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
448 public void testAddGetRemoveCollectingArea() {
449 String tdwgLabel
= "GER";
450 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
451 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area",
453 specimenFacade
.addCollectingArea(newCollectingArea
);
454 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
455 .getCollectingAreas().size());
456 Assert
.assertSame("Areas should be same", newCollectingArea
,
457 specimenFacade
.innerFieldObservation().getGatheringEvent()
458 .getCollectingAreas().iterator().next());
459 specimenFacade
.addCollectingArea(tdwgArea
);
460 Assert
.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
461 .getCollectingAreas().size());
462 specimenFacade
.removeCollectingArea(newCollectingArea
);
463 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
464 .getCollectingAreas().size());
465 NamedArea remainingArea
= specimenFacade
.getCollectingAreas()
467 Assert
.assertEquals("Areas should be same", tdwgArea
, remainingArea
);
468 specimenFacade
.removeCollectingArea(tdwgArea
);
469 Assert
.assertEquals("No area should remain", 0, specimenFacade
470 .getCollectingAreas().size());
475 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
479 public void testAddCollectingAreas() {
480 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
481 Assert
.assertEquals("No area must exist", 0, specimenFacade
.getCollectingAreas().size());
482 specimenFacade
.addCollectingArea(firstArea
);
483 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
485 String tdwgLabel
= "GER";
486 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
487 NamedArea secondArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
489 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
490 areaCollection
.add(secondArea
);
491 areaCollection
.add(tdwgArea
);
492 specimenFacade
.addCollectingAreas(areaCollection
);
493 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
494 .getCollectingAreas().size());
499 * Test method for getting and setting absolute elevation.
500 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
504 public void testGetSetAbsoluteElevation() {
505 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
506 specimenFacade
.setAbsoluteElevation(400);
507 Assert
.assertEquals("Absolute elevation must be 400",Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
512 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
516 public void testGetSetAbsoluteElevationMaximum() {
517 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
518 Assert
.assertEquals("Absolute elevation maximum must be same",absoluteElevationMaximum
, specimenFacade
.getAbsoluteElevationMaximum());
519 specimenFacade
.setAbsoluteElevationMax(4);
520 Assert
.assertEquals("Absolute elevation maximum must be 4", Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationMaximum());
521 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
526 public void testGetSetAbsoluteElevationRange() {
527 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
528 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
530 specimenFacade
.setAbsoluteElevationRange(30, 36);
531 Assert
.assertEquals("", Integer
.valueOf(36),specimenFacade
.getAbsoluteElevationMaximum());
532 Assert
.assertEquals("", Integer
.valueOf(30),specimenFacade
.getAbsoluteElevation());
533 Assert
.assertEquals("", "30 " + UTF8
.EN_DASH
+ " 36",specimenFacade
.absoluteElevationToString());
534 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
536 specimenFacade
.setAbsoluteElevationRange(30, 35);
537 Assert
.assertEquals("Odd range should not throw an exception anymore", String
.format("30 %s 35", UTF8
.EN_DASH
),specimenFacade
.absoluteElevationToString());
539 specimenFacade
.setAbsoluteElevationRange(41, null);
540 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
541 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
542 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
543 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationText());
544 Assert
.assertEquals("", "41",specimenFacade
.absoluteElevationToString());
546 specimenFacade
.setAbsoluteElevationRange(null, null);
547 Assert
.assertNull("", specimenFacade
.getAbsoluteElevation());
548 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationMaximum());
549 Assert
.assertNull("", specimenFacade
.absoluteElevationToString());
554 public void testGetSetAbsoluteElevationText() {
555 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
556 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
557 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
559 String elevText
= "approx. 30 - 35";
560 specimenFacade
.setAbsoluteElevationText(elevText
);
561 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
562 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
563 Assert
.assertEquals("", elevText
,specimenFacade
.absoluteElevationToString());
565 specimenFacade
.setAbsoluteElevationRange(30, 35);
566 Assert
.assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
567 Assert
.assertEquals("", Integer
.valueOf(30), specimenFacade
.getAbsoluteElevation());
568 Assert
.assertEquals("", Integer
.valueOf(35),specimenFacade
.getAbsoluteElevationMaximum());
571 specimenFacade
.setAbsoluteElevationRange(41, null);
572 Assert
.assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
573 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
574 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
577 specimenFacade
.setAbsoluteElevationText(null);
578 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationText());
579 Assert
.assertEquals("ToString should change by setting text to null", "41",specimenFacade
.absoluteElevationToString());
580 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
581 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
588 public void testGetSetCollector() {
589 Assert
.assertNotNull("Collector must not be null",
590 specimenFacade
.getCollector());
591 Assert
.assertEquals("Collector must be same", collector
,
592 specimenFacade
.getCollector());
593 specimenFacade
.setCollector(null);
594 Assert
.assertNull("Collector must be null",
595 specimenFacade
.getCollector());
600 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
604 public void testGetSetCollectingMethod() {
605 Assert
.assertEquals("Collecting method must be same", collectingMethod
,
606 specimenFacade
.getCollectingMethod());
607 specimenFacade
.setCollectingMethod("new method");
608 Assert
.assertEquals("Collecting method must be 'new method'",
609 "new method", specimenFacade
.getCollectingMethod());
614 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
618 public void testGetSetDistanceToGround() {
619 Assert
.assertEquals("Distance to ground must be same",
620 distanceToGround
, specimenFacade
.getDistanceToGround());
621 specimenFacade
.setDistanceToGround(5);
622 Assert
.assertEquals("Distance to ground must be 5", Integer
.valueOf(5),
623 specimenFacade
.getDistanceToGround());
628 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
632 public void testGetDistanceToWaterSurface() {
633 Assert
.assertEquals("Distance to surface must be same",
634 distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
635 specimenFacade
.setDistanceToWaterSurface(6);
636 Assert
.assertEquals("Distance to surface must be 6",
637 Integer
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
638 // empty facade tests
639 Assert
.assertNull("Empty facace must not have any gathering values",
640 emptyFacade
.getDistanceToWaterSurface());
641 emptyFacade
.setDistanceToWaterSurface(13);
642 Assert
.assertNotNull(
643 "Field observation must exist if distance to water exists",
644 emptyFacade
.getFieldObservation(false));
645 Assert
.assertNotNull(
646 "Gathering event must exist if distance to water exists",
647 emptyFacade
.getGatheringEvent(false));
648 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
649 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
652 "Gathering event of facade and of specimen must be the same",
653 specimenFieldObservation
.getGatheringEvent(),
654 emptyFacade
.getGatheringEvent(false));
659 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
662 public void testGetSetExactLocation() {
663 Assert
.assertNotNull("Exact location must not be null",
664 specimenFacade
.getExactLocation());
665 Assert
.assertEquals("Exact location must be same", exactLocation
,
666 specimenFacade
.getExactLocation());
667 specimenFacade
.setExactLocation(null);
668 Assert
.assertNull("Exact location must be null",
669 specimenFacade
.getExactLocation());
673 public void testSetExactLocationByParsing() {
676 specimenFacade
.setExactLocationByParsing("112\u00B034'20\"W",
677 "34\u00B030,34'N", null, null);
678 point1
= specimenFacade
.getExactLocation();
679 Assert
.assertNotNull("", point1
.getLatitude());
680 System
.out
.println(point1
.getLatitude().toString());
681 Assert
.assertTrue("",
682 point1
.getLatitude().toString().startsWith("34.505"));
683 System
.out
.println(point1
.getLongitude().toString());
684 Assert
.assertTrue("",
685 point1
.getLongitude().toString().startsWith("-112.5722"));
687 } catch (ParseException e
) {
688 Assert
.fail("No parsing error should occur");
694 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
698 public void testGetSetGatheringEventDescription() {
699 Assert
.assertEquals("Gathering event description must be same",
700 gatheringEventDescription
,
701 specimenFacade
.getGatheringEventDescription());
702 specimenFacade
.setGatheringEventDescription("new description");
704 "Gathering event description must be 'new description' now",
706 specimenFacade
.getGatheringEventDescription());
711 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
714 public void testGetTimeperiod() {
715 Assert
.assertNotNull("Gathering period must not be null",
716 specimenFacade
.getGatheringPeriod());
717 Assert
.assertEquals("Gathering period must be same", gatheringPeriod
,
718 specimenFacade
.getGatheringPeriod());
719 specimenFacade
.setGatheringPeriod(null);
720 Assert
.assertNull("Gathering period must be null",
721 specimenFacade
.getGatheringPeriod());
725 public void testHasFieldObject() throws SecurityException
,
726 NoSuchFieldException
, IllegalArgumentException
,
727 IllegalAccessException
{
728 // this test depends on the current implementation of SpecimenFacade. In
730 // field observation may not be initialized from the beginning. Than the
732 // assert should be set to assertNull
734 "field object should not be null (depends on specimen facade initialization !!)",
735 specimenFacade
.hasFieldObject());
737 Field fieldObservationField
= DerivedUnitFacade
.class
738 .getDeclaredField("fieldObservation");
739 fieldObservationField
.setAccessible(true);
740 fieldObservationField
.set(specimenFacade
, null);
741 Assert
.assertFalse("The field observation should be null now",
742 specimenFacade
.hasFieldObject());
744 specimenFacade
.setDistanceToGround(33);
746 "The field observation should have been created again",
747 specimenFacade
.hasFieldObject());
752 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
756 public void testAddGetRemoveFieldObjectDefinition() {
757 Assert
.assertEquals("There should be no definition yet", 0,
758 specimenFacade
.getFieldObjectDefinition().size());
759 specimenFacade
.addFieldObjectDefinition("Tres interesant",
761 Assert
.assertEquals("There should be exactly one definition", 1,
762 specimenFacade
.getFieldObjectDefinition().size());
764 "The French definition should be 'Tres interesant'",
765 "Tres interesant", specimenFacade
.getFieldObjectDefinition()
766 .get(Language
.FRENCH()).getText());
768 "The French definition should be 'Tres interesant'",
770 specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
771 specimenFacade
.addFieldObjectDefinition("Sehr interessant",
773 Assert
.assertEquals("There should be exactly 2 definition", 2,
774 specimenFacade
.getFieldObjectDefinition().size());
775 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
776 Assert
.assertEquals("There should remain exactly 1 definition", 1,
777 specimenFacade
.getFieldObjectDefinition().size());
779 "The remaining German definition should be 'Sehr interessant'",
781 specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
782 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
783 Assert
.assertEquals("There should remain no definition", 0,
784 specimenFacade
.getFieldObjectDefinition().size());
789 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
793 public void testAddGetHasRemoveFieldObjectMedia() {
794 Assert
.assertFalse("There should be no image gallery yet",
795 specimenFacade
.hasFieldObjectImageGallery());
796 Assert
.assertFalse("There should be no specimen image gallery either",
797 specimenFacade
.hasDerivedUnitImageGallery());
799 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
800 Assert
.assertFalse("There should still not be an image gallery now",
801 specimenFacade
.hasFieldObjectImageGallery());
802 Assert
.assertEquals("There should be no media yet in the gallery", 0,
805 Media media1
= Media
.NewInstance();
806 specimenFacade
.addFieldObjectMedia(media1
);
807 Assert
.assertEquals("There should be exactly one specimen media", 1,
808 specimenFacade
.getFieldObjectMedia().size());
809 Assert
.assertEquals("The only media should be media 1", media1
,
810 specimenFacade
.getFieldObjectMedia().get(0));
812 "There should still no specimen image gallery exist",
813 specimenFacade
.hasDerivedUnitImageGallery());
815 Media media2
= Media
.NewInstance();
816 specimenFacade
.addFieldObjectMedia(media2
);
817 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
818 specimenFacade
.getFieldObjectMedia().size());
819 Assert
.assertEquals("The first media should be media1", media1
,
820 specimenFacade
.getFieldObjectMedia().get(0));
821 Assert
.assertEquals("The second media should be media2", media2
,
822 specimenFacade
.getFieldObjectMedia().get(1));
824 specimenFacade
.removeFieldObjectMedia(media1
);
825 Assert
.assertEquals("There should be exactly one specimen media", 1,
826 specimenFacade
.getFieldObjectMedia().size());
827 Assert
.assertEquals("The only media should be media2", media2
,
828 specimenFacade
.getFieldObjectMedia().get(0));
830 specimenFacade
.removeFieldObjectMedia(media1
);
831 Assert
.assertEquals("There should still be exactly one specimen media",
832 1, specimenFacade
.getFieldObjectMedia().size());
834 specimenFacade
.removeFieldObjectMedia(media2
);
835 Assert
.assertEquals("There should remain no media in the gallery", 0,
842 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
846 public void testGetSetEcology() {
847 Assert
.assertNotNull(
848 "An empty ecology data should be created when calling getEcology()",
849 specimenFacade
.getEcologyAll());
851 "An empty ecology data should be created when calling getEcology()",
852 0, specimenFacade
.getEcologyAll().size());
853 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
854 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
855 specimenFacade
.getEcologyAll().size());
857 "Ecology data should be 'Tres jolie ici' for French",
858 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
860 "Ecology data should be null for the default language",
861 specimenFacade
.getEcology());
862 specimenFacade
.setEcology("Nice here");
863 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
864 specimenFacade
.getEcologyAll().size());
865 Assert
.assertEquals("Ecology data should be 'Tres jolie ici'",
866 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
868 "Ecology data should be 'Nice here' for the default language",
869 "Nice here", specimenFacade
.getEcology());
870 Assert
.assertEquals("Ecology data should be 'Nice here' for english",
871 "Nice here", specimenFacade
.getEcology());
873 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
874 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
875 specimenFacade
.getEcologyAll().size());
876 Assert
.assertEquals("Ecology data should be 'Vert et rouge'",
877 "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
879 "Ecology data should be 'Nice here' for the default language",
880 "Nice here", specimenFacade
.getEcology());
882 specimenFacade
.setEcology(null, Language
.FRENCH());
883 Assert
.assertEquals("Ecology data should exist for 1 languages", 1,
884 specimenFacade
.getEcologyAll().size());
886 "Ecology data should be 'Nice here' for the default language",
887 "Nice here", specimenFacade
.getEcology());
888 Assert
.assertNull("Ecology data should be 'null' for French",
889 specimenFacade
.getEcology(Language
.FRENCH()));
891 specimenFacade
.removeEcology(null);
892 Assert
.assertEquals("There should be no ecology left", 0,
893 specimenFacade
.getEcologyAll().size());
894 Assert
.assertNull("Ecology data should be 'null' for default language",
895 specimenFacade
.getEcology());
901 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
905 public void testGetSetPlantDescription() {
906 Assert
.assertNotNull(
907 "An empty plant description data should be created when calling getPlantDescriptionAll()",
908 specimenFacade
.getPlantDescriptionAll());
910 "An empty plant description data should be created when calling getPlantDescription()",
911 0, specimenFacade
.getPlantDescriptionAll().size());
912 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
914 "Plant description data should exist for 1 language", 1,
915 specimenFacade
.getPlantDescriptionAll().size());
917 "Plant description data should be 'bleu' for French", "bleu",
918 specimenFacade
.getPlantDescription(Language
.FRENCH()));
920 "Plant description data should be null for the default language",
921 specimenFacade
.getPlantDescription());
922 specimenFacade
.setPlantDescription("Nice here");
924 "Plant description data should exist for 2 languages", 2,
925 specimenFacade
.getPlantDescriptionAll().size());
926 Assert
.assertEquals("Plant description data should be 'bleu'", "bleu",
927 specimenFacade
.getPlantDescription(Language
.FRENCH()));
929 "Plant description data should be 'Nice here' for the default language",
930 "Nice here", specimenFacade
.getPlantDescription());
932 "Plant description data should be 'Nice here' for english",
933 "Nice here", specimenFacade
.getPlantDescription());
935 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
937 "Plant description data should exist for 2 languages", 2,
938 specimenFacade
.getPlantDescriptionAll().size());
939 Assert
.assertEquals("Plant description data should be 'Vert et rouge'",
941 specimenFacade
.getPlantDescription(Language
.FRENCH()));
943 "Plant description data should be 'Nice here' for the default language",
944 "Nice here", specimenFacade
.getPlantDescription());
946 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
948 "Plant description data should exist for 1 languages", 1,
949 specimenFacade
.getPlantDescriptionAll().size());
951 "Plant description data should be 'Nice here' for the default language",
952 "Nice here", specimenFacade
.getPlantDescription());
953 Assert
.assertNull("Plant description data should be 'null' for French",
954 specimenFacade
.getPlantDescription(Language
.FRENCH()));
956 // test interference with ecology
957 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
958 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
959 specimenFacade
.getEcologyAll().size());
961 "Ecology data should be 'Tres jolie ici' for French",
962 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
964 "Ecology data should be null for the default language",
965 specimenFacade
.getEcology());
969 "Plant description data should exist for 1 languages", 1,
970 specimenFacade
.getPlantDescriptionAll().size());
972 "Plant description data should be 'Nice here' for the default language",
973 "Nice here", specimenFacade
.getPlantDescription());
974 Assert
.assertNull("Plant description data should be 'null' for French",
975 specimenFacade
.getPlantDescription(Language
.FRENCH()));
977 specimenFacade
.removePlantDescription(null);
978 Assert
.assertEquals("There should be no plant description left", 0,
979 specimenFacade
.getPlantDescriptionAll().size());
981 "Plant description data should be 'null' for default language",
982 specimenFacade
.getPlantDescription());
988 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
991 public void testGetSetFieldNumber() {
992 Assert
.assertEquals("Field number must be same", fieldNumber
,
993 specimenFacade
.getFieldNumber());
994 specimenFacade
.setFieldNumber("564AB");
995 Assert
.assertEquals("New field number must be '564AB'", "564AB",
996 specimenFacade
.getFieldNumber());
997 // empty facade tests
998 Assert
.assertNull("Empty facace must not have any field value",
999 emptyFacade
.getFieldNumber());
1000 emptyFacade
.setFieldNumber("1256A");
1001 Assert
.assertNotNull(
1002 "Field observation must exist if field number exists",
1003 emptyFacade
.getFieldObservation(false));
1004 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
1005 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
1008 "Field observation of facade and of specimen must be the same",
1009 specimenFieldObservation
,
1010 emptyFacade
.getFieldObservation(false));
1011 Assert
.assertEquals("1256A", emptyFacade
.getFieldNumber());
1016 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
1019 public void testGetSetFieldNotes() {
1020 Assert
.assertEquals("Field notes must be same", fieldNotes
,
1021 specimenFacade
.getFieldNotes());
1022 specimenFacade
.setFieldNotes("A completely new info");
1023 Assert
.assertEquals("New field note must be 'A completely new info'",
1024 "A completely new info", specimenFacade
.getFieldNotes());
1029 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1033 @Ignore // #######DerivationEvent ---------------------------------------- 1
1034 public void testSetGatheringEvent() {
1035 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1036 newGatheringEvent
.setDistanceToGround(43);
1037 Assert
.assertFalse("The initial distance to ground should not be 43",
1038 specimenFacade
.getDistanceToGround() == 43);
1039 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1040 Assert
.assertTrue("The final distance to ground should be 43",
1041 specimenFacade
.getDistanceToGround() == 43);
1043 "The new gathering event should be 'newGatheringEvent'",
1044 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1049 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1053 public void testGetGatheringEvent() {
1054 Assert
.assertNotNull("Gathering event must not be null",
1055 specimenFacade
.innerGatheringEvent());
1056 Assert
.assertEquals(
1057 "Gathering event must be field observations gathering event",
1058 specimenFacade
.innerFieldObservation().getGatheringEvent(),
1059 specimenFacade
.innerGatheringEvent());
1064 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1068 public void testGetSetIndividualCount() {
1069 Assert
.assertEquals("Individual count must be same", individualCount
,
1070 specimenFacade
.getIndividualCount());
1071 specimenFacade
.setIndividualCount(4);
1072 Assert
.assertEquals("New individual count must be '4'",
1073 Integer
.valueOf(4), specimenFacade
.getIndividualCount());
1079 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1082 public void testGetSetLifeStage() {
1083 Assert
.assertNotNull("Life stage must not be null",
1084 specimenFacade
.getLifeStage());
1085 Assert
.assertEquals("Life stage must be same", lifeStage
,
1086 specimenFacade
.getLifeStage());
1087 specimenFacade
.setLifeStage(null);
1088 Assert
.assertNull("Life stage must be null",
1089 specimenFacade
.getLifeStage());
1094 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1097 public void testGetSetSex() {
1098 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
1099 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1100 specimenFacade
.setSex(null);
1101 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
1106 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1109 public void testGetSetLocality() {
1110 Assert
.assertEquals("Locality must be same", locality
,
1111 specimenFacade
.getLocality());
1112 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1113 Assert
.assertEquals("New locality must be 'A completely new place'",
1114 "A completely new place", specimenFacade
.getLocalityText());
1115 Assert
.assertEquals("New locality language must be French",
1116 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1117 specimenFacade
.setLocality("Another place");
1118 Assert
.assertEquals("New locality must be 'Another place'",
1119 "Another place", specimenFacade
.getLocalityText());
1120 Assert
.assertEquals("New locality language must be default",
1121 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1126 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1130 public void testAddGetRemoveSpecimenDefinition() {
1131 Assert
.assertEquals("There should be no definition yet", 0,
1132 specimenFacade
.getDerivedUnitDefinitions().size());
1133 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1135 Assert
.assertEquals("There should be exactly one definition", 1,
1136 specimenFacade
.getDerivedUnitDefinitions().size());
1137 Assert
.assertEquals(
1138 "The French definition should be 'Tres interesant'",
1139 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1140 .get(Language
.FRENCH()).getText());
1141 Assert
.assertEquals(
1142 "The French definition should be 'Tres interesant'",
1144 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1145 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1147 Assert
.assertEquals("There should be exactly 2 definition", 2,
1148 specimenFacade
.getDerivedUnitDefinitions().size());
1149 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1150 Assert
.assertEquals("There should remain exactly 1 definition", 1,
1151 specimenFacade
.getDerivedUnitDefinitions().size());
1152 Assert
.assertEquals(
1153 "The remaining German definition should be 'Sehr interessant'",
1155 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1156 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1157 Assert
.assertEquals("There should remain no definition", 0,
1158 specimenFacade
.getDerivedUnitDefinitions().size());
1163 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1167 public void testAddGetRemoveDetermination() {
1168 Assert
.assertEquals("There should be no determination yet", 0,
1169 specimenFacade
.getDeterminations().size());
1170 DeterminationEvent determinationEvent1
= DeterminationEvent
1172 specimenFacade
.addDetermination(determinationEvent1
);
1173 Assert
.assertEquals("There should be exactly one determination", 1,
1174 specimenFacade
.getDeterminations().size());
1175 Assert
.assertEquals("The only determination should be determination 1",
1176 determinationEvent1
, specimenFacade
.getDeterminations()
1177 .iterator().next());
1179 DeterminationEvent determinationEvent2
= DeterminationEvent
1181 specimenFacade
.addDetermination(determinationEvent2
);
1182 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1183 specimenFacade
.getDeterminations().size());
1184 specimenFacade
.removeDetermination(determinationEvent1
);
1186 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1187 specimenFacade
.getDeterminations().size());
1188 Assert
.assertEquals(
1189 "The remaining determinations should be determination 2",
1190 determinationEvent2
, specimenFacade
.getDeterminations()
1191 .iterator().next());
1193 specimenFacade
.removeDetermination(determinationEvent1
);
1194 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1195 specimenFacade
.getDeterminations().size());
1197 specimenFacade
.removeDetermination(determinationEvent2
);
1198 Assert
.assertEquals("There should remain no definition", 0,
1199 specimenFacade
.getDerivedUnitDefinitions().size());
1206 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1210 public void testPreferredOtherDeterminations() {
1211 Assert
.assertEquals("There should be no determination yet", 0,
1212 specimenFacade
.getDeterminations().size());
1213 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1214 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1216 Assert
.assertEquals("There should be exactly one determination", 1,
1217 specimenFacade
.getDeterminations().size());
1218 Assert
.assertEquals("The only determination should be determination 1",
1219 determinationEvent1
, specimenFacade
.getDeterminations()
1220 .iterator().next());
1221 Assert
.assertEquals("determination 1 should be the preferred determination",
1222 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1223 Assert
.assertEquals("There should be no 'non preferred' determination", 0,
1224 specimenFacade
.getOtherDeterminations().size());
1228 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1229 specimenFacade
.addDetermination(determinationEvent2
);
1230 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1231 specimenFacade
.getDeterminations().size());
1232 Assert
.assertEquals("determination 1 should be the preferred determination",
1233 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1234 Assert
.assertEquals("There should be one 'non preferred' determination", 1,
1235 specimenFacade
.getOtherDeterminations().size());
1236 Assert
.assertEquals("The only 'non preferred' determination should be determination 2",
1237 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1240 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1241 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1242 Assert
.assertEquals("There should be exactly 3 determinations", 3,
1243 specimenFacade
.getDeterminations().size());
1244 Assert
.assertEquals("determination 3 should be the preferred determination",
1245 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1246 Assert
.assertEquals("There should be 2 'non preferred' determination", 2,
1247 specimenFacade
.getOtherDeterminations().size());
1248 Assert
.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1249 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1250 Assert
.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1251 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1257 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1261 public void testAddGetHasRemoveSpecimenMedia() {
1262 Assert
.assertFalse("There should be no image gallery yet",
1263 specimenFacade
.hasDerivedUnitImageGallery());
1265 "There should be also no field object image gallery yet",
1266 specimenFacade
.hasFieldObjectImageGallery());
1268 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1270 "There should still not be an empty image gallery now",
1271 specimenFacade
.hasDerivedUnitImageGallery());
1272 Assert
.assertEquals("There should be no media yet in the gallery", 0,
1275 Media media1
= Media
.NewInstance();
1276 specimenFacade
.addDerivedUnitMedia(media1
);
1277 Assert
.assertEquals("There should be exactly one specimen media", 1,
1278 specimenFacade
.getDerivedUnitMedia().size());
1279 Assert
.assertEquals("The only media should be media 1", media1
,
1280 specimenFacade
.getDerivedUnitMedia().get(0));
1282 "There should be still no field object image gallery",
1283 specimenFacade
.hasFieldObjectImageGallery());
1285 Media media2
= Media
.NewInstance();
1286 specimenFacade
.addDerivedUnitMedia(media2
);
1287 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
1288 specimenFacade
.getDerivedUnitMedia().size());
1289 Assert
.assertEquals("The first media should be media1", media1
,
1290 specimenFacade
.getDerivedUnitMedia().get(0));
1291 Assert
.assertEquals("The second media should be media2", media2
,
1292 specimenFacade
.getDerivedUnitMedia().get(1));
1294 specimenFacade
.removeDerivedUnitMedia(media1
);
1295 Assert
.assertEquals("There should be exactly one specimen media", 1,
1296 specimenFacade
.getDerivedUnitMedia().size());
1297 Assert
.assertEquals("The only media should be media2", media2
,
1298 specimenFacade
.getDerivedUnitMedia().get(0));
1300 specimenFacade
.removeDerivedUnitMedia(media1
);
1301 Assert
.assertEquals("There should still be exactly one specimen media",
1302 1, specimenFacade
.getDerivedUnitMedia().size());
1304 specimenFacade
.removeDerivedUnitMedia(media2
);
1305 Assert
.assertEquals("There should remain no media in the gallery", 0,
1311 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1315 public void testGetSetAccessionNumber() {
1316 Assert
.assertEquals("Accession number must be same", accessionNumber
,
1317 specimenFacade
.getAccessionNumber());
1318 specimenFacade
.setAccessionNumber("A12345693");
1319 Assert
.assertEquals("New accession number must be 'A12345693'",
1320 "A12345693", specimenFacade
.getAccessionNumber());
1325 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1328 public void testGetCatalogNumber() {
1329 Assert
.assertEquals("Catalog number must be same", catalogNumber
,
1330 specimenFacade
.getCatalogNumber());
1331 specimenFacade
.setCatalogNumber("B12345693");
1332 Assert
.assertEquals("New catalog number must be 'B12345693'",
1333 "B12345693", specimenFacade
.getCatalogNumber());
1338 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1341 public void testGetPreservation() {
1343 Assert
.assertNotNull("Preservation method must not be null",
1344 specimenFacade
.getPreservationMethod());
1345 Assert
.assertEquals("Preservation method must be same",
1346 preservationMethod
, specimenFacade
.getPreservationMethod());
1347 specimenFacade
.setPreservationMethod(null);
1348 Assert
.assertNull("Preservation method must be null",
1349 specimenFacade
.getPreservationMethod());
1350 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1351 Assert
.fail("Method not supported should not be thrown for a specimen");
1353 specimenFacade
= DerivedUnitFacade
1354 .NewInstance(DerivedUnitType
.Observation
);
1356 specimenFacade
.setPreservationMethod(preservationMethod
);
1357 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
1359 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1362 specimenFacade
= DerivedUnitFacade
1363 .NewInstance(DerivedUnitType
.LivingBeing
);
1365 specimenFacade
.getPreservationMethod();
1366 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
1367 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1375 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1378 public void testGetStoredUnder() {
1379 Assert
.assertNotNull("Stored under name must not be null",
1380 specimenFacade
.getStoredUnder());
1381 Assert
.assertEquals("Stored under name must be same", taxonName
,
1382 specimenFacade
.getStoredUnder());
1383 specimenFacade
.setStoredUnder(null);
1384 Assert
.assertNull("Stored under name must be null",
1385 specimenFacade
.getStoredUnder());
1389 // * Test method for
1390 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1394 // public void testGetSetCollectorsNumber() {
1395 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1396 // specimenFacade.getCollectorsNumber());
1397 // specimenFacade.setCollectorsNumber("C12345693");
1398 // Assert.assertEquals("New collectors number must be 'C12345693'",
1399 // "C12345693", specimenFacade.getCollectorsNumber());
1404 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1407 public void testGetTitleCache() {
1408 Assert
.assertNotNull(
1409 "The title cache should never return null if not protected",
1410 specimenFacade
.getTitleCache());
1411 specimenFacade
.setTitleCache(null, false);
1412 Assert
.assertNotNull(
1413 "The title cache should never return null if not protected",
1414 specimenFacade
.getTitleCache());
1419 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1423 public void testSetTitleCache() {
1424 String testTitle
= "Absdwk aksjlf";
1425 specimenFacade
.setTitleCache(testTitle
, true);
1426 Assert
.assertEquals(
1427 "Protected title cache should returns the test title",
1428 testTitle
, specimenFacade
.getTitleCache());
1429 specimenFacade
.setTitleCache(testTitle
, false);
1431 "Unprotected title cache should not return the test title",
1432 testTitle
.equals(specimenFacade
.getTitleCache()));
1437 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1440 public void testGetSpecimen() {
1441 Assert
.assertEquals("Specimen must be same", specimen
,
1442 specimenFacade
.innerDerivedUnit());
1447 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1450 public void testGetSetCollection() {
1451 Assert
.assertNotNull("Collection must not be null",
1452 specimenFacade
.getCollection());
1453 Assert
.assertEquals("Collection must be same", collection
,
1454 specimenFacade
.getCollection());
1455 specimenFacade
.setCollection(null);
1456 Assert
.assertNull("Collection must be null",
1457 specimenFacade
.getCollection());
1461 public void testAddGetRemoveSource() {
1462 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
.getSources().size());
1464 Reference
<?
> reference
= ReferenceFactory
.newBook();
1465 IdentifiableSource source1
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference
, "54", "myName");
1466 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1467 IdentifiableSource source2
= IdentifiableSource
.NewDataImportInstance("1", "myTable");
1468 specimenFacade
.addSource(source2
);
1469 Assert
.assertEquals("One source should exist now", 2, specimenFacade
.getSources().size());
1470 specimenFacade
.removeSource(source1
);
1471 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1472 Reference
<?
> reference2
= ReferenceFactory
.newJournal();
1473 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference2
,null, null);
1474 specimenFacade
.removeSource(sourceNotUsed
);
1475 Assert
.assertEquals("One source should still exist", 1, specimenFacade
.getSources().size());
1476 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next().getIdInSource());
1477 specimenFacade
.removeSource(source2
);
1478 Assert
.assertEquals("No sources should exist anymore", 0,specimenFacade
.getSources().size());
1482 public void testAddGetRemoveDuplicate() {
1483 Assert
.assertEquals("No duplicates should be available yet", 0,specimenFacade
.getDuplicates().size());
1484 Specimen newSpecimen1
= Specimen
.NewInstance();
1485 specimenFacade
.addDuplicate(newSpecimen1
);
1486 Assert
.assertEquals("There should be 1 duplicate now", 1,specimenFacade
.getDuplicates().size());
1487 Specimen newSpecimen2
= Specimen
.NewInstance();
1488 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
1489 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1491 "The derivation event should be 'newDerivationEvent'",
1492 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1493 specimenFacade
.addDuplicate(newSpecimen2
);
1494 Assert
.assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
1495 Assert
.assertNotSame(
1496 "The derivation event should not be 'newDerivationEvent' anymore",
1497 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1499 "The derivation event should not be the facades derivation event",
1500 derivationEvent
, newSpecimen2
.getDerivedFrom());
1501 specimenFacade
.removeDuplicate(newSpecimen1
);
1502 Assert
.assertEquals("There should be 1 duplicate now", 1,
1503 specimenFacade
.getDuplicates().size());
1504 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now",
1505 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1506 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1507 Assert
.assertEquals(
1508 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1509 1, specimenFacade
.getDuplicates().size());
1511 Collection newCollection
= Collection
.NewInstance();
1512 String catalogNumber
= "1234890";
1513 String accessionNumber
= "345345";
1514 String collectorsNumber
= "lkjewe";
1515 TaxonNameBase
<?
,?
> storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
1516 PreservationMethod method
= PreservationMethod
.NewInstance();
1517 Specimen duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1518 catalogNumber
, accessionNumber
, storedUnder
,
1520 Assert
.assertEquals("There should be 2 duplicates now", 2,
1521 specimenFacade
.getDuplicates().size());
1522 specimenFacade
.removeDuplicate(newSpecimen2
);
1523 Assert
.assertEquals("There should be 1 duplicates now", 1,
1524 specimenFacade
.getDuplicates().size());
1525 Collection sameCollection
= specimenFacade
.getDuplicates().iterator()
1526 .next().getCollection();
1527 Assert
.assertSame("Collections should be same", newCollection
,
1531 // ************************** Existing Specimen with multiple derivation
1532 // events in line **************/
1535 public void testExistingSpecimen() {
1536 specimenFacade
= null;
1538 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1539 } catch (DerivedUnitFacadeNotSupportedException e
) {
1540 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
1543 "Gathering event should derive from the derivation line",
1544 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1545 Assert
.assertEquals(
1546 "Mediasize should be 0. Only Imagegallery media are supported",
1547 0, specimenFacade
.getFieldObjectMedia().size());
1551 public void testMultipleFieldObservationsNotSupported() {
1552 specimenFacade
= null;
1553 FieldObservation secondFieldObject
= FieldObservation
.NewInstance();
1554 firstDerivationEvent
.addOriginal(secondFieldObject
);
1556 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1557 Assert
.fail("Multiple field observations for one specimen should no be supported by the facade");
1558 } catch (DerivedUnitFacadeNotSupportedException e
) {
1561 Assert
.assertNull("Specimen facade should not be initialized",
1565 @Test // #######DerivationEvent
1566 public void testOnlyImageGallerySupported() {
1567 specimenFacade
= null;
1568 firstFieldObject
.addMedia(media1
);
1570 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1571 Assert
.fail("Only image galleries are supported by the facade but not direct media");
1572 } catch (DerivedUnitFacadeNotSupportedException e
) {
1575 Assert
.assertNull("Specimen facade should not be initialized",
1579 @Test // #######DerivationEvent
1580 public void testEventPropagation() {
1581 specimenFacade
.setDistanceToGround(24);
1585 // @Ignore // set to ignore because I did not want to check knowingly
1586 // failing tests. Remove @Ignore when this is fixed
1588 public void testSetBarcode() {
1589 String barcode
= "barcode";
1590 specimenFacade
.setBarcode(barcode
);
1592 Assert
.assertEquals(barcode
, specimenFacade
.getBarcode());
1596 public void testIsEvenDistance() {
1597 Integer minimum
= 20;
1598 Integer maximum
= 1234;
1600 // this should not throw exceptions
1601 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1606 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1607 * This test doesn't handle the above issue yet as it doesn't fire events as
1608 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1609 * In the meanwhile the property change framework for the facade has been changed
1610 * so the original problem may have disappeared.
1614 public void testNoRecursiveChangeEvents(){
1615 String username
= "username";
1616 String password
= "password";
1617 User user
= User
.NewInstance(username
, password
);
1618 userService
.save(user
);
1619 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1620 SecurityContextHolder
.getContext().setAuthentication(token
);
1622 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
1623 facade
.setLocality("testLocality");
1624 facade
.getTitleCache();
1625 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1626 this.service
.save(facade
.innerDerivedUnit());
1627 commitAndStartNewTransaction(null);