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 static org
.junit
.Assert
.assertEquals
;
14 import java
.io
.FileNotFoundException
;
15 import java
.lang
.reflect
.Field
;
17 import java
.text
.ParseException
;
18 import java
.util
.HashSet
;
19 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.junit
.Assert
;
24 import org
.junit
.Before
;
25 import org
.junit
.Ignore
;
26 import org
.junit
.Test
;
27 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
28 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
29 import org
.unitils
.dbunit
.annotation
.DataSet
;
30 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
31 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
36 import eu
.etaxonomy
.cdm
.common
.UTF8
;
37 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
38 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
39 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
40 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
41 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
42 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
43 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
44 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
45 import eu
.etaxonomy
.cdm
.model
.common
.User
;
46 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
47 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
48 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
49 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
50 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
51 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
52 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
53 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
54 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
55 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
56 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
64 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
65 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
66 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
67 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
68 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
71 * Test class for {@link DerivedUnitFacade}
76 public class DerivedUnitFacadeTest
extends CdmTransactionalIntegrationTest
{
77 @SuppressWarnings("unused")
78 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeTest
.class);
82 private IOccurrenceService service
;
85 private ITermService termService
;
88 private IUserService userService
;
92 DerivationEvent derivationEvent
;
94 GatheringEvent gatheringEvent
;
95 Integer absoluteElevation
= 10;
96 Integer absoluteElevationMaximum
= 14;
97 AgentBase
<?
> collector
= Team
.NewInstance();
98 String collectingMethod
= "Collection Method";
99 Double distanceToGround
= 22.0;
100 Double distanceToSurface
= 0.3;
101 Double distanceToSurfaceMax
= 0.7;
103 ReferenceSystem referenceSystem
= ReferenceSystem
.WGS84();
104 Point exactLocation
= Point
.NewInstance(12.3, 10.567, referenceSystem
, 22);
105 String gatheringEventDescription
= "A nice gathering description";
106 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(1888, 1889);
108 String fieldNumber
= "15p23B";
109 String fieldNotes
= "such a beautiful specimen";
111 Integer individualCount
= 1;
112 DefinedTerm lifeStage
= DefinedTerm
.NewStageInstance("A wonderful stage", "stage", "st");
113 DefinedTerm sex
= DefinedTerm
.NewSexInstance("FemaleMale", "FM", "FM");
114 LanguageString locality
= LanguageString
.NewInstance("My locality",
117 String accessionNumber
= "888462535";
118 String catalogNumber
= "UU879873590";
119 TaxonNameBase
<?
,?
> taxonName
= BotanicalName
.NewInstance(Rank
.GENUS(), "Abies",
120 null, null, null, null, null, null, null);
121 String collectorsNumber
= "234589913A34";
122 Collection collection
= Collection
.NewInstance();
123 PreservationMethod preservationMethod
= PreservationMethod
.NewInstance(null, "my prservation");
124 String originalLabelInfo
= "original label info";
125 URI stableUri
= URI
.create("http://www.abc.de");
128 DerivedUnitFacade specimenFacade
;
130 DerivedUnit collectionSpecimen
;
131 GatheringEvent existingGatheringEvent
;
132 DerivationEvent firstDerivationEvent
;
133 FieldUnit firstFieldObject
;
134 Media media1
= Media
.NewInstance();
136 DerivedUnitFacade emptyFacade
;
138 NamedArea country
= Country
.GERMANY();
140 // ****************************** SET UP **********************************/
144 * @throws java.lang.Exception
147 public void setUp() throws Exception
{
149 specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
151 derivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
152 specimen
.setDerivedFrom(derivationEvent
);
153 fieldUnit
= FieldUnit
.NewInstance();
154 fieldUnit
.addDerivationEvent(derivationEvent
);
155 gatheringEvent
= GatheringEvent
.NewInstance();
156 fieldUnit
.setGatheringEvent(gatheringEvent
);
157 gatheringEvent
.setAbsoluteElevation(absoluteElevation
);
158 gatheringEvent
.setAbsoluteElevationMax(absoluteElevationMaximum
);
159 gatheringEvent
.setActor(collector
);
160 gatheringEvent
.setCollectingMethod(collectingMethod
);
161 gatheringEvent
.setDistanceToGround(distanceToGround
);
162 gatheringEvent
.setDistanceToWaterSurface(distanceToSurface
);
163 gatheringEvent
.setDistanceToWaterSurfaceMax(distanceToSurfaceMax
);
164 gatheringEvent
.setExactLocation(exactLocation
);
165 gatheringEvent
.setDescription(gatheringEventDescription
);
166 gatheringEvent
.setCountry(country
);
168 gatheringEvent
.setTimeperiod(gatheringPeriod
);
169 gatheringEvent
.setLocality(locality
);
171 fieldUnit
.setFieldNumber(fieldNumber
);
172 fieldUnit
.setFieldNotes(fieldNotes
);
173 fieldUnit
.setIndividualCount(individualCount
);
174 fieldUnit
.setSex(sex
);
175 fieldUnit
.setLifeStage(lifeStage
);
177 specimen
.setAccessionNumber(accessionNumber
);
178 specimen
.setCatalogNumber(catalogNumber
);
179 specimen
.setStoredUnder(taxonName
);
180 specimen
.setCollection(collection
);
181 specimen
.setPreservation(preservationMethod
);
182 specimen
.setOriginalLabelInfo(originalLabelInfo
);
183 specimen
.setPreferredStableUri(stableUri
);
185 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
187 // existing specimen with 2 derivation events in line
188 collectionSpecimen
= DerivedUnit
.NewPreservedSpecimenInstance();
189 DerivedUnit middleSpecimen
= DerivedUnit
.NewPreservedSpecimenInstance();
190 firstFieldObject
= FieldUnit
.NewInstance();
192 //TODO maybe we should define concrete event types here
193 DerivationEventType eventType
= DerivationEventType
.ACCESSIONING();
194 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
195 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
196 firstDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
198 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
200 lastDerivationEvent
.addOriginal(middleSpecimen
);
201 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
202 firstDerivationEvent
.addOriginal(firstFieldObject
);
203 existingGatheringEvent
= GatheringEvent
.NewInstance();
204 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
207 emptyFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
211 // ****************************** TESTS*****************************/
213 @Ignore //doesn't run in suite
215 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
217 public void testSetFieldObjectImageGallery() {
218 UUID imageFeatureUuid
= Feature
.IMAGE().getUuid();
219 Feature imageFeature
= (Feature
) termService
.find(imageFeatureUuid
);
221 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
222 facade
.innerDerivedUnit().setUuid(UUID
.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));
223 facade
.setFieldNumber("12345");
224 Media media
= Media
.NewInstance(URI
.create("www.abc.de"), 200, null,"jpeg");
227 SpecimenDescription imageGallery
= SpecimenDescription
.NewInstance();
228 imageGallery
.setDescribedSpecimenOrObservation(facade
.innerFieldUnit());
229 imageGallery
.setImageGallery(true);
230 TextData textData
= TextData
.NewInstance();
231 textData
.setFeature(imageFeature
);
232 imageGallery
.addElement(textData
);
233 textData
.addMedia(media
);
234 facade
.setFieldObjectImageGallery(imageGallery
);
236 } catch (DerivedUnitFacadeNotSupportedException e1
) {
237 e1
.printStackTrace();
238 Assert
.fail(e1
.getLocalizedMessage());
240 this.service
.save(facade
.innerDerivedUnit());
242 setComplete(); endTransaction();
243 // try {if (true){printDataSet(System.out, new
244 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
245 // ,"DERIVATIONEVENT",
246 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
247 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
248 // } catch(Exception e) { logger.warn(e);}
254 // TODO generally works but has id problems when running together with above
255 // test ()setFieldObjectImageGallery. Therefore set to ignore.
256 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
258 public void testSetDerivedUnitImageGallery() {
259 // UUID specimenUUID =
260 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
261 // Specimen specimen = (Specimen)service.find(specimenUUID);
262 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
263 Media media
= Media
.NewInstance(URI
.create("www.derivedUnitImage.de"),200, null, "png");
266 SpecimenDescription imageGallery
= SpecimenDescription
268 imageGallery
.setDescribedSpecimenOrObservation(facade
.innerDerivedUnit());
269 imageGallery
.setImageGallery(true);
270 TextData textData
= TextData
.NewInstance();
271 imageGallery
.addElement(textData
);
272 textData
.addMedia(media
);
273 facade
.setDerivedUnitImageGallery(imageGallery
);
275 } catch (DerivedUnitFacadeNotSupportedException e1
) {
276 e1
.printStackTrace();
277 Assert
.fail(e1
.getLocalizedMessage());
279 this.service
.save(facade
.innerDerivedUnit());
281 // setComplete(); endTransaction();
282 // try {if (true){printDataSet(System.out, new
283 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
284 // ,"DERIVATIONEVENT",
285 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
286 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
287 // } catch(Exception e) { logger.warn(e);}
294 @Ignore // TODO generally works has id problems with following tests when running in suite
295 public void testGetFieldObjectImageGalleryBooleanPersisted() {
296 UUID specimenUUID
= UUID
.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
297 DerivedUnit specimen
= (DerivedUnit
) service
.load(specimenUUID
);
298 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
300 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
301 SpecimenDescription imageGallery
= facade
.getFieldObjectImageGallery(true);
302 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
303 Assert
.assertEquals("UUID should be equal to the persisted uuid",
304 UUID
.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
305 imageGallery
.getUuid());
306 Assert
.assertEquals("The image gallery should be flagged as such",true, imageGallery
.isImageGallery());
307 Assert
.assertEquals("There should be one TextData in image gallery", 1,
308 imageGallery
.getElements().size());
309 List
<Media
> media
= imageGallery
.getElements().iterator().next().getMedia();
310 Assert
.assertEquals("There should be 1 media", 1, media
.size());
311 } catch (DerivedUnitFacadeNotSupportedException e
) {
319 // @Ignore // TODO generally works has id problems with following tests when running in suite
320 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
321 UUID specimenUUID
= UUID
.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
322 DerivedUnit specimen
= (DerivedUnit
) service
.load(specimenUUID
);
323 Assert
.assertNotNull("Specimen should exist (persisted)", specimen
);
325 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
326 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
327 Assert
.assertNotNull("Image gallery should exist", imageGallery
);
328 Assert
.assertEquals("UUID should be equal to the persisted uuid",
329 UUID
.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
330 imageGallery
.getUuid());
331 Assert
.assertEquals("The image gallery should be flagged as such",
332 true, imageGallery
.isImageGallery());
334 "There should be one TextData in image gallery", 1,
335 imageGallery
.getElements().size());
336 List
<Media
> media
= imageGallery
.getElements().iterator().next().getMedia();
337 Assert
.assertEquals("There should be 1 media", 1, media
.size());
338 } catch (DerivedUnitFacadeNotSupportedException e
) {
345 public void testGetDerivedUnitImageGalleryBoolean() {
346 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
348 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
349 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
350 Assert
.assertNotNull("Image Gallery should have been created",imageGallery
);
351 Assert
.assertEquals("The image gallery should be flagged as such",true, imageGallery
.isImageGallery());
352 } catch (DerivedUnitFacadeNotSupportedException e
) {
361 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
364 public void testNewInstanceGatheringEventCreated() {
365 Assert
.assertNotNull("The specimen should have been created",
366 specimenFacade
.innerDerivedUnit());
368 Assert
.assertNotNull("The derivation event should have been created",
369 specimenFacade
.innerDerivedUnit().getDerivedFrom());
370 Assert
.assertNotNull("The field unit should have been created",
371 specimenFacade
.innerFieldUnit());
372 Assert
.assertNotNull("The gathering event should have been created",
373 specimenFacade
.innerGatheringEvent());
381 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
385 public void testNewInstanceSpecimen() {
386 Assert
.assertSame("Specimen should be same", specimen
,
387 specimenFacade
.innerDerivedUnit());
388 Assert
.assertSame("Derivation event should be same", derivationEvent
,
389 specimenFacade
.innerDerivedUnit().getDerivedFrom());
390 Assert
.assertSame("Field unit should be same", fieldUnit
,
391 specimenFacade
.innerFieldUnit());
392 Assert
.assertSame("Gathering event should be same", gatheringEvent
,
393 specimenFacade
.innerGatheringEvent());
397 public void testNewInstanceSpecimenWithoutFieldUnit() {
398 DerivedUnit parent
= DerivedUnit
.NewPreservedSpecimenInstance();
399 DerivedUnit child
= DerivedUnit
.NewPreservedSpecimenInstance();
400 DerivationEvent
.NewSimpleInstance(parent
, child
, DerivationEventType
.ACCESSIONING());
402 DerivedUnitFacade facade
;
404 facade
= DerivedUnitFacade
.NewInstance(child
);
405 Assert
.assertTrue(facade
.innerDerivedUnit().getDerivedFrom().getOriginals().size() == 1);
406 Assert
.assertNull(facade
.getFieldUnit(false));
407 DerivationEvent
.NewSimpleInstance(FieldUnit
.NewInstance(), parent
, DerivationEventType
.ACCESSIONING());
409 } catch (DerivedUnitFacadeNotSupportedException e
) {
417 public void testGatheringEventIsConnectedToDerivedUnit() {
418 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
419 DerivedUnitFacade specimenFacade
;
421 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
422 specimenFacade
.setDistanceToGround(2.0);
423 FieldUnit specimenFieldUnit
= (FieldUnit
) specimen
.getDerivedFrom().getOriginals().iterator().next();
425 "Facade gathering event and specimen gathering event should be the same",
426 specimenFacade
.innerGatheringEvent(),
427 specimenFieldUnit
.getGatheringEvent());
428 } catch (DerivedUnitFacadeNotSupportedException e
) {
429 Assert
.fail("An error should not occur in NewInstance()");
434 public void testNoGatheringEventAndFieldUnit() {
435 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
436 DerivedUnitFacade specimenFacade
;
438 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
439 Assert
.assertNull("No field unit should exists",
440 specimenFacade
.innerFieldUnit());
441 } catch (DerivedUnitFacadeNotSupportedException e
) {
442 Assert
.fail("An error should not occur in NewInstance()");
447 public void testInititializeTextDataWithSupportTest() {
449 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
450 DerivedUnitFacade specimenFacade
;
452 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
453 specimenFacade
.setEcology("Ecology");
454 String plantDescription
= specimenFacade
.getPlantDescription();
456 "No plantDescription should exist yet and no NPE should be thrown until now",
458 } catch (DerivedUnitFacadeNotSupportedException e
) {
459 Assert
.fail("An error should not occur in NewInstance()");
464 public void testGetSetType() {
465 Assert
.assertEquals("Type must be same", SpecimenOrObservationType
.PreservedSpecimen
, specimenFacade
.getType());
466 SpecimenOrObservationType newType
= SpecimenOrObservationType
.Fossil
;
467 specimenFacade
.setType(newType
);
468 Assert
.assertEquals("New type must be Fossil", newType
, specimenFacade
.getType());
469 Assert
.assertEquals("DerivedUnit recordBasis must be set to Fossil", newType
, specimenFacade
.innerDerivedUnit().getRecordBasis());
474 public void testGetSetCountry() {
475 Assert
.assertEquals("Country must be same", country
, specimenFacade
.getCountry());
476 specimenFacade
.setCountry(Country
.FRANCEFRENCHREPUBLIC());
477 Assert
.assertEquals("New country must be France", Country
.FRANCEFRENCHREPUBLIC(), specimenFacade
.getCountry());
482 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
486 public void testAddGetRemoveCollectingArea() {
487 String tdwgLabel
= "GER";
488 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
489 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area",
491 specimenFacade
.addCollectingArea(newCollectingArea
);
492 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
493 .getCollectingAreas().size());
494 Assert
.assertSame("Areas should be same", newCollectingArea
,
495 specimenFacade
.innerFieldUnit().getGatheringEvent()
496 .getCollectingAreas().iterator().next());
497 specimenFacade
.addCollectingArea(tdwgArea
);
498 Assert
.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
499 .getCollectingAreas().size());
500 specimenFacade
.removeCollectingArea(newCollectingArea
);
501 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
502 .getCollectingAreas().size());
503 NamedArea remainingArea
= specimenFacade
.getCollectingAreas()
505 Assert
.assertEquals("Areas should be same", tdwgArea
, remainingArea
);
506 specimenFacade
.removeCollectingArea(tdwgArea
);
507 Assert
.assertEquals("No area should remain", 0, specimenFacade
508 .getCollectingAreas().size());
513 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
517 public void testAddCollectingAreas() {
518 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
519 Assert
.assertEquals("No area must exist", 0, specimenFacade
.getCollectingAreas().size());
520 specimenFacade
.addCollectingArea(firstArea
);
521 Assert
.assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
523 String tdwgLabel
= "GER";
524 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
525 NamedArea secondArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
527 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
528 areaCollection
.add(secondArea
);
529 areaCollection
.add(tdwgArea
);
530 specimenFacade
.addCollectingAreas(areaCollection
);
531 Assert
.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
532 .getCollectingAreas().size());
537 * Test method for getting and setting absolute elevation.
538 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
542 public void testGetSetAbsoluteElevation() {
543 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
544 specimenFacade
.setAbsoluteElevation(400);
545 Assert
.assertEquals("Absolute elevation must be 400",Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
550 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
554 public void testGetSetAbsoluteElevationMaximum() {
555 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
556 Assert
.assertEquals("Absolute elevation maximum must be same",absoluteElevationMaximum
, specimenFacade
.getAbsoluteElevationMaximum());
557 specimenFacade
.setAbsoluteElevationMax(4);
558 Assert
.assertEquals("Absolute elevation maximum must be 4", Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationMaximum());
559 Assert
.assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
564 public void testGetSetAbsoluteElevationRange() {
565 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
566 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
568 specimenFacade
.setAbsoluteElevationRange(30, 36);
569 Assert
.assertEquals("", Integer
.valueOf(36),specimenFacade
.getAbsoluteElevationMaximum());
570 Assert
.assertEquals("", Integer
.valueOf(30),specimenFacade
.getAbsoluteElevation());
571 Assert
.assertEquals("", "30" + UTF8
.EN_DASH_SPATIUM
+ "36 m",specimenFacade
.absoluteElevationToString());
572 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
574 specimenFacade
.setAbsoluteElevationRange(30, 35);
575 Assert
.assertEquals("Odd range should not throw an exception anymore",
576 String
.format("30%s35 m", UTF8
.EN_DASH_SPATIUM
),specimenFacade
.absoluteElevationToString());
578 specimenFacade
.setAbsoluteElevationRange(41, null);
579 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
580 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
581 Assert
.assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
582 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationText());
583 Assert
.assertEquals("", "41 m",specimenFacade
.absoluteElevationToString());
585 specimenFacade
.setAbsoluteElevationRange(null, null);
586 Assert
.assertNull("", specimenFacade
.getAbsoluteElevation());
587 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationMaximum());
588 Assert
.assertNull("", specimenFacade
.absoluteElevationToString());
593 public void testGetSetAbsoluteElevationText() {
594 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
595 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
596 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
598 String elevText
= "approx. 30 - 35";
599 specimenFacade
.setAbsoluteElevationText(elevText
);
600 Assert
.assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
601 Assert
.assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
602 Assert
.assertEquals("", elevText
,specimenFacade
.absoluteElevationToString());
604 specimenFacade
.setAbsoluteElevationRange(30, 35);
605 Assert
.assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
606 Assert
.assertEquals("", Integer
.valueOf(30), specimenFacade
.getAbsoluteElevation());
607 Assert
.assertEquals("", Integer
.valueOf(35),specimenFacade
.getAbsoluteElevationMaximum());
610 specimenFacade
.setAbsoluteElevationRange(41, null);
611 Assert
.assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
612 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
613 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
616 specimenFacade
.setAbsoluteElevationText(null);
617 Assert
.assertNull("", specimenFacade
.getAbsoluteElevationText());
618 Assert
.assertEquals("ToString should change by setting text to null", "41 m",specimenFacade
.absoluteElevationToString());
619 Assert
.assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
620 Assert
.assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
627 public void testGetSetCollector() {
628 Assert
.assertNotNull("Collector must not be null",
629 specimenFacade
.getCollector());
630 Assert
.assertEquals("Collector must be same", collector
,
631 specimenFacade
.getCollector());
632 specimenFacade
.setCollector(null);
633 Assert
.assertNull("Collector must be null",
634 specimenFacade
.getCollector());
639 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
643 public void testGetSetCollectingMethod() {
644 Assert
.assertEquals("Collecting method must be same", collectingMethod
,
645 specimenFacade
.getCollectingMethod());
646 specimenFacade
.setCollectingMethod("new method");
647 Assert
.assertEquals("Collecting method must be 'new method'",
648 "new method", specimenFacade
.getCollectingMethod());
653 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
657 public void testGetSetDistanceToGround() {
658 Assert
.assertEquals("Distance to ground must be same",distanceToGround
, specimenFacade
.getDistanceToGround());
659 specimenFacade
.setDistanceToGround(5.0);
660 Assert
.assertEquals("Distance to ground must be 5", Double
.valueOf(5), specimenFacade
.getDistanceToGround());
665 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
669 public void testGetDistanceToWaterSurface() {
670 Assert
.assertEquals("Distance to surface must be same", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
671 specimenFacade
.setDistanceToWaterSurface(6.0);
672 Assert
.assertEquals("Distance to surface must be 6", Double
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
673 // empty facade tests
674 Assert
.assertNull("Empty facace must not have any gathering values", emptyFacade
.getDistanceToWaterSurface());
675 emptyFacade
.setDistanceToWaterSurface(13.0);
676 Assert
.assertNotNull("Field unit must exist if distance to water exists", emptyFacade
.getFieldUnit(false));
677 Assert
.assertNotNull("Gathering event must exist if distance to water exists", emptyFacade
.getGatheringEvent(false));
678 FieldUnit specimenFieldUnit
= (FieldUnit
) emptyFacade
679 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
680 Assert
.assertSame("Gathering event of facade and of specimen must be the same",
681 specimenFieldUnit
.getGatheringEvent(), emptyFacade
.getGatheringEvent(false));
685 public void testGetSetDistanceToWaterText() {
686 Assert
.assertEquals("", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
687 Assert
.assertEquals("", distanceToSurfaceMax
,specimenFacade
.getDistanceToWaterSurfaceMax());
688 Assert
.assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceText());
690 String distText
= "approx. 0.3 - 0.6";
691 specimenFacade
.setDistanceToWaterSurfaceText(distText
);
692 Assert
.assertEquals("", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
693 Assert
.assertEquals("", distanceToSurfaceMax
,specimenFacade
.getDistanceToWaterSurfaceMax());
694 Assert
.assertEquals("", distText
,specimenFacade
.distanceToWaterSurfaceToString());
696 specimenFacade
.setDistanceToWaterSurfaceRange(0.6, 1.4);
697 Assert
.assertEquals("ToString should not change by setting range if text is set", distText
,specimenFacade
.distanceToWaterSurfaceToString());
698 Assert
.assertEquals("", Double
.valueOf(0.6), specimenFacade
.getDistanceToWaterSurface());
699 Assert
.assertEquals("", Double
.valueOf(1.4),specimenFacade
.getDistanceToWaterSurfaceMax());
701 specimenFacade
.setDistanceToWaterSurfaceRange(41.2, null);
702 Assert
.assertEquals("ToString should not change by setting range if text is set", distText
,specimenFacade
.distanceToWaterSurfaceToString());
703 Assert
.assertEquals("", Double
.valueOf(41.2), specimenFacade
.getDistanceToWaterSurface());
704 Assert
.assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceMax());
706 specimenFacade
.setDistanceToWaterSurfaceText(null);
707 Assert
.assertNull("", specimenFacade
.getDistanceToWaterSurfaceText());
708 Assert
.assertEquals("ToString should change by setting text to null", "41.2 m",specimenFacade
.distanceToWaterSurfaceToString());
709 Assert
.assertEquals("", Double
.valueOf(41.2), specimenFacade
.getDistanceToWaterSurface());
710 Assert
.assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceMax());
716 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
719 public void testGetSetExactLocation() {
720 Assert
.assertNotNull("Exact location must not be null",
721 specimenFacade
.getExactLocation());
722 Assert
.assertEquals("Exact location must be same", exactLocation
,
723 specimenFacade
.getExactLocation());
724 specimenFacade
.setExactLocation(null);
725 Assert
.assertNull("Exact location must be null",
726 specimenFacade
.getExactLocation());
730 public void testSetExactLocationByParsing() {
733 specimenFacade
.setExactLocationByParsing("112\u00B034'20\"W",
734 "34\u00B030,34'N", null, null);
735 point1
= specimenFacade
.getExactLocation();
736 Assert
.assertNotNull("", point1
.getLatitude());
737 System
.out
.println(point1
.getLatitude().toString());
738 Assert
.assertTrue("",
739 point1
.getLatitude().toString().startsWith("34.505"));
740 System
.out
.println(point1
.getLongitude().toString());
741 Assert
.assertTrue("",
742 point1
.getLongitude().toString().startsWith("-112.5722"));
744 } catch (ParseException e
) {
745 Assert
.fail("No parsing error should occur");
751 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
755 public void testGetSetGatheringEventDescription() {
756 Assert
.assertEquals("Gathering event description must be same",
757 gatheringEventDescription
,
758 specimenFacade
.getGatheringEventDescription());
759 specimenFacade
.setGatheringEventDescription("new description");
761 "Gathering event description must be 'new description' now",
763 specimenFacade
.getGatheringEventDescription());
768 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
771 public void testGetTimeperiod() {
772 Assert
.assertNotNull("Gathering period must not be null", specimenFacade
.getGatheringPeriod());
773 Assert
.assertFalse("Gathering period must not be empty", specimenFacade
.getGatheringPeriod().isEmpty());
774 Assert
.assertEquals("Gathering period must be same", gatheringPeriod
, specimenFacade
.getGatheringPeriod());
775 specimenFacade
.setGatheringPeriod(null);
776 Assert
.assertTrue("Gathering period must be null", specimenFacade
.getGatheringPeriod().isEmpty());
780 public void testHasFieldObject() throws SecurityException
,
781 NoSuchFieldException
, IllegalArgumentException
,
782 IllegalAccessException
{
783 // this test depends on the current implementation of SpecimenFacade. In
785 // field unit may not be initialized from the beginning. Than the
787 // assert should be set to assertNull
788 Assert
.assertTrue("field object should not be null (depends on specimen facade initialization !!)",
789 specimenFacade
.hasFieldObject());
791 Field fieldUnitField
= DerivedUnitFacade
.class.getDeclaredField("fieldUnit");
792 fieldUnitField
.setAccessible(true);
793 fieldUnitField
.set(specimenFacade
, null);
794 Assert
.assertFalse("The field unit should be null now",
795 specimenFacade
.hasFieldObject());
797 specimenFacade
.setDistanceToGround(33.0);
799 "The field unit should have been created again",
800 specimenFacade
.hasFieldObject());
805 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
809 public void testAddGetRemoveFieldObjectDefinition() {
810 Assert
.assertEquals("There should be no definition yet", 0,
811 specimenFacade
.getFieldObjectDefinition().size());
812 specimenFacade
.addFieldObjectDefinition("Tres interesant",
814 Assert
.assertEquals("There should be exactly one definition", 1,
815 specimenFacade
.getFieldObjectDefinition().size());
817 "The French definition should be 'Tres interesant'",
818 "Tres interesant", specimenFacade
.getFieldObjectDefinition()
819 .get(Language
.FRENCH()).getText());
821 "The French definition should be 'Tres interesant'",
823 specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
824 specimenFacade
.addFieldObjectDefinition("Sehr interessant",
826 Assert
.assertEquals("There should be exactly 2 definition", 2,
827 specimenFacade
.getFieldObjectDefinition().size());
828 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
829 Assert
.assertEquals("There should remain exactly 1 definition", 1,
830 specimenFacade
.getFieldObjectDefinition().size());
832 "The remaining German definition should be 'Sehr interessant'",
834 specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
835 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
836 Assert
.assertEquals("There should remain no definition", 0,
837 specimenFacade
.getFieldObjectDefinition().size());
842 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
846 public void testAddGetHasRemoveFieldObjectMedia() {
847 Assert
.assertFalse("There should be no image gallery yet",
848 specimenFacade
.hasFieldObjectImageGallery());
849 Assert
.assertFalse("There should be no specimen image gallery either",
850 specimenFacade
.hasDerivedUnitImageGallery());
852 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
853 Assert
.assertFalse("There should still not be an image gallery now",
854 specimenFacade
.hasFieldObjectImageGallery());
855 Assert
.assertEquals("There should be no media yet in the gallery", 0,
858 Media media1
= Media
.NewInstance();
859 specimenFacade
.addFieldObjectMedia(media1
);
860 Assert
.assertEquals("There should be exactly one specimen media", 1,
861 specimenFacade
.getFieldObjectMedia().size());
862 Assert
.assertEquals("The only media should be media 1", media1
,
863 specimenFacade
.getFieldObjectMedia().get(0));
865 "There should still no specimen image gallery exist",
866 specimenFacade
.hasDerivedUnitImageGallery());
868 Media media2
= Media
.NewInstance();
869 specimenFacade
.addFieldObjectMedia(media2
);
870 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
871 specimenFacade
.getFieldObjectMedia().size());
872 Assert
.assertEquals("The first media should be media1", media1
,
873 specimenFacade
.getFieldObjectMedia().get(0));
874 Assert
.assertEquals("The second media should be media2", media2
,
875 specimenFacade
.getFieldObjectMedia().get(1));
877 specimenFacade
.removeFieldObjectMedia(media1
);
878 Assert
.assertEquals("There should be exactly one specimen media", 1,
879 specimenFacade
.getFieldObjectMedia().size());
880 Assert
.assertEquals("The only media should be media2", media2
,
881 specimenFacade
.getFieldObjectMedia().get(0));
883 specimenFacade
.removeFieldObjectMedia(media1
);
884 Assert
.assertEquals("There should still be exactly one specimen media",
885 1, specimenFacade
.getFieldObjectMedia().size());
887 specimenFacade
.removeFieldObjectMedia(media2
);
888 Assert
.assertEquals("There should remain no media in the gallery", 0,
895 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
899 public void testGetSetEcology() {
900 Assert
.assertNotNull(
901 "An empty ecology data should be created when calling getEcology()",
902 specimenFacade
.getEcologyAll());
904 "An empty ecology data should be created when calling getEcology()",
905 0, specimenFacade
.getEcologyAll().size());
906 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
907 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
908 specimenFacade
.getEcologyAll().size());
910 "Ecology data should be 'Tres jolie ici' for French",
911 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
913 "Ecology data should be null for the default language",
914 specimenFacade
.getEcology());
915 specimenFacade
.setEcology("Nice here");
916 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
917 specimenFacade
.getEcologyAll().size());
918 Assert
.assertEquals("Ecology data should be 'Tres jolie ici'",
919 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
921 "Ecology data should be 'Nice here' for the default language",
922 "Nice here", specimenFacade
.getEcology());
923 Assert
.assertEquals("Ecology data should be 'Nice here' for english",
924 "Nice here", specimenFacade
.getEcology());
926 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
927 Assert
.assertEquals("Ecology data should exist for 2 languages", 2,
928 specimenFacade
.getEcologyAll().size());
929 Assert
.assertEquals("Ecology data should be 'Vert et rouge'",
930 "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
932 "Ecology data should be 'Nice here' for the default language",
933 "Nice here", specimenFacade
.getEcology());
935 specimenFacade
.setEcology(null, Language
.FRENCH());
936 Assert
.assertEquals("Ecology data should exist for 1 languages", 1,
937 specimenFacade
.getEcologyAll().size());
939 "Ecology data should be 'Nice here' for the default language",
940 "Nice here", specimenFacade
.getEcology());
941 Assert
.assertNull("Ecology data should be 'null' for French",
942 specimenFacade
.getEcology(Language
.FRENCH()));
944 specimenFacade
.removeEcology(null);
945 Assert
.assertEquals("There should be no ecology left", 0,
946 specimenFacade
.getEcologyAll().size());
947 Assert
.assertNull("Ecology data should be 'null' for default language",
948 specimenFacade
.getEcology());
954 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
958 public void testGetSetPlantDescription() {
959 Assert
.assertNotNull(
960 "An empty plant description data should be created when calling getPlantDescriptionAll()",
961 specimenFacade
.getPlantDescriptionAll());
963 "An empty plant description data should be created when calling getPlantDescription()",
964 0, specimenFacade
.getPlantDescriptionAll().size());
965 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
967 "Plant description data should exist for 1 language", 1,
968 specimenFacade
.getPlantDescriptionAll().size());
970 "Plant description data should be 'bleu' for French", "bleu",
971 specimenFacade
.getPlantDescription(Language
.FRENCH()));
973 "Plant description data should be null for the default language",
974 specimenFacade
.getPlantDescription());
975 specimenFacade
.setPlantDescription("Nice here");
977 "Plant description data should exist for 2 languages", 2,
978 specimenFacade
.getPlantDescriptionAll().size());
979 Assert
.assertEquals("Plant description data should be 'bleu'", "bleu",
980 specimenFacade
.getPlantDescription(Language
.FRENCH()));
982 "Plant description data should be 'Nice here' for the default language",
983 "Nice here", specimenFacade
.getPlantDescription());
985 "Plant description data should be 'Nice here' for english",
986 "Nice here", specimenFacade
.getPlantDescription());
988 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
990 "Plant description data should exist for 2 languages", 2,
991 specimenFacade
.getPlantDescriptionAll().size());
992 Assert
.assertEquals("Plant description data should be 'Vert et rouge'",
994 specimenFacade
.getPlantDescription(Language
.FRENCH()));
996 "Plant description data should be 'Nice here' for the default language",
997 "Nice here", specimenFacade
.getPlantDescription());
999 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
1000 Assert
.assertEquals(
1001 "Plant description data should exist for 1 languages", 1,
1002 specimenFacade
.getPlantDescriptionAll().size());
1003 Assert
.assertEquals(
1004 "Plant description data should be 'Nice here' for the default language",
1005 "Nice here", specimenFacade
.getPlantDescription());
1006 Assert
.assertNull("Plant description data should be 'null' for French",
1007 specimenFacade
.getPlantDescription(Language
.FRENCH()));
1009 // test interference with ecology
1010 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
1011 Assert
.assertEquals("Ecology data should exist for 1 language", 1,
1012 specimenFacade
.getEcologyAll().size());
1013 Assert
.assertEquals(
1014 "Ecology data should be 'Tres jolie ici' for French",
1015 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
1017 "Ecology data should be null for the default language",
1018 specimenFacade
.getEcology());
1020 // repeat above test
1021 Assert
.assertEquals(
1022 "Plant description data should exist for 1 languages", 1,
1023 specimenFacade
.getPlantDescriptionAll().size());
1024 Assert
.assertEquals(
1025 "Plant description data should be 'Nice here' for the default language",
1026 "Nice here", specimenFacade
.getPlantDescription());
1027 Assert
.assertNull("Plant description data should be 'null' for French",
1028 specimenFacade
.getPlantDescription(Language
.FRENCH()));
1030 specimenFacade
.removePlantDescription(null);
1031 Assert
.assertEquals("There should be no plant description left", 0,
1032 specimenFacade
.getPlantDescriptionAll().size());
1034 "Plant description data should be 'null' for default language",
1035 specimenFacade
.getPlantDescription());
1041 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
1044 public void testGetSetFieldNumber() {
1045 Assert
.assertEquals("Field number must be same", fieldNumber
,
1046 specimenFacade
.getFieldNumber());
1047 specimenFacade
.setFieldNumber("564AB");
1048 Assert
.assertEquals("New field number must be '564AB'", "564AB",
1049 specimenFacade
.getFieldNumber());
1050 // empty facade tests
1051 Assert
.assertNull("Empty facace must not have any field value",
1052 emptyFacade
.getFieldNumber());
1053 emptyFacade
.setFieldNumber("1256A");
1054 Assert
.assertNotNull(
1055 "Field unit must exist if field number exists",
1056 emptyFacade
.getFieldUnit(false));
1057 FieldUnit specimenFieldUnit
= (FieldUnit
) emptyFacade
1058 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
1061 "Field unit of facade and of specimen must be the same",
1063 emptyFacade
.getFieldUnit(false));
1064 Assert
.assertEquals("1256A", emptyFacade
.getFieldNumber());
1069 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
1072 public void testGetSetFieldNotes() {
1073 Assert
.assertEquals("Field notes must be same", fieldNotes
,
1074 specimenFacade
.getFieldNotes());
1075 specimenFacade
.setFieldNotes("A completely new info");
1076 Assert
.assertEquals("New field note must be 'A completely new info'",
1077 "A completely new info", specimenFacade
.getFieldNotes());
1082 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1086 @Ignore // #######DerivationEvent ---------------------------------------- 1
1087 public void testSetGatheringEvent() {
1088 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1089 newGatheringEvent
.setDistanceToGround(43.0);
1090 Assert
.assertFalse("The initial distance to ground should not be 43",
1091 specimenFacade
.getDistanceToGround() == 43.0);
1092 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1093 Assert
.assertTrue("The final distance to ground should be 43",
1094 specimenFacade
.getDistanceToGround() == 43.0);
1096 "The new gathering event should be 'newGatheringEvent'",
1097 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1102 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1106 public void testGetGatheringEvent() {
1107 Assert
.assertNotNull("Gathering event must not be null",
1108 specimenFacade
.innerGatheringEvent());
1109 Assert
.assertEquals(
1110 "Gathering event must be field unit's gathering event",
1111 specimenFacade
.innerFieldUnit().getGatheringEvent(),
1112 specimenFacade
.innerGatheringEvent());
1117 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1121 public void testGetSetIndividualCount() {
1122 Assert
.assertEquals("Individual count must be same", individualCount
,
1123 specimenFacade
.getIndividualCount());
1124 specimenFacade
.setIndividualCount(4);
1125 Assert
.assertEquals("New individual count must be '4'",
1126 Integer
.valueOf(4), specimenFacade
.getIndividualCount());
1132 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1135 public void testGetSetLifeStage() {
1136 Assert
.assertNotNull("Life stage must not be null",
1137 specimenFacade
.getLifeStage());
1138 Assert
.assertEquals("Life stage must be same", lifeStage
,
1139 specimenFacade
.getLifeStage());
1140 specimenFacade
.setLifeStage(null);
1141 Assert
.assertNull("Life stage must be null",
1142 specimenFacade
.getLifeStage());
1147 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1150 public void testGetSetSex() {
1151 Assert
.assertNotNull("Sex must not be null", specimenFacade
.getSex());
1152 Assert
.assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1153 specimenFacade
.setSex(null);
1154 Assert
.assertNull("Sex must be null", specimenFacade
.getSex());
1159 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1162 public void testGetSetLocality() {
1163 Assert
.assertEquals("Locality must be same", locality
,
1164 specimenFacade
.getLocality());
1165 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1166 Assert
.assertEquals("New locality must be 'A completely new place'",
1167 "A completely new place", specimenFacade
.getLocalityText());
1168 Assert
.assertEquals("New locality language must be French",
1169 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1170 specimenFacade
.setLocality("Another place");
1171 Assert
.assertEquals("New locality must be 'Another place'",
1172 "Another place", specimenFacade
.getLocalityText());
1173 Assert
.assertEquals("New locality language must be default",
1174 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1179 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1183 public void testAddGetRemoveSpecimenDefinition() {
1184 Assert
.assertEquals("There should be no definition yet", 0,
1185 specimenFacade
.getDerivedUnitDefinitions().size());
1186 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1188 Assert
.assertEquals("There should be exactly one definition", 1,
1189 specimenFacade
.getDerivedUnitDefinitions().size());
1190 Assert
.assertEquals(
1191 "The French definition should be 'Tres interesant'",
1192 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1193 .get(Language
.FRENCH()).getText());
1194 Assert
.assertEquals(
1195 "The French definition should be 'Tres interesant'",
1197 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1198 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1200 Assert
.assertEquals("There should be exactly 2 definition", 2,
1201 specimenFacade
.getDerivedUnitDefinitions().size());
1202 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1203 Assert
.assertEquals("There should remain exactly 1 definition", 1,
1204 specimenFacade
.getDerivedUnitDefinitions().size());
1205 Assert
.assertEquals(
1206 "The remaining German definition should be 'Sehr interessant'",
1208 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1209 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1210 Assert
.assertEquals("There should remain no definition", 0,
1211 specimenFacade
.getDerivedUnitDefinitions().size());
1216 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1220 public void testAddGetRemoveDetermination() {
1221 Assert
.assertEquals("There should be no determination yet", 0,
1222 specimenFacade
.getDeterminations().size());
1223 DeterminationEvent determinationEvent1
= DeterminationEvent
1225 specimenFacade
.addDetermination(determinationEvent1
);
1226 Assert
.assertEquals("There should be exactly one determination", 1,
1227 specimenFacade
.getDeterminations().size());
1228 Assert
.assertEquals("The only determination should be determination 1",
1229 determinationEvent1
, specimenFacade
.getDeterminations()
1230 .iterator().next());
1232 DeterminationEvent determinationEvent2
= DeterminationEvent
1234 specimenFacade
.addDetermination(determinationEvent2
);
1235 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1236 specimenFacade
.getDeterminations().size());
1237 specimenFacade
.removeDetermination(determinationEvent1
);
1239 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1240 specimenFacade
.getDeterminations().size());
1241 Assert
.assertEquals(
1242 "The remaining determinations should be determination 2",
1243 determinationEvent2
, specimenFacade
.getDeterminations()
1244 .iterator().next());
1246 specimenFacade
.removeDetermination(determinationEvent1
);
1247 Assert
.assertEquals("There should remain exactly 1 determination", 1,
1248 specimenFacade
.getDeterminations().size());
1250 specimenFacade
.removeDetermination(determinationEvent2
);
1251 Assert
.assertEquals("There should remain no definition", 0,
1252 specimenFacade
.getDerivedUnitDefinitions().size());
1259 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1263 public void testPreferredOtherDeterminations() {
1264 Assert
.assertEquals("There should be no determination yet", 0,
1265 specimenFacade
.getDeterminations().size());
1266 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1267 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1269 Assert
.assertEquals("There should be exactly one determination", 1,
1270 specimenFacade
.getDeterminations().size());
1271 Assert
.assertEquals("The only determination should be determination 1",
1272 determinationEvent1
, specimenFacade
.getDeterminations()
1273 .iterator().next());
1274 Assert
.assertEquals("determination 1 should be the preferred determination",
1275 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1276 Assert
.assertEquals("There should be no 'non preferred' determination", 0,
1277 specimenFacade
.getOtherDeterminations().size());
1281 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1282 specimenFacade
.addDetermination(determinationEvent2
);
1283 Assert
.assertEquals("There should be exactly 2 determinations", 2,
1284 specimenFacade
.getDeterminations().size());
1285 Assert
.assertEquals("determination 1 should be the preferred determination",
1286 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1287 Assert
.assertEquals("There should be one 'non preferred' determination", 1,
1288 specimenFacade
.getOtherDeterminations().size());
1289 Assert
.assertEquals("The only 'non preferred' determination should be determination 2",
1290 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1293 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1294 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1295 Assert
.assertEquals("There should be exactly 3 determinations", 3,
1296 specimenFacade
.getDeterminations().size());
1297 Assert
.assertEquals("determination 3 should be the preferred determination",
1298 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1299 Assert
.assertEquals("There should be 2 'non preferred' determination", 2,
1300 specimenFacade
.getOtherDeterminations().size());
1301 Assert
.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1302 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1303 Assert
.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1304 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1310 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1314 public void testAddGetHasRemoveSpecimenMedia() {
1315 Assert
.assertFalse("There should be no image gallery yet",
1316 specimenFacade
.hasDerivedUnitImageGallery());
1318 "There should be also no field object image gallery yet",
1319 specimenFacade
.hasFieldObjectImageGallery());
1321 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1323 "There should still not be an empty image gallery now",
1324 specimenFacade
.hasDerivedUnitImageGallery());
1325 Assert
.assertEquals("There should be no media yet in the gallery", 0,
1328 Media media1
= Media
.NewInstance();
1329 specimenFacade
.addDerivedUnitMedia(media1
);
1330 Assert
.assertEquals("There should be exactly one specimen media", 1,
1331 specimenFacade
.getDerivedUnitMedia().size());
1332 Assert
.assertEquals("The only media should be media 1", media1
,
1333 specimenFacade
.getDerivedUnitMedia().get(0));
1335 "There should be still no field object image gallery",
1336 specimenFacade
.hasFieldObjectImageGallery());
1338 Media media2
= Media
.NewInstance();
1339 specimenFacade
.addDerivedUnitMedia(media2
);
1340 Assert
.assertEquals("There should be exactly 2 specimen media", 2,
1341 specimenFacade
.getDerivedUnitMedia().size());
1342 Assert
.assertEquals("The first media should be media1", media1
,
1343 specimenFacade
.getDerivedUnitMedia().get(0));
1344 Assert
.assertEquals("The second media should be media2", media2
,
1345 specimenFacade
.getDerivedUnitMedia().get(1));
1347 specimenFacade
.removeDerivedUnitMedia(media1
);
1348 Assert
.assertEquals("There should be exactly one specimen media", 1,
1349 specimenFacade
.getDerivedUnitMedia().size());
1350 Assert
.assertEquals("The only media should be media2", media2
,
1351 specimenFacade
.getDerivedUnitMedia().get(0));
1353 specimenFacade
.removeDerivedUnitMedia(media1
);
1354 Assert
.assertEquals("There should still be exactly one specimen media",
1355 1, specimenFacade
.getDerivedUnitMedia().size());
1357 specimenFacade
.removeDerivedUnitMedia(media2
);
1358 Assert
.assertEquals("There should remain no media in the gallery", 0,
1364 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1368 public void testGetSetAccessionNumber() {
1369 Assert
.assertEquals("Accession number must be same", accessionNumber
,
1370 specimenFacade
.getAccessionNumber());
1371 specimenFacade
.setAccessionNumber("A12345693");
1372 Assert
.assertEquals("New accession number must be 'A12345693'",
1373 "A12345693", specimenFacade
.getAccessionNumber());
1379 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1382 public void testGetCatalogNumber() {
1383 Assert
.assertEquals("Catalog number must be same", catalogNumber
,
1384 specimenFacade
.getCatalogNumber());
1385 specimenFacade
.setCatalogNumber("B12345693");
1386 Assert
.assertEquals("New catalog number must be 'B12345693'",
1387 "B12345693", specimenFacade
.getCatalogNumber());
1392 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1395 public void testGetPreservation() {
1397 Assert
.assertNotNull("Preservation method must not be null",
1398 specimenFacade
.getPreservationMethod());
1399 Assert
.assertEquals("Preservation method must be same",
1400 preservationMethod
, specimenFacade
.getPreservationMethod());
1401 specimenFacade
.setPreservationMethod(null);
1402 Assert
.assertNull("Preservation method must be null",
1403 specimenFacade
.getPreservationMethod());
1404 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1405 Assert
.fail("Method not supported should not be thrown for a specimen");
1407 specimenFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.Observation
);
1409 specimenFacade
.setPreservationMethod(preservationMethod
);
1410 Assert
.fail("Method not supported should be thrown for an observation on set preservation method");
1412 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1415 specimenFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.LivingSpecimen
);
1417 specimenFacade
.getPreservationMethod();
1418 Assert
.fail("Method not supported should be thrown for a living being on get preservation method");
1419 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1426 public void testGetSetOriginalLabelInfo() {
1427 Assert
.assertEquals("Original label info must be same", originalLabelInfo
,
1428 specimenFacade
.getOriginalLabelInfo());
1429 specimenFacade
.setOriginalLabelInfo("OrigLabel Info xxx");
1430 Assert
.assertEquals("New accession number must be 'OrigLabel Info xxx'",
1431 "OrigLabel Info xxx", specimenFacade
.getOriginalLabelInfo());
1435 public void testGetSetStableUri() {
1436 Assert
.assertEquals("Preferred stable URI must be same", stableUri
,
1437 specimenFacade
.getPreferredStableUri());
1438 URI newURI
= URI
.create("http://www.fgh.ij");
1439 specimenFacade
.setPreferredStableUri(newURI
);
1440 Assert
.assertEquals("New preferred stable must be '" + newURI
.toString() + "'",
1441 newURI
, specimenFacade
.getPreferredStableUri());
1448 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1451 public void testGetStoredUnder() {
1452 Assert
.assertNotNull("Stored under name must not be null",
1453 specimenFacade
.getStoredUnder());
1454 Assert
.assertEquals("Stored under name must be same", taxonName
,
1455 specimenFacade
.getStoredUnder());
1456 specimenFacade
.setStoredUnder(null);
1457 Assert
.assertNull("Stored under name must be null",
1458 specimenFacade
.getStoredUnder());
1462 // * Test method for
1463 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1467 // public void testGetSetCollectorsNumber() {
1468 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1469 // specimenFacade.getCollectorsNumber());
1470 // specimenFacade.setCollectorsNumber("C12345693");
1471 // Assert.assertEquals("New collectors number must be 'C12345693'",
1472 // "C12345693", specimenFacade.getCollectorsNumber());
1477 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1480 public void testGetTitleCache() {
1481 Assert
.assertNotNull(
1482 "The title cache should never return null if not protected",
1483 specimenFacade
.getTitleCache());
1484 specimenFacade
.setTitleCache(null, false);
1485 Assert
.assertNotNull(
1486 "The title cache should never return null if not protected",
1487 specimenFacade
.getTitleCache());
1492 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1496 public void testSetTitleCache() {
1497 String testTitle
= "Absdwk aksjlf";
1498 specimenFacade
.setTitleCache(testTitle
, true);
1499 Assert
.assertEquals(
1500 "Protected title cache should returns the test title",
1501 testTitle
, specimenFacade
.getTitleCache());
1502 specimenFacade
.setTitleCache(testTitle
, false);
1504 "Unprotected title cache should not return the test title",
1505 testTitle
.equals(specimenFacade
.getTitleCache()));
1510 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1513 public void testGetSpecimen() {
1514 Assert
.assertEquals("Specimen must be same", specimen
,
1515 specimenFacade
.innerDerivedUnit());
1520 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1523 public void testGetSetCollection() {
1524 Assert
.assertNotNull("Collection must not be null",
1525 specimenFacade
.getCollection());
1526 Assert
.assertEquals("Collection must be same", collection
,
1527 specimenFacade
.getCollection());
1528 specimenFacade
.setCollection(null);
1529 Assert
.assertNull("Collection must be null",
1530 specimenFacade
.getCollection());
1534 public void testAddGetRemoveSource() {
1535 Assert
.assertEquals("No sources should exist yet", 0, specimenFacade
.getSources().size());
1537 Reference
<?
> reference
= ReferenceFactory
.newBook();
1538 IdentifiableSource source1
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference
, "54", "myName");
1539 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1540 IdentifiableSource source2
= IdentifiableSource
.NewDataImportInstance("1", "myTable");
1541 specimenFacade
.addSource(source2
);
1542 Assert
.assertEquals("One source should exist now", 2, specimenFacade
.getSources().size());
1543 specimenFacade
.removeSource(source1
);
1544 Assert
.assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1545 Reference
<?
> reference2
= ReferenceFactory
.newJournal();
1546 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference2
,null, null);
1547 specimenFacade
.removeSource(sourceNotUsed
);
1548 Assert
.assertEquals("One source should still exist", 1, specimenFacade
.getSources().size());
1549 Assert
.assertEquals("1", specimenFacade
.getSources().iterator().next().getIdInSource());
1550 specimenFacade
.removeSource(source2
);
1551 Assert
.assertEquals("No sources should exist anymore", 0,specimenFacade
.getSources().size());
1555 public void testAddGetRemoveDuplicate() {
1556 Assert
.assertEquals("No duplicates should be available yet", 0,specimenFacade
.getDuplicates().size());
1557 DerivedUnit newSpecimen1
= DerivedUnit
.NewPreservedSpecimenInstance();
1558 specimenFacade
.addDuplicate(newSpecimen1
);
1559 Assert
.assertEquals("There should be 1 duplicate now", 1,specimenFacade
.getDuplicates().size());
1560 DerivedUnit newSpecimen2
= DerivedUnit
.NewPreservedSpecimenInstance();
1561 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
1562 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1564 "The derivation event should be 'newDerivationEvent'",
1565 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1566 specimenFacade
.addDuplicate(newSpecimen2
);
1567 Assert
.assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
1568 Assert
.assertNotSame(
1569 "The derivation event should not be 'newDerivationEvent' anymore",
1570 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1572 "The derivation event should not be the facades derivation event",
1573 derivationEvent
, newSpecimen2
.getDerivedFrom());
1574 specimenFacade
.removeDuplicate(newSpecimen1
);
1575 Assert
.assertEquals("There should be 1 duplicate now", 1,
1576 specimenFacade
.getDuplicates().size());
1577 Assert
.assertSame("The only duplicate should be 'newSpecimen2' now",
1578 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1579 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1580 Assert
.assertEquals(
1581 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1582 1, specimenFacade
.getDuplicates().size());
1584 Collection newCollection
= Collection
.NewInstance();
1585 String catalogNumber
= "1234890";
1586 String accessionNumber
= "345345";
1587 TaxonNameBase
<?
,?
> storedUnder
= BotanicalName
.NewInstance(Rank
.SPECIES());
1588 PreservationMethod method
= PreservationMethod
.NewInstance();
1589 DerivedUnit duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1590 catalogNumber
, accessionNumber
, storedUnder
,
1592 Assert
.assertEquals("There should be 2 duplicates now", 2,
1593 specimenFacade
.getDuplicates().size());
1594 specimenFacade
.removeDuplicate(newSpecimen2
);
1595 Assert
.assertEquals("There should be 1 duplicates now", 1,
1596 specimenFacade
.getDuplicates().size());
1597 Collection sameCollection
= specimenFacade
.getDuplicates().iterator().next().getCollection();
1598 Assert
.assertSame("Collections should be same", newCollection
, sameCollection
);
1601 // ************************** Existing Specimen with multiple derivation
1602 // events in line **************/
1605 public void testExistingSpecimen() {
1606 specimenFacade
= null;
1608 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1609 } catch (DerivedUnitFacadeNotSupportedException e
) {
1610 Assert
.fail("Multiple derivation events in line should not throw a not supported exception");
1613 "Gathering event should derive from the derivation line",
1614 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1615 Assert
.assertEquals(
1616 "Mediasize should be 0. Only Imagegallery media are supported",
1617 0, specimenFacade
.getFieldObjectMedia().size());
1621 public void testMultipleFieldUnitNotSupported() {
1622 specimenFacade
= null;
1623 FieldUnit secondFieldObject
= FieldUnit
.NewInstance();
1624 firstDerivationEvent
.addOriginal(secondFieldObject
);
1626 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1627 Assert
.fail("Multiple field units for one specimen should no be supported by the facade");
1628 } catch (DerivedUnitFacadeNotSupportedException e
) {
1631 Assert
.assertNull("Specimen facade should not be initialized",
1635 // not required anymore #3597
1636 // @Test // #######DerivationEvent
1637 // public void testOnlyImageGallerySupported() {
1638 // specimenFacade = null;
1639 // firstFieldObject.addMedia(media1);
1641 // specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
1642 // Assert.fail("Only image galleries are supported by the facade but not direct media");
1643 // } catch (DerivedUnitFacadeNotSupportedException e) {
1646 // Assert.assertNull("Specimen facade should not be initialized",
1650 @Test // #######DerivationEvent
1651 public void testEventPropagation() {
1652 specimenFacade
.setDistanceToGround(24.0);
1656 // @Ignore // set to ignore because I did not want to check knowingly
1657 // failing tests. Remove @Ignore when this is fixed
1659 public void testSetBarcode() {
1660 String barcode
= "barcode";
1661 specimenFacade
.setBarcode(barcode
);
1663 Assert
.assertEquals(barcode
, specimenFacade
.getBarcode());
1667 public void testIsEvenDistance() {
1668 Integer minimum
= 20;
1669 Integer maximum
= 1234;
1671 // this should not throw exceptions
1672 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1677 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1678 * This test doesn't handle the above issue yet as it doesn't fire events as
1679 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1680 * In the meanwhile the property change framework for the facade has been changed
1681 * so the original problem may have disappeared.
1685 public void testNoRecursiveChangeEvents(){
1686 String username
= "username";
1687 String password
= "password";
1688 User user
= User
.NewInstance(username
, password
);
1689 userService
.save(user
);
1690 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1691 SecurityContextHolder
.getContext().setAuthentication(token
);
1693 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
1694 facade
.setLocality("testLocality");
1695 facade
.getTitleCache();
1696 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1697 this.service
.save(facade
.innerDerivedUnit());
1698 commitAndStartNewTransaction(null);
1702 public void testBaseUnit() throws DerivedUnitFacadeNotSupportedException
{
1703 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
1704 assertEquals("baseUnit is incorrect", specimen
, facade
.baseUnit());
1706 facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.FieldUnit
, fieldUnit
);
1707 assertEquals("baseUnit is incorrect", fieldUnit
, facade
.baseUnit());
1709 facade
= DerivedUnitFacade
.NewInstance(specimen
);
1710 facade
.getFieldUnit(true);
1711 assertEquals("baseUnit is incorrect", specimen
, facade
.baseUnit());
1715 public void createTestDataSet() throws FileNotFoundException
{
1716 // TODO Auto-generated method stub