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
.model
.agent
.AgentBase
;
35 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
36 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
38 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
39 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
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
.DerivationEventType
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
64 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
65 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
66 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 absoluteElevationError
= 2;
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 Stage lifeStage
= Stage
.NewInstance("A wonderful stage", "stage", "st");
108 Sex sex
= Sex
.NewInstance("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
.setAbsoluteElevationError(absoluteElevationError
);
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
= TdwgArea
.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
482 .getCollectingAreas().size());
483 specimenFacade
.addCollectingArea(firstArea
);
484 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
485 .getCollectingAreas().size());
487 String tdwgLabel
= "GER";
488 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
489 NamedArea secondArea
= NamedArea
490 .NewInstance("A nice area", "nice", "n");
492 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
493 areaCollection
.add(secondArea
);
494 areaCollection
.add(tdwgArea
);
495 specimenFacade
.addCollectingAreas(areaCollection
);
496 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
497 .getCollectingAreas().size());
503 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
507 @Ignore // #######DerivationEvent --------------------------- 2
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 @Ignore // #######DerivationEvent ---------------------------------------- 1
1012 public void testSetGatheringEvent() {
1013 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1014 newGatheringEvent
.setDistanceToGround(43);
1015 Assert
.assertFalse("The initial distance to ground should not be 43",
1016 specimenFacade
.getDistanceToGround() == 43);
1017 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1018 Assert
.assertTrue("The final distance to ground should be 43",
1019 specimenFacade
.getDistanceToGround() == 43);
1021 "The new gathering event should be 'newGatheringEvent'",
1022 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1027 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1031 public void testGetGatheringEvent() {
1032 Assert
.assertNotNull("Gathering event must not be null",
1033 specimenFacade
.innerGatheringEvent());
1034 Assert
.assertEquals(
1035 "Gathering event must be field observations gathering event",
1036 specimenFacade
.innerFieldObservation().getGatheringEvent(),
1037 specimenFacade
.innerGatheringEvent());
1042 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1046 public void testGetSetIndividualCount() {
1047 Assert
.assertEquals("Individual count must be same", individualCount
,
1048 specimenFacade
.getIndividualCount());
1049 specimenFacade
.setIndividualCount(4);
1050 Assert
.assertEquals("New individual count must be '4'",
1051 Integer
.valueOf(4), specimenFacade
.getIndividualCount());
1057 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1060 public void testGetSetLifeStage() {
1061 Assert
.assertNotNull("Life stage must not be null",
1062 specimenFacade
.getLifeStage());
1063 Assert
.assertEquals("Life stage must be same", lifeStage
,
1064 specimenFacade
.getLifeStage());
1065 specimenFacade
.setLifeStage(null);
1066 Assert
.assertNull("Life stage must be null",
1067 specimenFacade
.getLifeStage());
1072 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1075 public void testGetSetSex() {
1076 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
1077 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1078 specimenFacade
.setSex(null);
1079 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
1084 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1087 public void testGetSetLocality() {
1088 Assert
.assertEquals("Locality must be same", locality
,
1089 specimenFacade
.getLocality());
1090 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1091 Assert
.assertEquals("New locality must be 'A completely new place'",
1092 "A completely new place", specimenFacade
.getLocalityText());
1093 Assert
.assertEquals("New locality language must be French",
1094 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1095 specimenFacade
.setLocality("Another place");
1096 Assert
.assertEquals("New locality must be 'Another place'",
1097 "Another place", specimenFacade
.getLocalityText());
1098 Assert
.assertEquals("New locality language must be default",
1099 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1104 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1108 public void testAddGetRemoveSpecimenDefinition() {
1109 Assert
.assertEquals("There should be no definition yet", 0,
1110 specimenFacade
.getDerivedUnitDefinitions().size());
1111 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1113 Assert
.assertEquals("There should be exactly one definition", 1,
1114 specimenFacade
.getDerivedUnitDefinitions().size());
1115 Assert
.assertEquals(
1116 "The French definition should be 'Tres interesant'",
1117 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1118 .get(Language
.FRENCH()).getText());
1119 Assert
.assertEquals(
1120 "The French definition should be 'Tres interesant'",
1122 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1123 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1125 Assert
.assertEquals("There should be exactly 2 definition", 2,
1126 specimenFacade
.getDerivedUnitDefinitions().size());
1127 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1128 Assert
.assertEquals("There should remain exactly 1 definition", 1,
1129 specimenFacade
.getDerivedUnitDefinitions().size());
1130 Assert
.assertEquals(
1131 "The remaining German definition should be 'Sehr interessant'",
1133 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1134 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1135 Assert
.assertEquals("There should remain no definition", 0,
1136 specimenFacade
.getDerivedUnitDefinitions().size());
1141 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1145 public void testAddGetRemoveDetermination() {
1146 Assert
.assertEquals("There should be no determination yet", 0,
1147 specimenFacade
.getDeterminations().size());
1148 DeterminationEvent determinationEvent1
= DeterminationEvent
1150 specimenFacade
.addDetermination(determinationEvent1
);
1151 Assert
.assertEquals("There should be exactly one determination", 1,
1152 specimenFacade
.getDeterminations().size());
1153 Assert
.assertEquals("The only determination should be determination 1",
1154 determinationEvent1
, specimenFacade
.getDeterminations()
1155 .iterator().next());
1157 DeterminationEvent determinationEvent2
= DeterminationEvent
1159 specimenFacade
.addDetermination(determinationEvent2
);
1160 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1161 specimenFacade
.getDeterminations().size());
1162 specimenFacade
.removeDetermination(determinationEvent1
);
1164 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1165 specimenFacade
.getDeterminations().size());
1166 Assert
.assertEquals(
1167 "The remaining determinations should be determination 2",
1168 determinationEvent2
, specimenFacade
.getDeterminations()
1169 .iterator().next());
1171 specimenFacade
.removeDetermination(determinationEvent1
);
1172 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1173 specimenFacade
.getDeterminations().size());
1175 specimenFacade
.removeDetermination(determinationEvent2
);
1176 Assert
.assertEquals("There should remain no definition", 0,
1177 specimenFacade
.getDerivedUnitDefinitions().size());
1184 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1188 public void testPreferredOtherDeterminations() {
1189 Assert
.assertEquals("There should be no determination yet", 0,
1190 specimenFacade
.getDeterminations().size());
1191 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1192 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1194 Assert
.assertEquals("There should be exactly one determination", 1,
1195 specimenFacade
.getDeterminations().size());
1196 Assert
.assertEquals("The only determination should be determination 1",
1197 determinationEvent1
, specimenFacade
.getDeterminations()
1198 .iterator().next());
1199 Assert
.assertEquals("determination 1 should be the preferred determination",
1200 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1201 Assert
.assertEquals("There should be no 'non preferred' determination", 0,
1202 specimenFacade
.getOtherDeterminations().size());
1206 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1207 specimenFacade
.addDetermination(determinationEvent2
);
1208 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1209 specimenFacade
.getDeterminations().size());
1210 Assert
.assertEquals("determination 1 should be the preferred determination",
1211 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1212 Assert
.assertEquals("There should be one 'non preferred' determination", 1,
1213 specimenFacade
.getOtherDeterminations().size());
1214 Assert
.assertEquals("The only 'non preferred' determination should be determination 2",
1215 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1218 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1219 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1220 Assert
.assertEquals("There should be exactly 3 determinations", 3,
1221 specimenFacade
.getDeterminations().size());
1222 Assert
.assertEquals("determination 3 should be the preferred determination",
1223 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1224 Assert
.assertEquals("There should be 2 'non preferred' determination", 2,
1225 specimenFacade
.getOtherDeterminations().size());
1226 Assert
.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1227 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1228 Assert
.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1229 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1235 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1239 public void testAddGetHasRemoveSpecimenMedia() {
1240 Assert
.assertFalse("There should be no image gallery yet",
1241 specimenFacade
.hasDerivedUnitImageGallery());
1243 "There should be also no field object image gallery yet",
1244 specimenFacade
.hasFieldObjectImageGallery());
1246 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1248 "There should still not be an empty image gallery now",
1249 specimenFacade
.hasDerivedUnitImageGallery());
1250 Assert
.assertEquals("There should be no media yet in the gallery", 0,
1253 Media media1
= Media
.NewInstance();
1254 specimenFacade
.addDerivedUnitMedia(media1
);
1255 Assert
.assertEquals("There should be exactly one specimen media", 1,
1256 specimenFacade
.getDerivedUnitMedia().size());
1257 Assert
.assertEquals("The only media should be media 1", media1
,
1258 specimenFacade
.getDerivedUnitMedia().get(0));
1260 "There should be still no field object image gallery",
1261 specimenFacade
.hasFieldObjectImageGallery());
1263 Media media2
= Media
.NewInstance();
1264 specimenFacade
.addDerivedUnitMedia(media2
);
1265 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
1266 specimenFacade
.getDerivedUnitMedia().size());
1267 Assert
.assertEquals("The first media should be media1", media1
,
1268 specimenFacade
.getDerivedUnitMedia().get(0));
1269 Assert
.assertEquals("The second media should be media2", media2
,
1270 specimenFacade
.getDerivedUnitMedia().get(1));
1272 specimenFacade
.removeDerivedUnitMedia(media1
);
1273 Assert
.assertEquals("There should be exactly one specimen media", 1,
1274 specimenFacade
.getDerivedUnitMedia().size());
1275 Assert
.assertEquals("The only media should be media2", media2
,
1276 specimenFacade
.getDerivedUnitMedia().get(0));
1278 specimenFacade
.removeDerivedUnitMedia(media1
);
1279 Assert
.assertEquals("There should still be exactly one specimen media",
1280 1, specimenFacade
.getDerivedUnitMedia().size());
1282 specimenFacade
.removeDerivedUnitMedia(media2
);
1283 Assert
.assertEquals("There should remain no media in the gallery", 0,
1289 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1293 public void testGetSetAccessionNumber() {
1294 Assert
.assertEquals("Accession number must be same", accessionNumber
,
1295 specimenFacade
.getAccessionNumber());
1296 specimenFacade
.setAccessionNumber("A12345693");
1297 Assert
.assertEquals("New accession number must be 'A12345693'",
1298 "A12345693", specimenFacade
.getAccessionNumber());
1303 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1306 public void testGetCatalogNumber() {
1307 Assert
.assertEquals("Catalog number must be same", catalogNumber
,
1308 specimenFacade
.getCatalogNumber());
1309 specimenFacade
.setCatalogNumber("B12345693");
1310 Assert
.assertEquals("New catalog number must be 'B12345693'",
1311 "B12345693", specimenFacade
.getCatalogNumber());
1316 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1319 public void testGetPreservation() {
1321 Assert
.assertNotNull("Preservation method must not be null",
1322 specimenFacade
.getPreservationMethod());
1323 Assert
.assertEquals("Preservation method must be same",
1324 preservationMethod
, specimenFacade
.getPreservationMethod());
1325 specimenFacade
.setPreservationMethod(null);
1326 Assert
.assertNull("Preservation method must be null",
1327 specimenFacade
.getPreservationMethod());
1328 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1329 Assert
.fail("Method not supported should not be thrown for a specimen");
1331 specimenFacade
= DerivedUnitFacade
1332 .NewInstance(DerivedUnitType
.Observation
);
1334 specimenFacade
.setPreservationMethod(preservationMethod
);
1335 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
1337 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1340 specimenFacade
= DerivedUnitFacade
1341 .NewInstance(DerivedUnitType
.LivingBeing
);
1343 specimenFacade
.getPreservationMethod();
1344 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
1345 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1353 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1356 public void testGetStoredUnder() {
1357 Assert
.assertNotNull("Stored under name must not be null",
1358 specimenFacade
.getStoredUnder());
1359 Assert
.assertEquals("Stored under name must be same", taxonName
,
1360 specimenFacade
.getStoredUnder());
1361 specimenFacade
.setStoredUnder(null);
1362 Assert
.assertNull("Stored under name must be null",
1363 specimenFacade
.getStoredUnder());
1367 // * Test method for
1368 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1372 // public void testGetSetCollectorsNumber() {
1373 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1374 // specimenFacade.getCollectorsNumber());
1375 // specimenFacade.setCollectorsNumber("C12345693");
1376 // Assert.assertEquals("New collectors number must be 'C12345693'",
1377 // "C12345693", specimenFacade.getCollectorsNumber());
1382 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1385 public void testGetTitleCache() {
1386 Assert
.assertNotNull(
1387 "The title cache should never return null if not protected",
1388 specimenFacade
.getTitleCache());
1389 specimenFacade
.setTitleCache(null, false);
1390 Assert
.assertNotNull(
1391 "The title cache should never return null if not protected",
1392 specimenFacade
.getTitleCache());
1397 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1401 public void testSetTitleCache() {
1402 String testTitle
= "Absdwk aksjlf";
1403 specimenFacade
.setTitleCache(testTitle
, true);
1404 Assert
.assertEquals(
1405 "Protected title cache should returns the test title",
1406 testTitle
, specimenFacade
.getTitleCache());
1407 specimenFacade
.setTitleCache(testTitle
, false);
1409 "Unprotected title cache should not return the test title",
1410 testTitle
.equals(specimenFacade
.getTitleCache()));
1415 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1418 public void testGetSpecimen() {
1419 Assert
.assertEquals("Specimen must be same", specimen
,
1420 specimenFacade
.innerDerivedUnit());
1425 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1428 public void testGetSetCollection() {
1429 Assert
.assertNotNull("Collection must not be null",
1430 specimenFacade
.getCollection());
1431 Assert
.assertEquals("Collection must be same", collection
,
1432 specimenFacade
.getCollection());
1433 specimenFacade
.setCollection(null);
1434 Assert
.assertNull("Collection must be null",
1435 specimenFacade
.getCollection());
1439 public void testAddGetRemoveSource() {
1440 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
.getSources().size());
1442 Reference
<?
> reference
= ReferenceFactory
.newBook();
1443 IdentifiableSource source1
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference
, "54", "myName");
1444 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1445 IdentifiableSource source2
= IdentifiableSource
.NewDataImportInstance("1", "myTable");
1446 specimenFacade
.addSource(source2
);
1447 Assert
.assertEquals("One source should exist now", 2, specimenFacade
.getSources().size());
1448 specimenFacade
.removeSource(source1
);
1449 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1450 Reference reference2
= ReferenceFactory
.newJournal();
1451 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference2
,null, null);
1452 specimenFacade
.removeSource(sourceNotUsed
);
1453 Assert
.assertEquals("One source should still exist", 1, specimenFacade
.getSources().size());
1454 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next().getIdInSource());
1455 specimenFacade
.removeSource(source2
);
1456 Assert
.assertEquals("No sources should exist anymore", 0,specimenFacade
.getSources().size());
1460 public void testAddGetRemoveDuplicate() {
1461 Assert
.assertEquals("No duplicates should be available yet", 0,specimenFacade
.getDuplicates().size());
1462 Specimen newSpecimen1
= Specimen
.NewInstance();
1463 specimenFacade
.addDuplicate(newSpecimen1
);
1464 Assert
.assertEquals("There should be 1 duplicate now", 1,specimenFacade
.getDuplicates().size());
1465 Specimen newSpecimen2
= Specimen
.NewInstance();
1466 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
1467 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1469 "The derivation event should be 'newDerivationEvent'",
1470 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1471 specimenFacade
.addDuplicate(newSpecimen2
);
1472 Assert
.assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
1473 Assert
.assertNotSame(
1474 "The derivation event should not be 'newDerivationEvent' anymore",
1475 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1477 "The derivation event should not be the facades derivation event",
1478 derivationEvent
, newSpecimen2
.getDerivedFrom());
1479 specimenFacade
.removeDuplicate(newSpecimen1
);
1480 Assert
.assertEquals("There should be 1 duplicate now", 1,
1481 specimenFacade
.getDuplicates().size());
1482 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now",
1483 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1484 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1485 Assert
.assertEquals(
1486 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1487 1, specimenFacade
.getDuplicates().size());
1489 Collection newCollection
= Collection
.NewInstance();
1490 String catalogNumber
= "1234890";
1491 String accessionNumber
= "345345";
1492 String collectorsNumber
= "lkjewe";
1493 TaxonNameBase
<?
,?
> storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
1494 PreservationMethod method
= PreservationMethod
.NewInstance();
1495 Specimen duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1496 catalogNumber
, accessionNumber
, storedUnder
,
1498 Assert
.assertEquals("There should be 2 duplicates now", 2,
1499 specimenFacade
.getDuplicates().size());
1500 specimenFacade
.removeDuplicate(newSpecimen2
);
1501 Assert
.assertEquals("There should be 1 duplicates now", 1,
1502 specimenFacade
.getDuplicates().size());
1503 Collection sameCollection
= specimenFacade
.getDuplicates().iterator()
1504 .next().getCollection();
1505 Assert
.assertSame("Collections should be same", newCollection
,
1509 // ************************** Existing Specimen with multiple derivation
1510 // events in line **************/
1513 public void testExistingSpecimen() {
1514 specimenFacade
= null;
1516 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1517 } catch (DerivedUnitFacadeNotSupportedException e
) {
1518 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
1521 "Gathering event should derive from the derivation line",
1522 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1523 Assert
.assertEquals(
1524 "Mediasize should be 0. Only Imagegallery media are supported",
1525 0, specimenFacade
.getFieldObjectMedia().size());
1529 public void testMultipleFieldObservationsNotSupported() {
1530 specimenFacade
= null;
1531 FieldObservation secondFieldObject
= FieldObservation
.NewInstance();
1532 firstDerivationEvent
.addOriginal(secondFieldObject
);
1534 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1535 Assert
.fail("Multiple field observations for one specimen should no be supported by the facade");
1536 } catch (DerivedUnitFacadeNotSupportedException e
) {
1539 Assert
.assertNull("Specimen facade should not be initialized",
1543 @Test // #######DerivationEvent
1544 public void testOnlyImageGallerySupported() {
1545 specimenFacade
= null;
1546 firstFieldObject
.addMedia(media1
);
1548 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1549 Assert
.fail("Only image galleries are supported by the facade but not direct media");
1550 } catch (DerivedUnitFacadeNotSupportedException e
) {
1553 Assert
.assertNull("Specimen facade should not be initialized",
1557 @Test // #######DerivationEvent
1558 public void testEventPropagation() {
1559 specimenFacade
.setDistanceToGround(24);
1563 // @Ignore // set to ignore because I did not want to check knowingly
1564 // failing tests. Remove @Ignore when this is fixed
1566 public void testSetBarcode() {
1567 String barcode
= "barcode";
1568 specimenFacade
.setBarcode(barcode
);
1570 Assert
.assertEquals(barcode
, specimenFacade
.getBarcode());
1574 public void testIsEvenDistance() {
1575 Integer minimum
= 20;
1576 Integer maximum
= 1234;
1578 // this should not throw exceptions
1579 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1584 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1585 * This test doesn't handle the above issue yet as it doesn't fire events as
1586 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1587 * In the meanwhile the property change framework for the facade has been changed
1588 * so the original problem may have disappeared.
1592 public void testNoRecursiveChangeEvents(){
1593 String username
= "username";
1594 String password
= "password";
1595 User user
= User
.NewInstance(username
, password
);
1596 userService
.save(user
);
1597 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1598 SecurityContextHolder
.getContext().setAuthentication(token
);
1600 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
1601 facade
.setLocality("testLocality");
1602 facade
.getTitleCache();
1603 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1604 this.service
.save(facade
.innerDerivedUnit());
1605 commitAndStartNewTransaction(null);