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
.BeforeClass
;
23 import org
.junit
.Ignore
;
24 import org
.junit
.Test
;
25 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
26 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
27 import org
.unitils
.dbunit
.annotation
.DataSet
;
28 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
29 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
31 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
35 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
36 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
37 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
38 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
39 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
40 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
41 import eu
.etaxonomy
.cdm
.model
.common
.User
;
42 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Sex
;
44 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
45 import eu
.etaxonomy
.cdm
.model
.description
.Stage
;
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
.TdwgArea
;
51 import eu
.etaxonomy
.cdm
.model
.location
.WaterbodyOrCountry
;
52 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
53 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
54 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
55 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
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
;
72 public class DerivedUnitFacadeTest
extends CdmTransactionalIntegrationTest
{
73 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeTest
.class);
76 private IOccurrenceService service
;
79 private ITermService termService
;
82 DerivationEvent derivationEvent
;
83 FieldObservation fieldObservation
;
84 GatheringEvent gatheringEvent
;
85 Integer absoluteElevation
= 10;
86 Integer absoluteElevationError
= 2;
87 AgentBase collector
= Team
.NewInstance();
88 String collectingMethod
= "Collection Method";
89 Integer distanceToGround
= 22;
90 Integer distanceToSurface
= 50;
91 ReferenceSystem referenceSystem
= ReferenceSystem
.WGS84();
92 Point exactLocation
= Point
.NewInstance(12.3, 10.567, referenceSystem
, 22);
93 String gatheringEventDescription
= "A nice gathering description";
94 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(1888, 1889);
96 String fieldNumber
= "15p23B";
97 String fieldNotes
= "such a beautiful specimen";
99 Integer individualCount
= 1;
100 Stage lifeStage
= Stage
.NewInstance("A wonderful stage", "stage", "st");
101 Sex sex
= Sex
.NewInstance("FemaleMale", "FM", "FM");
102 LanguageString locality
= LanguageString
.NewInstance("My locality",
105 String accessionNumber
= "888462535";
106 String catalogNumber
= "UU879873590";
107 TaxonNameBase taxonName
= BotanicalName
.NewInstance(Rank
.GENUS(), "Abies",
108 null, null, null, null, null, null, null);
109 String collectorsNumber
= "234589913A34";
110 Collection collection
= Collection
.NewInstance();
111 PreservationMethod preservationMethod
= PreservationMethod
.NewInstance(
112 "my prservation", null, null);
114 DerivedUnitFacade specimenFacade
;
116 Specimen collectionSpecimen
;
117 GatheringEvent existingGatheringEvent
;
118 DerivationEvent firstDerivationEvent
;
119 FieldObservation firstFieldObject
;
120 Media media1
= Media
.NewInstance();
122 DerivedUnitFacade emptyFacade
;
124 NamedArea country
= WaterbodyOrCountry
.GERMANY();
126 // ****************************** SET UP **********************************/
129 * @throws java.lang.Exception
132 public static void setUpBeforeClass() throws Exception
{
133 // new DefaultTermInitializer().initialize();
137 * @throws java.lang.Exception
140 public void setUp() throws Exception
{
141 specimen
= Specimen
.NewInstance();
143 derivationEvent
= DerivationEvent
.NewInstance();
144 specimen
.setDerivedFrom(derivationEvent
);
145 fieldObservation
= FieldObservation
.NewInstance();
146 fieldObservation
.addDerivationEvent(derivationEvent
);
147 gatheringEvent
= GatheringEvent
.NewInstance();
148 fieldObservation
.setGatheringEvent(gatheringEvent
);
149 gatheringEvent
.setAbsoluteElevation(absoluteElevation
);
150 gatheringEvent
.setAbsoluteElevationError(absoluteElevationError
);
151 gatheringEvent
.setActor(collector
);
152 gatheringEvent
.setCollectingMethod(collectingMethod
);
153 gatheringEvent
.setDistanceToGround(distanceToGround
);
154 gatheringEvent
.setDistanceToWaterSurface(distanceToSurface
);
155 gatheringEvent
.setExactLocation(exactLocation
);
156 gatheringEvent
.setDescription(gatheringEventDescription
);
157 gatheringEvent
.setCountry(country
);
159 gatheringEvent
.setTimeperiod(gatheringPeriod
);
160 gatheringEvent
.setLocality(locality
);
162 fieldObservation
.setFieldNumber(fieldNumber
);
163 fieldObservation
.setFieldNotes(fieldNotes
);
164 fieldObservation
.setIndividualCount(individualCount
);
165 fieldObservation
.setSex(sex
);
166 fieldObservation
.setLifeStage(lifeStage
);
168 specimen
.setAccessionNumber(accessionNumber
);
169 specimen
.setCatalogNumber(catalogNumber
);
170 specimen
.setStoredUnder(taxonName
);
171 specimen
.setCollection(collection
);
172 specimen
.setPreservation(preservationMethod
);
174 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
176 // existing specimen with 2 derivation events in line
177 collectionSpecimen
= Specimen
.NewInstance();
178 Specimen middleSpecimen
= Specimen
.NewInstance();
179 firstFieldObject
= FieldObservation
.NewInstance();
181 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance();
182 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance();
183 firstDerivationEvent
= DerivationEvent
.NewInstance();
185 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
187 lastDerivationEvent
.addOriginal(middleSpecimen
);
188 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
189 firstDerivationEvent
.addOriginal(firstFieldObject
);
190 existingGatheringEvent
= GatheringEvent
.NewInstance();
191 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
194 emptyFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
198 // ****************************** TESTS*****************************/
200 @Ignore //doesn't run in suite
202 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
204 public void testSetFieldObjectImageGallery() {
205 UUID imageFeatureUuid
= Feature
.IMAGE().getUuid();
206 Feature imageFeature
= (Feature
) termService
.find(imageFeatureUuid
);
208 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
209 facade
.innerDerivedUnit().setUuid(UUID
.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));
210 facade
.setFieldNumber("12345");
211 Media media
= Media
.NewInstance(URI
.create("www.abc.de"), 200, null,"jpeg");
214 SpecimenDescription imageGallery
= SpecimenDescription
.NewInstance();
215 imageGallery
.addDescribedSpecimenOrObservation(facade
.innerFieldObservation());
216 imageGallery
.setImageGallery(true);
217 TextData textData
= TextData
.NewInstance();
218 textData
.setFeature(imageFeature
);
219 imageGallery
.addElement(textData
);
220 textData
.addMedia(media
);
221 facade
.setFieldObjectImageGallery(imageGallery
);
223 } catch (DerivedUnitFacadeNotSupportedException e1
) {
224 e1
.printStackTrace();
225 Assert
.fail(e1
.getLocalizedMessage());
227 this.service
.save(facade
.innerDerivedUnit());
229 setComplete(); endTransaction();
230 try {if (true){printDataSet(System
.out
, new
231 String
[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
233 "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
234 "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
235 } catch(Exception e
) { logger
.warn(e
);}
241 // TODO generally works but has id problems when running together with above
242 // test ()setFieldObjectImageGallery. Therefore set to ignore.
243 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
245 public void testSetDerivedUnitImageGallery() {
246 // UUID specimenUUID =
247 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
248 // Specimen specimen = (Specimen)service.find(specimenUUID);
249 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
250 Media media
= Media
.NewInstance(URI
.create("www.derivedUnitImage.de"),200, null, "png");
253 SpecimenDescription imageGallery
= SpecimenDescription
255 imageGallery
.addDescribedSpecimenOrObservation(facade
256 .innerDerivedUnit());
257 imageGallery
.setImageGallery(true);
258 TextData textData
= TextData
.NewInstance();
259 imageGallery
.addElement(textData
);
260 textData
.addMedia(media
);
261 facade
.setDerivedUnitImageGallery(imageGallery
);
263 } catch (DerivedUnitFacadeNotSupportedException e1
) {
264 e1
.printStackTrace();
265 Assert
.fail(e1
.getLocalizedMessage());
267 this.service
.save(facade
.innerDerivedUnit());
269 // setComplete(); endTransaction();
270 // try {if (true){printDataSet(System.out, new
271 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
272 // ,"DERIVATIONEVENT",
273 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
274 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
275 // } catch(Exception e) { logger.warn(e);}
281 public void testGetFieldObjectImageGalleryBooleanPersisted() {
282 UUID specimenUUID
= UUID
283 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
284 Specimen specimen
= (Specimen
) service
.find(specimenUUID
);
285 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
287 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
288 SpecimenDescription imageGallery
= facade
289 .getFieldObjectImageGallery(true);
290 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
291 Assert
.assertEquals("UUID should be equal to the persisted uuid",
292 UUID
.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
293 imageGallery
.getUuid());
294 Assert
.assertEquals("The image gallery should be flagged as such",
295 true, imageGallery
.isImageGallery());
297 "There should be one TextData in image gallery", 1,
298 imageGallery
.getElements().size());
299 List
<Media
> media
= imageGallery
.getElements().iterator().next()
301 Assert
.assertEquals("There should be 1 media", 1, media
.size());
302 } catch (DerivedUnitFacadeNotSupportedException e
) {
310 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
311 UUID specimenUUID
= UUID
312 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
313 Specimen specimen
= (Specimen
) service
.find(specimenUUID
);
314 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
316 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
317 SpecimenDescription imageGallery
= facade
318 .getDerivedUnitImageGallery(true);
319 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
320 Assert
.assertEquals("UUID should be equal to the persisted uuid",
321 UUID
.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
322 imageGallery
.getUuid());
323 Assert
.assertEquals("The image gallery should be flagged as such",
324 true, imageGallery
.isImageGallery());
326 "There should be one TextData in image gallery", 1,
327 imageGallery
.getElements().size());
328 List
<Media
> media
= imageGallery
.getElements().iterator().next()
330 Assert
.assertEquals("There should be 1 media", 1, media
.size());
331 } catch (DerivedUnitFacadeNotSupportedException e
) {
338 public void testGetDerivedUnitImageGalleryBoolean() {
339 Specimen specimen
= Specimen
.NewInstance();
341 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
342 SpecimenDescription imageGallery
= facade
343 .getDerivedUnitImageGallery(true);
344 Assert
.assertNotNull("Image Gallery should have been created",
346 Assert
.assertEquals("The image gallery should be flagged as such",
347 true, imageGallery
.isImageGallery());
348 } catch (DerivedUnitFacadeNotSupportedException e
) {
357 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
360 public void testNewInstance() {
361 Assert
.assertNotNull("The specimen should have been created",
362 specimenFacade
.innerDerivedUnit());
364 // Assert.assertNotNull("The derivation event should have been created",
365 // specimenFacade.getSpecimen().getDerivedFrom());
366 // Assert.assertNotNull("The field observation should have been created",
367 // specimenFacade.getFieldObservation());
368 // Assert.assertNotNull("The gathering event should have been created",
369 // specimenFacade.getGatheringEvent());
374 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
378 public void testNewInstanceSpecimen() {
379 Assert
.assertSame("Specimen should be same", specimen
,
380 specimenFacade
.innerDerivedUnit());
381 Assert
.assertSame("Derivation event should be same", derivationEvent
,
382 specimenFacade
.innerDerivedUnit().getDerivedFrom());
383 Assert
.assertSame("Field observation should be same", fieldObservation
,
384 specimenFacade
.innerFieldObservation());
385 Assert
.assertSame("Gathering event should be same", gatheringEvent
,
386 specimenFacade
.innerGatheringEvent());
391 public void testGatheringEventIsConnectedToDerivedUnit() {
392 Specimen specimen
= Specimen
.NewInstance();
393 DerivedUnitFacade specimenFacade
;
395 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
396 specimenFacade
.setDistanceToGround(2);
397 FieldObservation specimenFieldObservation
= (FieldObservation
) specimen
398 .getDerivedFrom().getOriginals().iterator().next();
400 "Facade gathering event and specimen gathering event should be the same",
401 specimenFacade
.innerGatheringEvent(),
402 specimenFieldObservation
.getGatheringEvent());
403 } catch (DerivedUnitFacadeNotSupportedException e
) {
404 Assert
.fail("An error should not occur in NewInstance()");
409 public void testNoGatheringEventAndFieldObservation() {
410 Specimen specimen
= Specimen
.NewInstance();
411 DerivedUnitFacade specimenFacade
;
413 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
414 Assert
.assertNull("No field observation should exists",
415 specimenFacade
.innerFieldObservation());
416 } catch (DerivedUnitFacadeNotSupportedException e
) {
417 Assert
.fail("An error should not occur in NewInstance()");
422 public void testInititializeTextDataWithSupportTest() {
424 Specimen specimen
= Specimen
.NewInstance();
425 DerivedUnitFacade specimenFacade
;
427 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
428 specimenFacade
.setEcology("Ecology");
429 String plantDescription
= specimenFacade
.getPlantDescription();
431 "No plantDescription should exist yet and no NPE should be thrown until now",
433 } catch (DerivedUnitFacadeNotSupportedException e
) {
434 Assert
.fail("An error should not occur in NewInstance()");
439 public void testGetSetCountry() {
440 logger
.warn("Not yet implemented");
445 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
449 public void testAddGetRemoveCollectingArea() {
450 String tdwgLabel
= "GER";
451 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
452 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area",
454 specimenFacade
.addCollectingArea(newCollectingArea
);
455 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
456 .getCollectingAreas().size());
457 Assert
.assertSame("Areas should be same", newCollectingArea
,
458 specimenFacade
.innerFieldObservation().getGatheringEvent()
459 .getCollectingAreas().iterator().next());
460 specimenFacade
.addCollectingArea(tdwgArea
);
461 Assert
.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
462 .getCollectingAreas().size());
463 specimenFacade
.removeCollectingArea(newCollectingArea
);
464 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
465 .getCollectingAreas().size());
466 NamedArea remainingArea
= specimenFacade
.getCollectingAreas()
468 Assert
.assertEquals("Areas should be same", tdwgArea
, remainingArea
);
469 specimenFacade
.removeCollectingArea(tdwgArea
);
470 Assert
.assertEquals("No area should remain", 0, specimenFacade
471 .getCollectingAreas().size());
476 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
480 public void testAddCollectingAreas() {
481 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
482 Assert
.assertEquals("No area must exist", 0, specimenFacade
483 .getCollectingAreas().size());
484 specimenFacade
.addCollectingArea(firstArea
);
485 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
486 .getCollectingAreas().size());
488 String tdwgLabel
= "GER";
489 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
490 NamedArea secondArea
= NamedArea
491 .NewInstance("A nice area", "nice", "n");
493 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
494 areaCollection
.add(secondArea
);
495 areaCollection
.add(tdwgArea
);
496 specimenFacade
.addCollectingAreas(areaCollection
);
497 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
498 .getCollectingAreas().size());
504 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
508 public void testGetSetAbsoluteElevation() {
509 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
510 specimenFacade
.setAbsoluteElevation(400);
511 Assert
.assertEquals("Absolute elevation must be 400",Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
516 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
520 public void testGetSetAbsoluteElevationError() {
521 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
522 Assert
.assertEquals("Absolute elevation error must be same",absoluteElevationError
, specimenFacade
.getAbsoluteElevationError());
523 specimenFacade
.setAbsoluteElevationError(4);
524 Assert
.assertEquals("Absolute elevation error must be 4",Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationError());
525 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
530 public void testGetSetAbsoluteElevationRange() {
531 Integer expected
= absoluteElevation
- 2;
532 Assert
.assertEquals("", expected
, specimenFacade
.getAbsoluteElevationMinimum());
533 expected
= absoluteElevation
+ 2;
534 Assert
.assertEquals("", expected
,specimenFacade
.getAbsoluteElevationMaximum());
536 specimenFacade
.setAbsoluteElevationRange(30, 36);
537 Assert
.assertEquals("", Integer
.valueOf(36),specimenFacade
.getAbsoluteElevationMaximum());
538 Assert
.assertEquals("", Integer
.valueOf(30),specimenFacade
.getAbsoluteElevationMinimum());
539 Assert
.assertEquals("", Integer
.valueOf(33),specimenFacade
.getAbsoluteElevation());
540 Assert
.assertEquals("", Integer
.valueOf(3),specimenFacade
.getAbsoluteElevationError());
544 specimenFacade
.setAbsoluteElevationRange(30, 35);
545 Assert
.fail("Odd distance needs to throw IllegalArgumentException");
546 } catch (IllegalArgumentException e
) {
547 Assert
.assertTrue("Exception needs to be thrown", true);
550 specimenFacade
.setAbsoluteElevationRange(41, null);
551 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevationMaximum());
552 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevationMinimum());
553 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
554 Assert
.assertNotNull("", specimenFacade
.getAbsoluteElevationError());
555 Assert
.assertEquals("", Integer
.valueOf(0),specimenFacade
.getAbsoluteElevationError());
557 specimenFacade
.setAbsoluteElevationRange(null, null);
558 Assert
.assertNull("", specimenFacade
.getAbsoluteElevation());
559 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationError());
566 public void testGetSetCollector() {
567 Assert
.assertNotNull("Collector must not be null",
568 specimenFacade
.getCollector());
569 Assert
.assertEquals("Collector must be same", collector
,
570 specimenFacade
.getCollector());
571 specimenFacade
.setCollector(null);
572 Assert
.assertNull("Collector must be null",
573 specimenFacade
.getCollector());
578 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
582 public void testGetSetCollectingMethod() {
583 Assert
.assertEquals("Collecting method must be same", collectingMethod
,
584 specimenFacade
.getCollectingMethod());
585 specimenFacade
.setCollectingMethod("new method");
586 Assert
.assertEquals("Collecting method must be 'new method'",
587 "new method", specimenFacade
.getCollectingMethod());
592 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
596 public void testGetSetDistanceToGround() {
597 Assert
.assertEquals("Distance to ground must be same",
598 distanceToGround
, specimenFacade
.getDistanceToGround());
599 specimenFacade
.setDistanceToGround(5);
600 Assert
.assertEquals("Distance to ground must be 5", Integer
.valueOf(5),
601 specimenFacade
.getDistanceToGround());
606 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
610 public void testGetDistanceToWaterSurface() {
611 Assert
.assertEquals("Distance to surface must be same",
612 distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
613 specimenFacade
.setDistanceToWaterSurface(6);
614 Assert
.assertEquals("Distance to surface must be 6",
615 Integer
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
616 // empty facade tests
617 Assert
.assertNull("Empty facace must not have any gathering values",
618 emptyFacade
.getDistanceToWaterSurface());
619 emptyFacade
.setDistanceToWaterSurface(13);
620 Assert
.assertNotNull(
621 "Field observation must exist if distance to water exists",
622 emptyFacade
.getFieldObservation(false));
623 Assert
.assertNotNull(
624 "Gathering event must exist if distance to water exists",
625 emptyFacade
.getGatheringEvent(false));
626 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
627 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
630 "Gathering event of facade and of specimen must be the same",
631 specimenFieldObservation
.getGatheringEvent(),
632 emptyFacade
.getGatheringEvent(false));
637 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
640 public void testGetSetExactLocation() {
641 Assert
.assertNotNull("Exact location must not be null",
642 specimenFacade
.getExactLocation());
643 Assert
.assertEquals("Exact location must be same", exactLocation
,
644 specimenFacade
.getExactLocation());
645 specimenFacade
.setExactLocation(null);
646 Assert
.assertNull("Exact location must be null",
647 specimenFacade
.getExactLocation());
651 public void testSetExactLocationByParsing() {
654 specimenFacade
.setExactLocationByParsing("112\u00B034'20\"W",
655 "34\u00B030,34'N", null, null);
656 point1
= specimenFacade
.getExactLocation();
657 Assert
.assertNotNull("", point1
.getLatitude());
658 System
.out
.println(point1
.getLatitude().toString());
659 Assert
.assertTrue("",
660 point1
.getLatitude().toString().startsWith("34.505"));
661 System
.out
.println(point1
.getLongitude().toString());
662 Assert
.assertTrue("",
663 point1
.getLongitude().toString().startsWith("-112.5722"));
665 } catch (ParseException e
) {
666 Assert
.fail("No parsing error should occur");
672 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
676 public void testGetSetGatheringEventDescription() {
677 Assert
.assertEquals("Gathering event description must be same",
678 gatheringEventDescription
,
679 specimenFacade
.getGatheringEventDescription());
680 specimenFacade
.setGatheringEventDescription("new description");
682 "Gathering event description must be 'new description' now",
684 specimenFacade
.getGatheringEventDescription());
689 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
692 public void testGetTimeperiod() {
693 Assert
.assertNotNull("Gathering period must not be null",
694 specimenFacade
.getGatheringPeriod());
695 Assert
.assertEquals("Gathering period must be same", gatheringPeriod
,
696 specimenFacade
.getGatheringPeriod());
697 specimenFacade
.setGatheringPeriod(null);
698 Assert
.assertNull("Gathering period must be null",
699 specimenFacade
.getGatheringPeriod());
703 public void testHasFieldObject() throws SecurityException
,
704 NoSuchFieldException
, IllegalArgumentException
,
705 IllegalAccessException
{
706 // this test depends on the current implementation of SpecimenFacade. In
708 // field observation may not be initialized from the beginning. Than the
710 // assert should be set to assertNull
712 "field object should not be null (depends on specimen facade initialization !!)",
713 specimenFacade
.hasFieldObject());
715 Field fieldObservationField
= DerivedUnitFacade
.class
716 .getDeclaredField("fieldObservation");
717 fieldObservationField
.setAccessible(true);
718 fieldObservationField
.set(specimenFacade
, null);
719 Assert
.assertFalse("The field observation should be null now",
720 specimenFacade
.hasFieldObject());
722 specimenFacade
.setDistanceToGround(33);
724 "The field observation should have been created again",
725 specimenFacade
.hasFieldObject());
730 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
734 public void testAddGetRemoveFieldObjectDefinition() {
735 Assert
.assertEquals("There should be no definition yet", 0,
736 specimenFacade
.getFieldObjectDefinition().size());
737 specimenFacade
.addFieldObjectDefinition("Tres interesant",
739 Assert
.assertEquals("There should be exactly one definition", 1,
740 specimenFacade
.getFieldObjectDefinition().size());
742 "The French definition should be 'Tres interesant'",
743 "Tres interesant", specimenFacade
.getFieldObjectDefinition()
744 .get(Language
.FRENCH()).getText());
746 "The French definition should be 'Tres interesant'",
748 specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
749 specimenFacade
.addFieldObjectDefinition("Sehr interessant",
751 Assert
.assertEquals("There should be exactly 2 definition", 2,
752 specimenFacade
.getFieldObjectDefinition().size());
753 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
754 Assert
.assertEquals("There should remain exactly 1 definition", 1,
755 specimenFacade
.getFieldObjectDefinition().size());
757 "The remaining German definition should be 'Sehr interessant'",
759 specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
760 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
761 Assert
.assertEquals("There should remain no definition", 0,
762 specimenFacade
.getFieldObjectDefinition().size());
767 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
771 public void testAddGetHasRemoveFieldObjectMedia() {
772 Assert
.assertFalse("There should be no image gallery yet",
773 specimenFacade
.hasFieldObjectImageGallery());
774 Assert
.assertFalse("There should be no specimen image gallery either",
775 specimenFacade
.hasDerivedUnitImageGallery());
777 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
778 Assert
.assertFalse("There should still not be an image gallery now",
779 specimenFacade
.hasFieldObjectImageGallery());
780 Assert
.assertEquals("There should be no media yet in the gallery", 0,
783 Media media1
= Media
.NewInstance();
784 specimenFacade
.addFieldObjectMedia(media1
);
785 Assert
.assertEquals("There should be exactly one specimen media", 1,
786 specimenFacade
.getFieldObjectMedia().size());
787 Assert
.assertEquals("The only media should be media 1", media1
,
788 specimenFacade
.getFieldObjectMedia().get(0));
790 "There should still no specimen image gallery exist",
791 specimenFacade
.hasDerivedUnitImageGallery());
793 Media media2
= Media
.NewInstance();
794 specimenFacade
.addFieldObjectMedia(media2
);
795 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
796 specimenFacade
.getFieldObjectMedia().size());
797 Assert
.assertEquals("The first media should be media1", media1
,
798 specimenFacade
.getFieldObjectMedia().get(0));
799 Assert
.assertEquals("The second media should be media2", media2
,
800 specimenFacade
.getFieldObjectMedia().get(1));
802 specimenFacade
.removeFieldObjectMedia(media1
);
803 Assert
.assertEquals("There should be exactly one specimen media", 1,
804 specimenFacade
.getFieldObjectMedia().size());
805 Assert
.assertEquals("The only media should be media2", media2
,
806 specimenFacade
.getFieldObjectMedia().get(0));
808 specimenFacade
.removeFieldObjectMedia(media1
);
809 Assert
.assertEquals("There should still be exactly one specimen media",
810 1, specimenFacade
.getFieldObjectMedia().size());
812 specimenFacade
.removeFieldObjectMedia(media2
);
813 Assert
.assertEquals("There should remain no media in the gallery", 0,
820 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
824 public void testGetSetEcology() {
825 Assert
.assertNotNull(
826 "An empty ecology data should be created when calling getEcology()",
827 specimenFacade
.getEcologyAll());
829 "An empty ecology data should be created when calling getEcology()",
830 0, specimenFacade
.getEcologyAll().size());
831 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
832 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
833 specimenFacade
.getEcologyAll().size());
835 "Ecology data should be 'Tres jolie ici' for French",
836 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
838 "Ecology data should be null for the default language",
839 specimenFacade
.getEcology());
840 specimenFacade
.setEcology("Nice here");
841 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
842 specimenFacade
.getEcologyAll().size());
843 Assert
.assertEquals("Ecology data should be 'Tres jolie ici'",
844 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
846 "Ecology data should be 'Nice here' for the default language",
847 "Nice here", specimenFacade
.getEcology());
848 Assert
.assertEquals("Ecology data should be 'Nice here' for english",
849 "Nice here", specimenFacade
.getEcology());
851 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
852 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
853 specimenFacade
.getEcologyAll().size());
854 Assert
.assertEquals("Ecology data should be 'Vert et rouge'",
855 "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
857 "Ecology data should be 'Nice here' for the default language",
858 "Nice here", specimenFacade
.getEcology());
860 specimenFacade
.setEcology(null, Language
.FRENCH());
861 Assert
.assertEquals("Ecology data should exist for 1 languages", 1,
862 specimenFacade
.getEcologyAll().size());
864 "Ecology data should be 'Nice here' for the default language",
865 "Nice here", specimenFacade
.getEcology());
866 Assert
.assertNull("Ecology data should be 'null' for French",
867 specimenFacade
.getEcology(Language
.FRENCH()));
869 specimenFacade
.removeEcology(null);
870 Assert
.assertEquals("There should be no ecology left", 0,
871 specimenFacade
.getEcologyAll().size());
872 Assert
.assertNull("Ecology data should be 'null' for default language",
873 specimenFacade
.getEcology());
879 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
883 public void testGetSetPlantDescription() {
884 Assert
.assertNotNull(
885 "An empty plant description data should be created when calling getPlantDescriptionAll()",
886 specimenFacade
.getPlantDescriptionAll());
888 "An empty plant description data should be created when calling getPlantDescription()",
889 0, specimenFacade
.getPlantDescriptionAll().size());
890 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
892 "Plant description data should exist for 1 language", 1,
893 specimenFacade
.getPlantDescriptionAll().size());
895 "Plant description data should be 'bleu' for French", "bleu",
896 specimenFacade
.getPlantDescription(Language
.FRENCH()));
898 "Plant description data should be null for the default language",
899 specimenFacade
.getPlantDescription());
900 specimenFacade
.setPlantDescription("Nice here");
902 "Plant description data should exist for 2 languages", 2,
903 specimenFacade
.getPlantDescriptionAll().size());
904 Assert
.assertEquals("Plant description data should be 'bleu'", "bleu",
905 specimenFacade
.getPlantDescription(Language
.FRENCH()));
907 "Plant description data should be 'Nice here' for the default language",
908 "Nice here", specimenFacade
.getPlantDescription());
910 "Plant description data should be 'Nice here' for english",
911 "Nice here", specimenFacade
.getPlantDescription());
913 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
915 "Plant description data should exist for 2 languages", 2,
916 specimenFacade
.getPlantDescriptionAll().size());
917 Assert
.assertEquals("Plant description data should be 'Vert et rouge'",
919 specimenFacade
.getPlantDescription(Language
.FRENCH()));
921 "Plant description data should be 'Nice here' for the default language",
922 "Nice here", specimenFacade
.getPlantDescription());
924 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
926 "Plant description data should exist for 1 languages", 1,
927 specimenFacade
.getPlantDescriptionAll().size());
929 "Plant description data should be 'Nice here' for the default language",
930 "Nice here", specimenFacade
.getPlantDescription());
931 Assert
.assertNull("Plant description data should be 'null' for French",
932 specimenFacade
.getPlantDescription(Language
.FRENCH()));
934 // test interference with ecology
935 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
936 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
937 specimenFacade
.getEcologyAll().size());
939 "Ecology data should be 'Tres jolie ici' for French",
940 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
942 "Ecology data should be null for the default language",
943 specimenFacade
.getEcology());
947 "Plant description data should exist for 1 languages", 1,
948 specimenFacade
.getPlantDescriptionAll().size());
950 "Plant description data should be 'Nice here' for the default language",
951 "Nice here", specimenFacade
.getPlantDescription());
952 Assert
.assertNull("Plant description data should be 'null' for French",
953 specimenFacade
.getPlantDescription(Language
.FRENCH()));
955 specimenFacade
.removePlantDescription(null);
956 Assert
.assertEquals("There should be no plant description left", 0,
957 specimenFacade
.getPlantDescriptionAll().size());
959 "Plant description data should be 'null' for default language",
960 specimenFacade
.getPlantDescription());
966 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
969 public void testGetSetFieldNumber() {
970 Assert
.assertEquals("Field number must be same", fieldNumber
,
971 specimenFacade
.getFieldNumber());
972 specimenFacade
.setFieldNumber("564AB");
973 Assert
.assertEquals("New field number must be '564AB'", "564AB",
974 specimenFacade
.getFieldNumber());
975 // empty facade tests
976 Assert
.assertNull("Empty facace must not have any field value",
977 emptyFacade
.getFieldNumber());
978 emptyFacade
.setFieldNumber("1256A");
979 Assert
.assertNotNull(
980 "Field observation must exist if field number exists",
981 emptyFacade
.getFieldObservation(false));
982 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
983 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
986 "Field observation of facade and of specimen must be the same",
987 specimenFieldObservation
,
988 emptyFacade
.getFieldObservation(false));
989 Assert
.assertEquals("1256A", emptyFacade
.getFieldNumber());
994 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
997 public void testGetSetFieldNotes() {
998 Assert
.assertEquals("Field notes must be same", fieldNotes
,
999 specimenFacade
.getFieldNotes());
1000 specimenFacade
.setFieldNotes("A completely new info");
1001 Assert
.assertEquals("New field note must be 'A completely new info'",
1002 "A completely new info", specimenFacade
.getFieldNotes());
1007 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1011 public void testSetGatheringEvent() {
1012 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1013 newGatheringEvent
.setDistanceToGround(43);
1014 Assert
.assertFalse("The initial distance to ground should not be 43",
1015 specimenFacade
.getDistanceToGround() == 43);
1016 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1017 Assert
.assertTrue("The final distance to ground should be 43",
1018 specimenFacade
.getDistanceToGround() == 43);
1020 "The new gathering event should be 'newGatheringEvent'",
1021 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1026 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1030 public void testGetGatheringEvent() {
1031 Assert
.assertNotNull("Gathering event must not be null",
1032 specimenFacade
.innerGatheringEvent());
1033 Assert
.assertEquals(
1034 "Gathering event must be field observations gathering event",
1035 specimenFacade
.innerFieldObservation().getGatheringEvent(),
1036 specimenFacade
.innerGatheringEvent());
1041 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1045 public void testGetSetIndividualCount() {
1046 Assert
.assertEquals("Individual count must be same", individualCount
,
1047 specimenFacade
.getIndividualCount());
1048 specimenFacade
.setIndividualCount(4);
1049 Assert
.assertEquals("New individual count must be '4'",
1050 Integer
.valueOf(4), specimenFacade
.getIndividualCount());
1056 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1059 public void testGetSetLifeStage() {
1060 Assert
.assertNotNull("Life stage must not be null",
1061 specimenFacade
.getLifeStage());
1062 Assert
.assertEquals("Life stage must be same", lifeStage
,
1063 specimenFacade
.getLifeStage());
1064 specimenFacade
.setLifeStage(null);
1065 Assert
.assertNull("Life stage must be null",
1066 specimenFacade
.getLifeStage());
1071 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1074 public void testGetSetSex() {
1075 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
1076 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1077 specimenFacade
.setSex(null);
1078 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
1083 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1086 public void testGetSetLocality() {
1087 Assert
.assertEquals("Locality must be same", locality
,
1088 specimenFacade
.getLocality());
1089 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1090 Assert
.assertEquals("New locality must be 'A completely new place'",
1091 "A completely new place", specimenFacade
.getLocalityText());
1092 Assert
.assertEquals("New locality language must be French",
1093 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1094 specimenFacade
.setLocality("Another place");
1095 Assert
.assertEquals("New locality must be 'Another place'",
1096 "Another place", specimenFacade
.getLocalityText());
1097 Assert
.assertEquals("New locality language must be default",
1098 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1103 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1107 public void testAddGetRemoveSpecimenDefinition() {
1108 Assert
.assertEquals("There should be no definition yet", 0,
1109 specimenFacade
.getDerivedUnitDefinitions().size());
1110 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1112 Assert
.assertEquals("There should be exactly one definition", 1,
1113 specimenFacade
.getDerivedUnitDefinitions().size());
1114 Assert
.assertEquals(
1115 "The French definition should be 'Tres interesant'",
1116 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1117 .get(Language
.FRENCH()).getText());
1118 Assert
.assertEquals(
1119 "The French definition should be 'Tres interesant'",
1121 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1122 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1124 Assert
.assertEquals("There should be exactly 2 definition", 2,
1125 specimenFacade
.getDerivedUnitDefinitions().size());
1126 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1127 Assert
.assertEquals("There should remain exactly 1 definition", 1,
1128 specimenFacade
.getDerivedUnitDefinitions().size());
1129 Assert
.assertEquals(
1130 "The remaining German definition should be 'Sehr interessant'",
1132 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1133 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1134 Assert
.assertEquals("There should remain no definition", 0,
1135 specimenFacade
.getDerivedUnitDefinitions().size());
1140 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1144 public void testAddGetRemoveDetermination() {
1145 Assert
.assertEquals("There should be no determination yet", 0,
1146 specimenFacade
.getDeterminations().size());
1147 DeterminationEvent determinationEvent1
= DeterminationEvent
1149 specimenFacade
.addDetermination(determinationEvent1
);
1150 Assert
.assertEquals("There should be exactly one determination", 1,
1151 specimenFacade
.getDeterminations().size());
1152 Assert
.assertEquals("The only determination should be determination 1",
1153 determinationEvent1
, specimenFacade
.getDeterminations()
1154 .iterator().next());
1156 DeterminationEvent determinationEvent2
= DeterminationEvent
1158 specimenFacade
.addDetermination(determinationEvent2
);
1159 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1160 specimenFacade
.getDeterminations().size());
1161 specimenFacade
.removeDetermination(determinationEvent1
);
1163 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1164 specimenFacade
.getDeterminations().size());
1165 Assert
.assertEquals(
1166 "The remaining determinations should be determination 2",
1167 determinationEvent2
, specimenFacade
.getDeterminations()
1168 .iterator().next());
1170 specimenFacade
.removeDetermination(determinationEvent1
);
1171 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1172 specimenFacade
.getDeterminations().size());
1174 specimenFacade
.removeDetermination(determinationEvent2
);
1175 Assert
.assertEquals("There should remain no definition", 0,
1176 specimenFacade
.getDerivedUnitDefinitions().size());
1183 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1187 public void testPreferredOtherDeterminations() {
1188 Assert
.assertEquals("There should be no determination yet", 0,
1189 specimenFacade
.getDeterminations().size());
1190 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1191 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1193 Assert
.assertEquals("There should be exactly one determination", 1,
1194 specimenFacade
.getDeterminations().size());
1195 Assert
.assertEquals("The only determination should be determination 1",
1196 determinationEvent1
, specimenFacade
.getDeterminations()
1197 .iterator().next());
1198 Assert
.assertEquals("determination 1 should be the preferred determination",
1199 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1200 Assert
.assertEquals("There should be no 'non preferred' determination", 0,
1201 specimenFacade
.getOtherDeterminations().size());
1205 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1206 specimenFacade
.addDetermination(determinationEvent2
);
1207 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1208 specimenFacade
.getDeterminations().size());
1209 Assert
.assertEquals("determination 1 should be the preferred determination",
1210 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1211 Assert
.assertEquals("There should be one 'non preferred' determination", 1,
1212 specimenFacade
.getOtherDeterminations().size());
1213 Assert
.assertEquals("The only 'non preferred' determination should be determination 2",
1214 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1217 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1218 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1219 Assert
.assertEquals("There should be exactly 3 determinations", 3,
1220 specimenFacade
.getDeterminations().size());
1221 Assert
.assertEquals("determination 3 should be the preferred determination",
1222 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1223 Assert
.assertEquals("There should be 2 'non preferred' determination", 2,
1224 specimenFacade
.getOtherDeterminations().size());
1225 Assert
.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1226 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1227 Assert
.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1228 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1234 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1238 public void testAddGetHasRemoveSpecimenMedia() {
1239 Assert
.assertFalse("There should be no image gallery yet",
1240 specimenFacade
.hasDerivedUnitImageGallery());
1242 "There should be also no field object image gallery yet",
1243 specimenFacade
.hasFieldObjectImageGallery());
1245 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1247 "There should still not be an empty image gallery now",
1248 specimenFacade
.hasDerivedUnitImageGallery());
1249 Assert
.assertEquals("There should be no media yet in the gallery", 0,
1252 Media media1
= Media
.NewInstance();
1253 specimenFacade
.addDerivedUnitMedia(media1
);
1254 Assert
.assertEquals("There should be exactly one specimen media", 1,
1255 specimenFacade
.getDerivedUnitMedia().size());
1256 Assert
.assertEquals("The only media should be media 1", media1
,
1257 specimenFacade
.getDerivedUnitMedia().get(0));
1259 "There should be still no field object image gallery",
1260 specimenFacade
.hasFieldObjectImageGallery());
1262 Media media2
= Media
.NewInstance();
1263 specimenFacade
.addDerivedUnitMedia(media2
);
1264 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
1265 specimenFacade
.getDerivedUnitMedia().size());
1266 Assert
.assertEquals("The first media should be media1", media1
,
1267 specimenFacade
.getDerivedUnitMedia().get(0));
1268 Assert
.assertEquals("The second media should be media2", media2
,
1269 specimenFacade
.getDerivedUnitMedia().get(1));
1271 specimenFacade
.removeDerivedUnitMedia(media1
);
1272 Assert
.assertEquals("There should be exactly one specimen media", 1,
1273 specimenFacade
.getDerivedUnitMedia().size());
1274 Assert
.assertEquals("The only media should be media2", media2
,
1275 specimenFacade
.getDerivedUnitMedia().get(0));
1277 specimenFacade
.removeDerivedUnitMedia(media1
);
1278 Assert
.assertEquals("There should still be exactly one specimen media",
1279 1, specimenFacade
.getDerivedUnitMedia().size());
1281 specimenFacade
.removeDerivedUnitMedia(media2
);
1282 Assert
.assertEquals("There should remain no media in the gallery", 0,
1288 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1292 public void testGetSetAccessionNumber() {
1293 Assert
.assertEquals("Accession number must be same", accessionNumber
,
1294 specimenFacade
.getAccessionNumber());
1295 specimenFacade
.setAccessionNumber("A12345693");
1296 Assert
.assertEquals("New accession number must be 'A12345693'",
1297 "A12345693", specimenFacade
.getAccessionNumber());
1302 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1305 public void testGetCatalogNumber() {
1306 Assert
.assertEquals("Catalog number must be same", catalogNumber
,
1307 specimenFacade
.getCatalogNumber());
1308 specimenFacade
.setCatalogNumber("B12345693");
1309 Assert
.assertEquals("New catalog number must be 'B12345693'",
1310 "B12345693", specimenFacade
.getCatalogNumber());
1315 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1318 public void testGetPreservation() {
1320 Assert
.assertNotNull("Preservation method must not be null",
1321 specimenFacade
.getPreservationMethod());
1322 Assert
.assertEquals("Preservation method must be same",
1323 preservationMethod
, specimenFacade
.getPreservationMethod());
1324 specimenFacade
.setPreservationMethod(null);
1325 Assert
.assertNull("Preservation method must be null",
1326 specimenFacade
.getPreservationMethod());
1327 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1328 Assert
.fail("Method not supported should not be thrown for a specimen");
1330 specimenFacade
= DerivedUnitFacade
1331 .NewInstance(DerivedUnitType
.Observation
);
1333 specimenFacade
.setPreservationMethod(preservationMethod
);
1334 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
1336 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1339 specimenFacade
= DerivedUnitFacade
1340 .NewInstance(DerivedUnitType
.LivingBeing
);
1342 specimenFacade
.getPreservationMethod();
1343 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
1344 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1352 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1355 public void testGetStoredUnder() {
1356 Assert
.assertNotNull("Stored under name must not be null",
1357 specimenFacade
.getStoredUnder());
1358 Assert
.assertEquals("Stored under name must be same", taxonName
,
1359 specimenFacade
.getStoredUnder());
1360 specimenFacade
.setStoredUnder(null);
1361 Assert
.assertNull("Stored under name must be null",
1362 specimenFacade
.getStoredUnder());
1366 // * Test method for
1367 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1371 // public void testGetSetCollectorsNumber() {
1372 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1373 // specimenFacade.getCollectorsNumber());
1374 // specimenFacade.setCollectorsNumber("C12345693");
1375 // Assert.assertEquals("New collectors number must be 'C12345693'",
1376 // "C12345693", specimenFacade.getCollectorsNumber());
1381 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1384 public void testGetTitleCache() {
1385 Assert
.assertNotNull(
1386 "The title cache should never return null if not protected",
1387 specimenFacade
.getTitleCache());
1388 specimenFacade
.setTitleCache(null, false);
1389 Assert
.assertNotNull(
1390 "The title cache should never return null if not protected",
1391 specimenFacade
.getTitleCache());
1396 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1400 public void testSetTitleCache() {
1401 String testTitle
= "Absdwk aksjlf";
1402 specimenFacade
.setTitleCache(testTitle
, true);
1403 Assert
.assertEquals(
1404 "Protected title cache should returns the test title",
1405 testTitle
, specimenFacade
.getTitleCache());
1406 specimenFacade
.setTitleCache(testTitle
, false);
1408 "Unprotected title cache should not return the test title",
1409 testTitle
.equals(specimenFacade
.getTitleCache()));
1414 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1417 public void testGetSpecimen() {
1418 Assert
.assertEquals("Specimen must be same", specimen
,
1419 specimenFacade
.innerDerivedUnit());
1424 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1427 public void testGetSetCollection() {
1428 Assert
.assertNotNull("Collection must not be null",
1429 specimenFacade
.getCollection());
1430 Assert
.assertEquals("Collection must be same", collection
,
1431 specimenFacade
.getCollection());
1432 specimenFacade
.setCollection(null);
1433 Assert
.assertNull("Collection must be null",
1434 specimenFacade
.getCollection());
1438 public void testAddGetRemoveSource() {
1439 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
1440 .getSources().size());
1441 Reference reference
= ReferenceFactory
.newBook();
1442 IdentifiableSource source1
= specimenFacade
.addSource(reference
, "54",
1444 Assert
.assertEquals("One source should exist now", 1, specimenFacade
1445 .getSources().size());
1446 IdentifiableSource source2
= IdentifiableSource
.NewInstance("1",
1448 specimenFacade
.addSource(source2
);
1449 Assert
.assertEquals("One source should exist now", 2, specimenFacade
1450 .getSources().size());
1451 specimenFacade
.removeSource(source1
);
1452 Assert
.assertEquals("One source should exist now", 1, specimenFacade
1453 .getSources().size());
1454 Reference reference2
= ReferenceFactory
.newJournal();
1455 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(reference2
,
1457 specimenFacade
.removeSource(sourceNotUsed
);
1458 Assert
.assertEquals("One source should still exist", 1, specimenFacade
1459 .getSources().size());
1460 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next()
1462 specimenFacade
.removeSource(source2
);
1463 Assert
.assertEquals("No sources should exist anymore", 0,
1464 specimenFacade
.getSources().size());
1468 public void testAddGetRemoveDuplicate() {
1469 Assert
.assertEquals("No duplicates should be available yet", 0,
1470 specimenFacade
.getDuplicates().size());
1471 Specimen newSpecimen1
= Specimen
.NewInstance();
1472 specimenFacade
.addDuplicate(newSpecimen1
);
1473 Assert
.assertEquals("There should be 1 duplicate now", 1,
1474 specimenFacade
.getDuplicates().size());
1475 Specimen newSpecimen2
= Specimen
.NewInstance();
1476 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance();
1477 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1479 "The derivation event should be 'newDerivationEvent'",
1480 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1481 specimenFacade
.addDuplicate(newSpecimen2
);
1482 Assert
.assertEquals("There should be 2 duplicates now", 2,
1483 specimenFacade
.getDuplicates().size());
1484 Assert
.assertNotSame(
1485 "The derivation event should not be 'newDerivationEvent' anymore",
1486 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1488 "The derivation event should not be the facades derivation event",
1489 derivationEvent
, newSpecimen2
.getDerivedFrom());
1490 specimenFacade
.removeDuplicate(newSpecimen1
);
1491 Assert
.assertEquals("There should be 1 duplicate now", 1,
1492 specimenFacade
.getDuplicates().size());
1493 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now",
1494 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1495 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1496 Assert
.assertEquals(
1497 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1498 1, specimenFacade
.getDuplicates().size());
1500 Collection newCollection
= Collection
.NewInstance();
1501 String catalogNumber
= "1234890";
1502 String accessionNumber
= "345345";
1503 String collectorsNumber
= "lkjewe";
1504 TaxonNameBase storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
1505 PreservationMethod method
= PreservationMethod
.NewInstance();
1506 Specimen duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1507 catalogNumber
, accessionNumber
, storedUnder
,
1509 Assert
.assertEquals("There should be 2 duplicates now", 2,
1510 specimenFacade
.getDuplicates().size());
1511 specimenFacade
.removeDuplicate(newSpecimen2
);
1512 Assert
.assertEquals("There should be 1 duplicates now", 1,
1513 specimenFacade
.getDuplicates().size());
1514 Collection sameCollection
= specimenFacade
.getDuplicates().iterator()
1515 .next().getCollection();
1516 Assert
.assertSame("Collections should be same", newCollection
,
1520 // ************************** Existing Specimen with multiple derivation
1521 // events in line **************/
1524 public void testExistingSpecimen() {
1525 specimenFacade
= null;
1527 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1528 } catch (DerivedUnitFacadeNotSupportedException e
) {
1529 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
1532 "Gathering event should derive from the derivation line",
1533 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1534 Assert
.assertEquals(
1535 "Mediasize should be 0. Only Imagegallery media are supported",
1536 0, specimenFacade
.getFieldObjectMedia().size());
1540 public void testMultipleFieldObservationsNotSupported() {
1541 specimenFacade
= null;
1542 FieldObservation secondFieldObject
= FieldObservation
.NewInstance();
1543 firstDerivationEvent
.addOriginal(secondFieldObject
);
1545 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1546 Assert
.fail("Multiple field observations for one specimen should no be supported by the facade");
1547 } catch (DerivedUnitFacadeNotSupportedException e
) {
1550 Assert
.assertNull("Specimen facade should not be initialized",
1555 public void testOnlyImageGallerySupported() {
1556 specimenFacade
= null;
1557 firstFieldObject
.addMedia(media1
);
1559 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1560 Assert
.fail("Only image galleries are supported by the facade but not direct media");
1561 } catch (DerivedUnitFacadeNotSupportedException e
) {
1564 Assert
.assertNull("Specimen facade should not be initialized",
1569 public void testEventPropagation() {
1570 specimenFacade
.setDistanceToGround(24);
1574 // @Ignore // set to ignore because I did not want to check knowingly
1575 // failing tests. Remove @Ignore when this is fixed
1577 public void testSetBarcode() {
1578 String barcode
= "barcode";
1579 specimenFacade
.setBarcode(barcode
);
1581 Assert
.assertEquals(barcode
, specimenFacade
.getBarcode());
1585 public void testIsEvenDistance() {
1586 Integer minimum
= 20;
1587 Integer maximum
= 1234;
1589 // this should not throw exceptions
1590 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1594 private IUserService userService
;
1598 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1599 * This test doesn't handle the above issue yet as it doesn't fire events as
1600 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1601 * In the meanwhile the property change framework for the facade has been changed
1602 * so the original problem may have disappeared.
1606 public void testNoRecursiveChangeEvents(){
1607 String username
= "username";
1608 String password
= "password";
1609 User user
= User
.NewInstance(username
, password
);
1610 userService
.save(user
);
1611 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1612 SecurityContextHolder
.getContext().setAuthentication(token
);
1614 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
1615 facade
.setLocality("testLocality");
1616 facade
.getTitleCache();
1617 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1618 this.service
.save(facade
.innerDerivedUnit());