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
127 // *****************************************/
130 * @throws java.lang.Exception
133 public static void setUpBeforeClass() throws Exception
{
134 // new DefaultTermInitializer().initialize();
138 * @throws java.lang.Exception
141 public void setUp() throws Exception
{
142 specimen
= Specimen
.NewInstance();
144 derivationEvent
= DerivationEvent
.NewInstance();
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 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance();
183 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance();
184 firstDerivationEvent
= DerivationEvent
.NewInstance();
186 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
188 lastDerivationEvent
.addOriginal(middleSpecimen
);
189 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
190 firstDerivationEvent
.addOriginal(firstFieldObject
);
191 existingGatheringEvent
= GatheringEvent
.NewInstance();
192 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
195 emptyFacade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
199 // ****************************** TESTS
200 // *****************************************/
203 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
205 public void testSetFieldObjectImageGallery() {
206 UUID imageFeatureUuid
= Feature
.IMAGE().getUuid();
207 Feature imageFeature
= (Feature
) termService
.find(imageFeatureUuid
);
209 DerivedUnitFacade facade
= DerivedUnitFacade
210 .NewInstance(DerivedUnitType
.Specimen
);
211 facade
.setFieldNumber("12345");
212 Media media
= Media
.NewInstance(URI
.create("www.abc.de"), 200, null,
216 SpecimenDescription imageGallery
= SpecimenDescription
218 imageGallery
.addDescribedSpecimenOrObservation(facade
219 .innerFieldObservation());
220 imageGallery
.setImageGallery(true);
221 TextData textData
= TextData
.NewInstance();
222 textData
.setFeature(imageFeature
);
223 imageGallery
.addElement(textData
);
224 textData
.addMedia(media
);
225 facade
.setFieldObjectImageGallery(imageGallery
);
227 } catch (DerivedUnitFacadeNotSupportedException e1
) {
228 e1
.printStackTrace();
229 Assert
.fail(e1
.getLocalizedMessage());
231 this.service
.save(facade
.innerDerivedUnit());
233 // setComplete(); endTransaction();
234 // try {if (true){printDataSet(System.out, new
235 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
236 // ,"DERIVATIONEVENT",
237 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
238 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
239 // } catch(Exception e) { logger.warn(e);}
245 // TODO generally works but has id problems when running together with above
246 // test ()setFieldObjectImageGallery. Therefore set to ignore.
247 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
249 public void testSetDerivedUnitImageGallery() {
250 // UUID specimenUUID =
251 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
252 // Specimen specimen = (Specimen)service.find(specimenUUID);
253 DerivedUnitFacade facade
= DerivedUnitFacade
254 .NewInstance(DerivedUnitType
.Specimen
);
255 Media media
= Media
.NewInstance(URI
.create("www.derivedUnitImage.de"),
259 SpecimenDescription imageGallery
= SpecimenDescription
261 imageGallery
.addDescribedSpecimenOrObservation(facade
262 .innerDerivedUnit());
263 imageGallery
.setImageGallery(true);
264 TextData textData
= TextData
.NewInstance();
265 imageGallery
.addElement(textData
);
266 textData
.addMedia(media
);
267 facade
.setDerivedUnitImageGallery(imageGallery
);
269 } catch (DerivedUnitFacadeNotSupportedException e1
) {
270 e1
.printStackTrace();
271 Assert
.fail(e1
.getLocalizedMessage());
273 this.service
.save(facade
.innerDerivedUnit());
275 // setComplete(); endTransaction();
276 // try {if (true){printDataSet(System.out, new
277 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
278 // ,"DERIVATIONEVENT",
279 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA","DESCRIPTIONBASE_SPECIMENOROBSERVATIONBASE",
280 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
281 // } catch(Exception e) { logger.warn(e);}
287 public void testGetFieldObjectImageGalleryBooleanPersisted() {
288 UUID specimenUUID
= UUID
289 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
290 Specimen specimen
= (Specimen
) service
.find(specimenUUID
);
291 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
293 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
294 SpecimenDescription imageGallery
= facade
295 .getFieldObjectImageGallery(true);
296 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
297 Assert
.assertEquals("UUID should be equal to the persisted uuid",
298 UUID
.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
299 imageGallery
.getUuid());
300 Assert
.assertEquals("The image gallery should be flagged as such",
301 true, imageGallery
.isImageGallery());
303 "There should be one TextData in image gallery", 1,
304 imageGallery
.getElements().size());
305 List
<Media
> media
= imageGallery
.getElements().iterator().next()
307 Assert
.assertEquals("There should be 1 media", 1, media
.size());
308 } catch (DerivedUnitFacadeNotSupportedException e
) {
316 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
317 UUID specimenUUID
= UUID
318 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
319 Specimen specimen
= (Specimen
) service
.find(specimenUUID
);
320 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
322 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
323 SpecimenDescription imageGallery
= facade
324 .getDerivedUnitImageGallery(true);
325 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
326 Assert
.assertEquals("UUID should be equal to the persisted uuid",
327 UUID
.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
328 imageGallery
.getUuid());
329 Assert
.assertEquals("The image gallery should be flagged as such",
330 true, imageGallery
.isImageGallery());
332 "There should be one TextData in image gallery", 1,
333 imageGallery
.getElements().size());
334 List
<Media
> media
= imageGallery
.getElements().iterator().next()
336 Assert
.assertEquals("There should be 1 media", 1, media
.size());
337 } catch (DerivedUnitFacadeNotSupportedException e
) {
344 public void testGetDerivedUnitImageGalleryBoolean() {
345 Specimen specimen
= Specimen
.NewInstance();
347 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
348 SpecimenDescription imageGallery
= facade
349 .getDerivedUnitImageGallery(true);
350 Assert
.assertNotNull("Image Gallery should have been created",
352 Assert
.assertEquals("The image gallery should be flagged as such",
353 true, imageGallery
.isImageGallery());
354 } catch (DerivedUnitFacadeNotSupportedException e
) {
363 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
366 public void testNewInstance() {
367 Assert
.assertNotNull("The specimen should have been created",
368 specimenFacade
.innerDerivedUnit());
370 // Assert.assertNotNull("The derivation event should have been created",
371 // specimenFacade.getSpecimen().getDerivedFrom());
372 // Assert.assertNotNull("The field observation should have been created",
373 // specimenFacade.getFieldObservation());
374 // Assert.assertNotNull("The gathering event should have been created",
375 // specimenFacade.getGatheringEvent());
380 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
384 public void testNewInstanceSpecimen() {
385 Assert
.assertSame("Specimen should be same", specimen
,
386 specimenFacade
.innerDerivedUnit());
387 Assert
.assertSame("Derivation event should be same", derivationEvent
,
388 specimenFacade
.innerDerivedUnit().getDerivedFrom());
389 Assert
.assertSame("Field observation should be same", fieldObservation
,
390 specimenFacade
.innerFieldObservation());
391 Assert
.assertSame("Gathering event should be same", gatheringEvent
,
392 specimenFacade
.innerGatheringEvent());
397 public void testGatheringEventIsConnectedToDerivedUnit() {
398 Specimen specimen
= Specimen
.NewInstance();
399 DerivedUnitFacade specimenFacade
;
401 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
402 specimenFacade
.setDistanceToGround(2);
403 FieldObservation specimenFieldObservation
= (FieldObservation
) specimen
404 .getDerivedFrom().getOriginals().iterator().next();
406 "Facade gathering event and specimen gathering event should be the same",
407 specimenFacade
.innerGatheringEvent(),
408 specimenFieldObservation
.getGatheringEvent());
409 } catch (DerivedUnitFacadeNotSupportedException e
) {
410 Assert
.fail("An error should not occur in NewInstance()");
415 public void testNoGatheringEventAndFieldObservation() {
416 Specimen specimen
= Specimen
.NewInstance();
417 DerivedUnitFacade specimenFacade
;
419 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
420 Assert
.assertNull("No field observation should exists",
421 specimenFacade
.innerFieldObservation());
422 } catch (DerivedUnitFacadeNotSupportedException e
) {
423 Assert
.fail("An error should not occur in NewInstance()");
428 public void testInititializeTextDataWithSupportTest() {
430 Specimen specimen
= Specimen
.NewInstance();
431 DerivedUnitFacade specimenFacade
;
433 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
434 specimenFacade
.setEcology("Ecology");
435 String plantDescription
= specimenFacade
.getPlantDescription();
437 "No plantDescription should exist yet and no NPE should be thrown until now",
439 } catch (DerivedUnitFacadeNotSupportedException e
) {
440 Assert
.fail("An error should not occur in NewInstance()");
445 public void testGetSetCountry() {
446 logger
.warn("Not yet implemented");
451 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
455 public void testAddGetRemoveCollectingArea() {
456 String tdwgLabel
= "GER";
457 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
458 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area",
460 specimenFacade
.addCollectingArea(newCollectingArea
);
461 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
462 .getCollectingAreas().size());
463 Assert
.assertSame("Areas should be same", newCollectingArea
,
464 specimenFacade
.innerFieldObservation().getGatheringEvent()
465 .getCollectingAreas().iterator().next());
466 specimenFacade
.addCollectingArea(tdwgArea
);
467 Assert
.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
468 .getCollectingAreas().size());
469 specimenFacade
.removeCollectingArea(newCollectingArea
);
470 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
471 .getCollectingAreas().size());
472 NamedArea remainingArea
= specimenFacade
.getCollectingAreas()
474 Assert
.assertEquals("Areas should be same", tdwgArea
, remainingArea
);
475 specimenFacade
.removeCollectingArea(tdwgArea
);
476 Assert
.assertEquals("No area should remain", 0, specimenFacade
477 .getCollectingAreas().size());
482 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
486 public void testAddCollectingAreas() {
487 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
488 Assert
.assertEquals("No area must exist", 0, specimenFacade
489 .getCollectingAreas().size());
490 specimenFacade
.addCollectingArea(firstArea
);
491 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
492 .getCollectingAreas().size());
494 String tdwgLabel
= "GER";
495 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgAbbreviation(tdwgLabel
);
496 NamedArea secondArea
= NamedArea
497 .NewInstance("A nice area", "nice", "n");
499 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
500 areaCollection
.add(secondArea
);
501 areaCollection
.add(tdwgArea
);
502 specimenFacade
.addCollectingAreas(areaCollection
);
503 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
504 .getCollectingAreas().size());
510 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
514 public void testGetSetAbsoluteElevation() {
515 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
516 specimenFacade
.setAbsoluteElevation(400);
517 Assert
.assertEquals("Absolute elevation must be 400",Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
522 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
526 public void testGetSetAbsoluteElevationError() {
527 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
528 Assert
.assertEquals("Absolute elevation error must be same",absoluteElevationError
, specimenFacade
.getAbsoluteElevationError());
529 specimenFacade
.setAbsoluteElevationError(4);
530 Assert
.assertEquals("Absolute elevation error must be 4",Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationError());
531 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
536 public void testGetSetAbsoluteElevationRange() {
537 Integer expected
= absoluteElevation
- 2;
538 Assert
.assertEquals("", expected
, specimenFacade
.getAbsoluteElevationMinimum());
539 expected
= absoluteElevation
+ 2;
540 Assert
.assertEquals("", expected
,specimenFacade
.getAbsoluteElevationMaximum());
542 specimenFacade
.setAbsoluteElevationRange(30, 36);
543 Assert
.assertEquals("", Integer
.valueOf(36),specimenFacade
.getAbsoluteElevationMaximum());
544 Assert
.assertEquals("", Integer
.valueOf(30),specimenFacade
.getAbsoluteElevationMinimum());
545 Assert
.assertEquals("", Integer
.valueOf(33),specimenFacade
.getAbsoluteElevation());
546 Assert
.assertEquals("", Integer
.valueOf(3),specimenFacade
.getAbsoluteElevationError());
550 specimenFacade
.setAbsoluteElevationRange(30, 35);
551 Assert
.fail("Odd distance needs to throw IllegalArgumentException");
552 } catch (IllegalArgumentException e
) {
553 Assert
.assertTrue("Exception needs to be thrown", true);
556 specimenFacade
.setAbsoluteElevationRange(41, null);
557 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevationMaximum());
558 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevationMinimum());
559 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
560 Assert
.assertNotNull("", specimenFacade
.getAbsoluteElevationError());
561 Assert
.assertEquals("", Integer
.valueOf(0),specimenFacade
.getAbsoluteElevationError());
563 specimenFacade
.setAbsoluteElevationRange(null, null);
564 Assert
.assertNull("", specimenFacade
.getAbsoluteElevation());
565 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationError());
572 public void testGetSetCollector() {
573 Assert
.assertNotNull("Collector must not be null",
574 specimenFacade
.getCollector());
575 Assert
.assertEquals("Collector must be same", collector
,
576 specimenFacade
.getCollector());
577 specimenFacade
.setCollector(null);
578 Assert
.assertNull("Collector must be null",
579 specimenFacade
.getCollector());
584 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
588 public void testGetSetCollectingMethod() {
589 Assert
.assertEquals("Collecting method must be same", collectingMethod
,
590 specimenFacade
.getCollectingMethod());
591 specimenFacade
.setCollectingMethod("new method");
592 Assert
.assertEquals("Collecting method must be 'new method'",
593 "new method", specimenFacade
.getCollectingMethod());
598 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
602 public void testGetSetDistanceToGround() {
603 Assert
.assertEquals("Distance to ground must be same",
604 distanceToGround
, specimenFacade
.getDistanceToGround());
605 specimenFacade
.setDistanceToGround(5);
606 Assert
.assertEquals("Distance to ground must be 5", Integer
.valueOf(5),
607 specimenFacade
.getDistanceToGround());
612 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
616 public void testGetDistanceToWaterSurface() {
617 Assert
.assertEquals("Distance to surface must be same",
618 distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
619 specimenFacade
.setDistanceToWaterSurface(6);
620 Assert
.assertEquals("Distance to surface must be 6",
621 Integer
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
622 // empty facade tests
623 Assert
.assertNull("Empty facace must not have any gathering values",
624 emptyFacade
.getDistanceToWaterSurface());
625 emptyFacade
.setDistanceToWaterSurface(13);
626 Assert
.assertNotNull(
627 "Field observation must exist if distance to water exists",
628 emptyFacade
.getFieldObservation(false));
629 Assert
.assertNotNull(
630 "Gathering event must exist if distance to water exists",
631 emptyFacade
.getGatheringEvent(false));
632 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
633 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
636 "Gathering event of facade and of specimen must be the same",
637 specimenFieldObservation
.getGatheringEvent(),
638 emptyFacade
.getGatheringEvent(false));
643 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
646 public void testGetSetExactLocation() {
647 Assert
.assertNotNull("Exact location must not be null",
648 specimenFacade
.getExactLocation());
649 Assert
.assertEquals("Exact location must be same", exactLocation
,
650 specimenFacade
.getExactLocation());
651 specimenFacade
.setExactLocation(null);
652 Assert
.assertNull("Exact location must be null",
653 specimenFacade
.getExactLocation());
657 public void testSetExactLocationByParsing() {
660 specimenFacade
.setExactLocationByParsing("112\u00B034'20\"W",
661 "34\u00B030,34'N", null, null);
662 point1
= specimenFacade
.getExactLocation();
663 Assert
.assertNotNull("", point1
.getLatitude());
664 System
.out
.println(point1
.getLatitude().toString());
665 Assert
.assertTrue("",
666 point1
.getLatitude().toString().startsWith("34.505"));
667 System
.out
.println(point1
.getLongitude().toString());
668 Assert
.assertTrue("",
669 point1
.getLongitude().toString().startsWith("-112.5722"));
671 } catch (ParseException e
) {
672 Assert
.fail("No parsing error should occur");
678 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
682 public void testGetSetGatheringEventDescription() {
683 Assert
.assertEquals("Gathering event description must be same",
684 gatheringEventDescription
,
685 specimenFacade
.getGatheringEventDescription());
686 specimenFacade
.setGatheringEventDescription("new description");
688 "Gathering event description must be 'new description' now",
690 specimenFacade
.getGatheringEventDescription());
695 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
698 public void testGetTimeperiod() {
699 Assert
.assertNotNull("Gathering period must not be null",
700 specimenFacade
.getGatheringPeriod());
701 Assert
.assertEquals("Gathering period must be same", gatheringPeriod
,
702 specimenFacade
.getGatheringPeriod());
703 specimenFacade
.setGatheringPeriod(null);
704 Assert
.assertNull("Gathering period must be null",
705 specimenFacade
.getGatheringPeriod());
709 public void testHasFieldObject() throws SecurityException
,
710 NoSuchFieldException
, IllegalArgumentException
,
711 IllegalAccessException
{
712 // this test depends on the current implementation of SpecimenFacade. In
714 // field observation may not be initialized from the beginning. Than the
716 // assert should be set to assertNull
718 "field object should not be null (depends on specimen facade initialization !!)",
719 specimenFacade
.hasFieldObject());
721 Field fieldObservationField
= DerivedUnitFacade
.class
722 .getDeclaredField("fieldObservation");
723 fieldObservationField
.setAccessible(true);
724 fieldObservationField
.set(specimenFacade
, null);
725 Assert
.assertFalse("The field observation should be null now",
726 specimenFacade
.hasFieldObject());
728 specimenFacade
.setDistanceToGround(33);
730 "The field observation should have been created again",
731 specimenFacade
.hasFieldObject());
736 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
740 public void testAddGetRemoveFieldObjectDefinition() {
741 Assert
.assertEquals("There should be no definition yet", 0,
742 specimenFacade
.getFieldObjectDefinition().size());
743 specimenFacade
.addFieldObjectDefinition("Tres interesant",
745 Assert
.assertEquals("There should be exactly one definition", 1,
746 specimenFacade
.getFieldObjectDefinition().size());
748 "The French definition should be 'Tres interesant'",
749 "Tres interesant", specimenFacade
.getFieldObjectDefinition()
750 .get(Language
.FRENCH()).getText());
752 "The French definition should be 'Tres interesant'",
754 specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
755 specimenFacade
.addFieldObjectDefinition("Sehr interessant",
757 Assert
.assertEquals("There should be exactly 2 definition", 2,
758 specimenFacade
.getFieldObjectDefinition().size());
759 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
760 Assert
.assertEquals("There should remain exactly 1 definition", 1,
761 specimenFacade
.getFieldObjectDefinition().size());
763 "The remaining German definition should be 'Sehr interessant'",
765 specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
766 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
767 Assert
.assertEquals("There should remain no definition", 0,
768 specimenFacade
.getFieldObjectDefinition().size());
773 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
777 public void testAddGetHasRemoveFieldObjectMedia() {
778 Assert
.assertFalse("There should be no image gallery yet",
779 specimenFacade
.hasFieldObjectImageGallery());
780 Assert
.assertFalse("There should be no specimen image gallery either",
781 specimenFacade
.hasDerivedUnitImageGallery());
783 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
784 Assert
.assertFalse("There should still not be an image gallery now",
785 specimenFacade
.hasFieldObjectImageGallery());
786 Assert
.assertEquals("There should be no media yet in the gallery", 0,
789 Media media1
= Media
.NewInstance();
790 specimenFacade
.addFieldObjectMedia(media1
);
791 Assert
.assertEquals("There should be exactly one specimen media", 1,
792 specimenFacade
.getFieldObjectMedia().size());
793 Assert
.assertEquals("The only media should be media 1", media1
,
794 specimenFacade
.getFieldObjectMedia().get(0));
796 "There should still no specimen image gallery exist",
797 specimenFacade
.hasDerivedUnitImageGallery());
799 Media media2
= Media
.NewInstance();
800 specimenFacade
.addFieldObjectMedia(media2
);
801 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
802 specimenFacade
.getFieldObjectMedia().size());
803 Assert
.assertEquals("The first media should be media1", media1
,
804 specimenFacade
.getFieldObjectMedia().get(0));
805 Assert
.assertEquals("The second media should be media2", media2
,
806 specimenFacade
.getFieldObjectMedia().get(1));
808 specimenFacade
.removeFieldObjectMedia(media1
);
809 Assert
.assertEquals("There should be exactly one specimen media", 1,
810 specimenFacade
.getFieldObjectMedia().size());
811 Assert
.assertEquals("The only media should be media2", media2
,
812 specimenFacade
.getFieldObjectMedia().get(0));
814 specimenFacade
.removeFieldObjectMedia(media1
);
815 Assert
.assertEquals("There should still be exactly one specimen media",
816 1, specimenFacade
.getFieldObjectMedia().size());
818 specimenFacade
.removeFieldObjectMedia(media2
);
819 Assert
.assertEquals("There should remain no media in the gallery", 0,
826 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
830 public void testGetSetEcology() {
831 Assert
.assertNotNull(
832 "An empty ecology data should be created when calling getEcology()",
833 specimenFacade
.getEcologyAll());
835 "An empty ecology data should be created when calling getEcology()",
836 0, specimenFacade
.getEcologyAll().size());
837 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
838 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
839 specimenFacade
.getEcologyAll().size());
841 "Ecology data should be 'Tres jolie ici' for French",
842 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
844 "Ecology data should be null for the default language",
845 specimenFacade
.getEcology());
846 specimenFacade
.setEcology("Nice here");
847 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
848 specimenFacade
.getEcologyAll().size());
849 Assert
.assertEquals("Ecology data should be 'Tres jolie ici'",
850 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
852 "Ecology data should be 'Nice here' for the default language",
853 "Nice here", specimenFacade
.getEcology());
854 Assert
.assertEquals("Ecology data should be 'Nice here' for english",
855 "Nice here", specimenFacade
.getEcology());
857 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
858 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
859 specimenFacade
.getEcologyAll().size());
860 Assert
.assertEquals("Ecology data should be 'Vert et rouge'",
861 "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
863 "Ecology data should be 'Nice here' for the default language",
864 "Nice here", specimenFacade
.getEcology());
866 specimenFacade
.setEcology(null, Language
.FRENCH());
867 Assert
.assertEquals("Ecology data should exist for 1 languages", 1,
868 specimenFacade
.getEcologyAll().size());
870 "Ecology data should be 'Nice here' for the default language",
871 "Nice here", specimenFacade
.getEcology());
872 Assert
.assertNull("Ecology data should be 'null' for French",
873 specimenFacade
.getEcology(Language
.FRENCH()));
875 specimenFacade
.removeEcology(null);
876 Assert
.assertEquals("There should be no ecology left", 0,
877 specimenFacade
.getEcologyAll().size());
878 Assert
.assertNull("Ecology data should be 'null' for default language",
879 specimenFacade
.getEcology());
885 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
889 public void testGetSetPlantDescription() {
890 Assert
.assertNotNull(
891 "An empty plant description data should be created when calling getPlantDescriptionAll()",
892 specimenFacade
.getPlantDescriptionAll());
894 "An empty plant description data should be created when calling getPlantDescription()",
895 0, specimenFacade
.getPlantDescriptionAll().size());
896 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
898 "Plant description data should exist for 1 language", 1,
899 specimenFacade
.getPlantDescriptionAll().size());
901 "Plant description data should be 'bleu' for French", "bleu",
902 specimenFacade
.getPlantDescription(Language
.FRENCH()));
904 "Plant description data should be null for the default language",
905 specimenFacade
.getPlantDescription());
906 specimenFacade
.setPlantDescription("Nice here");
908 "Plant description data should exist for 2 languages", 2,
909 specimenFacade
.getPlantDescriptionAll().size());
910 Assert
.assertEquals("Plant description data should be 'bleu'", "bleu",
911 specimenFacade
.getPlantDescription(Language
.FRENCH()));
913 "Plant description data should be 'Nice here' for the default language",
914 "Nice here", specimenFacade
.getPlantDescription());
916 "Plant description data should be 'Nice here' for english",
917 "Nice here", specimenFacade
.getPlantDescription());
919 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
921 "Plant description data should exist for 2 languages", 2,
922 specimenFacade
.getPlantDescriptionAll().size());
923 Assert
.assertEquals("Plant description data should be 'Vert et rouge'",
925 specimenFacade
.getPlantDescription(Language
.FRENCH()));
927 "Plant description data should be 'Nice here' for the default language",
928 "Nice here", specimenFacade
.getPlantDescription());
930 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
932 "Plant description data should exist for 1 languages", 1,
933 specimenFacade
.getPlantDescriptionAll().size());
935 "Plant description data should be 'Nice here' for the default language",
936 "Nice here", specimenFacade
.getPlantDescription());
937 Assert
.assertNull("Plant description data should be 'null' for French",
938 specimenFacade
.getPlantDescription(Language
.FRENCH()));
940 // test interference with ecology
941 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
942 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
943 specimenFacade
.getEcologyAll().size());
945 "Ecology data should be 'Tres jolie ici' for French",
946 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
948 "Ecology data should be null for the default language",
949 specimenFacade
.getEcology());
953 "Plant description data should exist for 1 languages", 1,
954 specimenFacade
.getPlantDescriptionAll().size());
956 "Plant description data should be 'Nice here' for the default language",
957 "Nice here", specimenFacade
.getPlantDescription());
958 Assert
.assertNull("Plant description data should be 'null' for French",
959 specimenFacade
.getPlantDescription(Language
.FRENCH()));
961 specimenFacade
.removePlantDescription(null);
962 Assert
.assertEquals("There should be no plant description left", 0,
963 specimenFacade
.getPlantDescriptionAll().size());
965 "Plant description data should be 'null' for default language",
966 specimenFacade
.getPlantDescription());
972 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
975 public void testGetSetFieldNumber() {
976 Assert
.assertEquals("Field number must be same", fieldNumber
,
977 specimenFacade
.getFieldNumber());
978 specimenFacade
.setFieldNumber("564AB");
979 Assert
.assertEquals("New field number must be '564AB'", "564AB",
980 specimenFacade
.getFieldNumber());
981 // empty facade tests
982 Assert
.assertNull("Empty facace must not have any field value",
983 emptyFacade
.getFieldNumber());
984 emptyFacade
.setFieldNumber("1256A");
985 Assert
.assertNotNull(
986 "Field observation must exist if field number exists",
987 emptyFacade
.getFieldObservation(false));
988 FieldObservation specimenFieldObservation
= (FieldObservation
) emptyFacade
989 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
992 "Field observation of facade and of specimen must be the same",
993 specimenFieldObservation
,
994 emptyFacade
.getFieldObservation(false));
995 Assert
.assertEquals("1256A", emptyFacade
.getFieldNumber());
1000 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
1003 public void testGetSetFieldNotes() {
1004 Assert
.assertEquals("Field notes must be same", fieldNotes
,
1005 specimenFacade
.getFieldNotes());
1006 specimenFacade
.setFieldNotes("A completely new info");
1007 Assert
.assertEquals("New field note must be 'A completely new info'",
1008 "A completely new info", specimenFacade
.getFieldNotes());
1013 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1017 public void testSetGatheringEvent() {
1018 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1019 newGatheringEvent
.setDistanceToGround(43);
1020 Assert
.assertFalse("The initial distance to ground should not be 43",
1021 specimenFacade
.getDistanceToGround() == 43);
1022 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1023 Assert
.assertTrue("The final distance to ground should be 43",
1024 specimenFacade
.getDistanceToGround() == 43);
1026 "The new gathering event should be 'newGatheringEvent'",
1027 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1032 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1036 public void testGetGatheringEvent() {
1037 Assert
.assertNotNull("Gathering event must not be null",
1038 specimenFacade
.innerGatheringEvent());
1039 Assert
.assertEquals(
1040 "Gathering event must be field observations gathering event",
1041 specimenFacade
.innerFieldObservation().getGatheringEvent(),
1042 specimenFacade
.innerGatheringEvent());
1047 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1051 public void testGetSetIndividualCount() {
1052 Assert
.assertEquals("Individual count must be same", individualCount
,
1053 specimenFacade
.getIndividualCount());
1054 specimenFacade
.setIndividualCount(4);
1055 Assert
.assertEquals("New individual count must be '4'",
1056 Integer
.valueOf(4), specimenFacade
.getIndividualCount());
1062 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1065 public void testGetSetLifeStage() {
1066 Assert
.assertNotNull("Life stage must not be null",
1067 specimenFacade
.getLifeStage());
1068 Assert
.assertEquals("Life stage must be same", lifeStage
,
1069 specimenFacade
.getLifeStage());
1070 specimenFacade
.setLifeStage(null);
1071 Assert
.assertNull("Life stage must be null",
1072 specimenFacade
.getLifeStage());
1077 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1080 public void testGetSetSex() {
1081 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
1082 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1083 specimenFacade
.setSex(null);
1084 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
1089 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1092 public void testGetSetLocality() {
1093 Assert
.assertEquals("Locality must be same", locality
,
1094 specimenFacade
.getLocality());
1095 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1096 Assert
.assertEquals("New locality must be 'A completely new place'",
1097 "A completely new place", specimenFacade
.getLocalityText());
1098 Assert
.assertEquals("New locality language must be French",
1099 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1100 specimenFacade
.setLocality("Another place");
1101 Assert
.assertEquals("New locality must be 'Another place'",
1102 "Another place", specimenFacade
.getLocalityText());
1103 Assert
.assertEquals("New locality language must be default",
1104 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1109 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1113 public void testAddGetRemoveSpecimenDefinition() {
1114 Assert
.assertEquals("There should be no definition yet", 0,
1115 specimenFacade
.getDerivedUnitDefinitions().size());
1116 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1118 Assert
.assertEquals("There should be exactly one definition", 1,
1119 specimenFacade
.getDerivedUnitDefinitions().size());
1120 Assert
.assertEquals(
1121 "The French definition should be 'Tres interesant'",
1122 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1123 .get(Language
.FRENCH()).getText());
1124 Assert
.assertEquals(
1125 "The French definition should be 'Tres interesant'",
1127 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1128 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1130 Assert
.assertEquals("There should be exactly 2 definition", 2,
1131 specimenFacade
.getDerivedUnitDefinitions().size());
1132 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1133 Assert
.assertEquals("There should remain exactly 1 definition", 1,
1134 specimenFacade
.getDerivedUnitDefinitions().size());
1135 Assert
.assertEquals(
1136 "The remaining German definition should be 'Sehr interessant'",
1138 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1139 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1140 Assert
.assertEquals("There should remain no definition", 0,
1141 specimenFacade
.getDerivedUnitDefinitions().size());
1146 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1150 public void testAddGetRemoveDetermination() {
1151 Assert
.assertEquals("There should be no determination yet", 0,
1152 specimenFacade
.getDeterminations().size());
1153 DeterminationEvent determinationEvent1
= DeterminationEvent
1155 specimenFacade
.addDetermination(determinationEvent1
);
1156 Assert
.assertEquals("There should be exactly one determination", 1,
1157 specimenFacade
.getDeterminations().size());
1158 Assert
.assertEquals("The only determination should be determination 1",
1159 determinationEvent1
, specimenFacade
.getDeterminations()
1160 .iterator().next());
1162 DeterminationEvent determinationEvent2
= DeterminationEvent
1164 specimenFacade
.addDetermination(determinationEvent2
);
1165 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1166 specimenFacade
.getDeterminations().size());
1167 specimenFacade
.removeDetermination(determinationEvent1
);
1169 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1170 specimenFacade
.getDeterminations().size());
1171 Assert
.assertEquals(
1172 "The remaining determinations should be determination 2",
1173 determinationEvent2
, specimenFacade
.getDeterminations()
1174 .iterator().next());
1176 specimenFacade
.removeDetermination(determinationEvent1
);
1177 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1178 specimenFacade
.getDeterminations().size());
1180 specimenFacade
.removeDetermination(determinationEvent2
);
1181 Assert
.assertEquals("There should remain no definition", 0,
1182 specimenFacade
.getDerivedUnitDefinitions().size());
1189 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1193 public void testPreferredOtherDeterminations() {
1194 Assert
.assertEquals("There should be no determination yet", 0,
1195 specimenFacade
.getDeterminations().size());
1196 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1197 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1199 Assert
.assertEquals("There should be exactly one determination", 1,
1200 specimenFacade
.getDeterminations().size());
1201 Assert
.assertEquals("The only determination should be determination 1",
1202 determinationEvent1
, specimenFacade
.getDeterminations()
1203 .iterator().next());
1204 Assert
.assertEquals("determination 1 should be the preferred determination",
1205 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1206 Assert
.assertEquals("There should be no 'non preferred' determination", 0,
1207 specimenFacade
.getOtherDeterminations().size());
1211 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1212 specimenFacade
.addDetermination(determinationEvent2
);
1213 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1214 specimenFacade
.getDeterminations().size());
1215 Assert
.assertEquals("determination 1 should be the preferred determination",
1216 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1217 Assert
.assertEquals("There should be one 'non preferred' determination", 1,
1218 specimenFacade
.getOtherDeterminations().size());
1219 Assert
.assertEquals("The only 'non preferred' determination should be determination 2",
1220 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1223 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1224 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1225 Assert
.assertEquals("There should be exactly 3 determinations", 3,
1226 specimenFacade
.getDeterminations().size());
1227 Assert
.assertEquals("determination 3 should be the preferred determination",
1228 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1229 Assert
.assertEquals("There should be 2 'non preferred' determination", 2,
1230 specimenFacade
.getOtherDeterminations().size());
1231 Assert
.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1232 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1233 Assert
.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1234 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1240 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1244 public void testAddGetHasRemoveSpecimenMedia() {
1245 Assert
.assertFalse("There should be no image gallery yet",
1246 specimenFacade
.hasDerivedUnitImageGallery());
1248 "There should be also no field object image gallery yet",
1249 specimenFacade
.hasFieldObjectImageGallery());
1251 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1253 "There should still not be an empty image gallery now",
1254 specimenFacade
.hasDerivedUnitImageGallery());
1255 Assert
.assertEquals("There should be no media yet in the gallery", 0,
1258 Media media1
= Media
.NewInstance();
1259 specimenFacade
.addDerivedUnitMedia(media1
);
1260 Assert
.assertEquals("There should be exactly one specimen media", 1,
1261 specimenFacade
.getDerivedUnitMedia().size());
1262 Assert
.assertEquals("The only media should be media 1", media1
,
1263 specimenFacade
.getDerivedUnitMedia().get(0));
1265 "There should be still no field object image gallery",
1266 specimenFacade
.hasFieldObjectImageGallery());
1268 Media media2
= Media
.NewInstance();
1269 specimenFacade
.addDerivedUnitMedia(media2
);
1270 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
1271 specimenFacade
.getDerivedUnitMedia().size());
1272 Assert
.assertEquals("The first media should be media1", media1
,
1273 specimenFacade
.getDerivedUnitMedia().get(0));
1274 Assert
.assertEquals("The second media should be media2", media2
,
1275 specimenFacade
.getDerivedUnitMedia().get(1));
1277 specimenFacade
.removeDerivedUnitMedia(media1
);
1278 Assert
.assertEquals("There should be exactly one specimen media", 1,
1279 specimenFacade
.getDerivedUnitMedia().size());
1280 Assert
.assertEquals("The only media should be media2", media2
,
1281 specimenFacade
.getDerivedUnitMedia().get(0));
1283 specimenFacade
.removeDerivedUnitMedia(media1
);
1284 Assert
.assertEquals("There should still be exactly one specimen media",
1285 1, specimenFacade
.getDerivedUnitMedia().size());
1287 specimenFacade
.removeDerivedUnitMedia(media2
);
1288 Assert
.assertEquals("There should remain no media in the gallery", 0,
1294 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1298 public void testGetSetAccessionNumber() {
1299 Assert
.assertEquals("Accession number must be same", accessionNumber
,
1300 specimenFacade
.getAccessionNumber());
1301 specimenFacade
.setAccessionNumber("A12345693");
1302 Assert
.assertEquals("New accession number must be 'A12345693'",
1303 "A12345693", specimenFacade
.getAccessionNumber());
1308 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1311 public void testGetCatalogNumber() {
1312 Assert
.assertEquals("Catalog number must be same", catalogNumber
,
1313 specimenFacade
.getCatalogNumber());
1314 specimenFacade
.setCatalogNumber("B12345693");
1315 Assert
.assertEquals("New catalog number must be 'B12345693'",
1316 "B12345693", specimenFacade
.getCatalogNumber());
1321 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1324 public void testGetPreservation() {
1326 Assert
.assertNotNull("Preservation method must not be null",
1327 specimenFacade
.getPreservationMethod());
1328 Assert
.assertEquals("Preservation method must be same",
1329 preservationMethod
, specimenFacade
.getPreservationMethod());
1330 specimenFacade
.setPreservationMethod(null);
1331 Assert
.assertNull("Preservation method must be null",
1332 specimenFacade
.getPreservationMethod());
1333 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1334 Assert
.fail("Method not supported should not be thrown for a specimen");
1336 specimenFacade
= DerivedUnitFacade
1337 .NewInstance(DerivedUnitType
.Observation
);
1339 specimenFacade
.setPreservationMethod(preservationMethod
);
1340 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
1342 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1345 specimenFacade
= DerivedUnitFacade
1346 .NewInstance(DerivedUnitType
.LivingBeing
);
1348 specimenFacade
.getPreservationMethod();
1349 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
1350 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1358 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1361 public void testGetStoredUnder() {
1362 Assert
.assertNotNull("Stored under name must not be null",
1363 specimenFacade
.getStoredUnder());
1364 Assert
.assertEquals("Stored under name must be same", taxonName
,
1365 specimenFacade
.getStoredUnder());
1366 specimenFacade
.setStoredUnder(null);
1367 Assert
.assertNull("Stored under name must be null",
1368 specimenFacade
.getStoredUnder());
1372 // * Test method for
1373 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1377 // public void testGetSetCollectorsNumber() {
1378 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1379 // specimenFacade.getCollectorsNumber());
1380 // specimenFacade.setCollectorsNumber("C12345693");
1381 // Assert.assertEquals("New collectors number must be 'C12345693'",
1382 // "C12345693", specimenFacade.getCollectorsNumber());
1387 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1390 public void testGetTitleCache() {
1391 Assert
.assertNotNull(
1392 "The title cache should never return null if not protected",
1393 specimenFacade
.getTitleCache());
1394 specimenFacade
.setTitleCache(null, false);
1395 Assert
.assertNotNull(
1396 "The title cache should never return null if not protected",
1397 specimenFacade
.getTitleCache());
1402 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1406 public void testSetTitleCache() {
1407 String testTitle
= "Absdwk aksjlf";
1408 specimenFacade
.setTitleCache(testTitle
, true);
1409 Assert
.assertEquals(
1410 "Protected title cache should returns the test title",
1411 testTitle
, specimenFacade
.getTitleCache());
1412 specimenFacade
.setTitleCache(testTitle
, false);
1414 "Unprotected title cache should not return the test title",
1415 testTitle
.equals(specimenFacade
.getTitleCache()));
1420 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1423 public void testGetSpecimen() {
1424 Assert
.assertEquals("Specimen must be same", specimen
,
1425 specimenFacade
.innerDerivedUnit());
1430 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1433 public void testGetSetCollection() {
1434 Assert
.assertNotNull("Collection must not be null",
1435 specimenFacade
.getCollection());
1436 Assert
.assertEquals("Collection must be same", collection
,
1437 specimenFacade
.getCollection());
1438 specimenFacade
.setCollection(null);
1439 Assert
.assertNull("Collection must be null",
1440 specimenFacade
.getCollection());
1444 public void testAddGetRemoveSource() {
1445 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
1446 .getSources().size());
1447 Reference reference
= ReferenceFactory
.newBook();
1448 IdentifiableSource source1
= specimenFacade
.addSource(reference
, "54",
1450 Assert
.assertEquals("One source should exist now", 1, specimenFacade
1451 .getSources().size());
1452 IdentifiableSource source2
= IdentifiableSource
.NewInstance("1",
1454 specimenFacade
.addSource(source2
);
1455 Assert
.assertEquals("One source should exist now", 2, specimenFacade
1456 .getSources().size());
1457 specimenFacade
.removeSource(source1
);
1458 Assert
.assertEquals("One source should exist now", 1, specimenFacade
1459 .getSources().size());
1460 Reference reference2
= ReferenceFactory
.newJournal();
1461 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(reference2
,
1463 specimenFacade
.removeSource(sourceNotUsed
);
1464 Assert
.assertEquals("One source should still exist", 1, specimenFacade
1465 .getSources().size());
1466 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next()
1468 specimenFacade
.removeSource(source2
);
1469 Assert
.assertEquals("No sources should exist anymore", 0,
1470 specimenFacade
.getSources().size());
1474 public void testAddGetRemoveDuplicate() {
1475 Assert
.assertEquals("No duplicates should be available yet", 0,
1476 specimenFacade
.getDuplicates().size());
1477 Specimen newSpecimen1
= Specimen
.NewInstance();
1478 specimenFacade
.addDuplicate(newSpecimen1
);
1479 Assert
.assertEquals("There should be 1 duplicate now", 1,
1480 specimenFacade
.getDuplicates().size());
1481 Specimen newSpecimen2
= Specimen
.NewInstance();
1482 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance();
1483 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1485 "The derivation event should be 'newDerivationEvent'",
1486 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1487 specimenFacade
.addDuplicate(newSpecimen2
);
1488 Assert
.assertEquals("There should be 2 duplicates now", 2,
1489 specimenFacade
.getDuplicates().size());
1490 Assert
.assertNotSame(
1491 "The derivation event should not be 'newDerivationEvent' anymore",
1492 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1494 "The derivation event should not be the facades derivation event",
1495 derivationEvent
, newSpecimen2
.getDerivedFrom());
1496 specimenFacade
.removeDuplicate(newSpecimen1
);
1497 Assert
.assertEquals("There should be 1 duplicate now", 1,
1498 specimenFacade
.getDuplicates().size());
1499 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now",
1500 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1501 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1502 Assert
.assertEquals(
1503 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1504 1, specimenFacade
.getDuplicates().size());
1506 Collection newCollection
= Collection
.NewInstance();
1507 String catalogNumber
= "1234890";
1508 String accessionNumber
= "345345";
1509 String collectorsNumber
= "lkjewe";
1510 TaxonNameBase storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
1511 PreservationMethod method
= PreservationMethod
.NewInstance();
1512 Specimen duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1513 catalogNumber
, accessionNumber
, storedUnder
,
1515 Assert
.assertEquals("There should be 2 duplicates now", 2,
1516 specimenFacade
.getDuplicates().size());
1517 specimenFacade
.removeDuplicate(newSpecimen2
);
1518 Assert
.assertEquals("There should be 1 duplicates now", 1,
1519 specimenFacade
.getDuplicates().size());
1520 Collection sameCollection
= specimenFacade
.getDuplicates().iterator()
1521 .next().getCollection();
1522 Assert
.assertSame("Collections should be same", newCollection
,
1526 // ************************** Existing Specimen with multiple derivation
1527 // events in line **************/
1530 public void testExistingSpecimen() {
1531 specimenFacade
= null;
1533 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1534 } catch (DerivedUnitFacadeNotSupportedException e
) {
1535 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
1538 "Gathering event should derive from the derivation line",
1539 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1540 Assert
.assertEquals(
1541 "Mediasize should be 0. Only Imagegallery media are supported",
1542 0, specimenFacade
.getFieldObjectMedia().size());
1546 public void testMultipleFieldObservationsNotSupported() {
1547 specimenFacade
= null;
1548 FieldObservation secondFieldObject
= FieldObservation
.NewInstance();
1549 firstDerivationEvent
.addOriginal(secondFieldObject
);
1551 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1552 Assert
.fail("Multiple field observations for one specimen should no be supported by the facade");
1553 } catch (DerivedUnitFacadeNotSupportedException e
) {
1556 Assert
.assertNull("Specimen facade should not be initialized",
1561 public void testOnlyImageGallerySupported() {
1562 specimenFacade
= null;
1563 firstFieldObject
.addMedia(media1
);
1565 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1566 Assert
.fail("Only image galleries are supported by the facade but not direct media");
1567 } catch (DerivedUnitFacadeNotSupportedException e
) {
1570 Assert
.assertNull("Specimen facade should not be initialized",
1575 public void testEventPropagation() {
1576 specimenFacade
.setDistanceToGround(24);
1580 // @Ignore // set to ignore because I did not want to check knowingly
1581 // failing tests. Remove @Ignore when this is fixed
1583 public void testSetBarcode() {
1584 String barcode
= "barcode";
1585 specimenFacade
.setBarcode(barcode
);
1587 Assert
.assertEquals(barcode
, specimenFacade
.getBarcode());
1591 public void testIsEvenDistance() {
1592 Integer minimum
= 20;
1593 Integer maximum
= 1234;
1595 // this should not throw exceptions
1596 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1600 private IUserService userService
;
1604 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1605 * This test doesn't handle the above issue yet as it doesn't fire events as
1606 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1607 * In the meanwhile the property change framework for the facade has been changed
1608 * so the original problem may have disappeared.
1612 public void testNoRecursiveChangeEvents(){
1613 String username
= "username";
1614 String password
= "password";
1615 User user
= User
.NewInstance(username
, password
);
1616 userService
.save(user
);
1617 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1618 SecurityContextHolder
.getContext().setAuthentication(token
);
1620 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
1621 facade
.setLocality("testLocality");
1622 facade
.getTitleCache();
1623 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1624 this.service
.save(facade
.innerDerivedUnit());