2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.facade
;
11 import static org
.junit
.Assert
.assertEquals
;
12 import static org
.junit
.Assert
.assertFalse
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNotSame
;
15 import static org
.junit
.Assert
.assertNull
;
16 import static org
.junit
.Assert
.assertSame
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
20 import java
.io
.FileNotFoundException
;
21 import java
.lang
.reflect
.Field
;
22 import java
.text
.ParseException
;
23 import java
.util
.HashSet
;
24 import java
.util
.List
;
25 import java
.util
.UUID
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.junit
.Before
;
29 import org
.junit
.Ignore
;
30 import org
.junit
.Test
;
31 import org
.springframework
.security
.authentication
.UsernamePasswordAuthenticationToken
;
32 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
33 import org
.unitils
.dbunit
.annotation
.DataSet
;
34 import org
.unitils
.dbunit
.annotation
.DataSets
;
35 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
36 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
38 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
41 import eu
.etaxonomy
.cdm
.common
.URI
;
42 import eu
.etaxonomy
.cdm
.common
.UTF8
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
44 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
45 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
46 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
47 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
48 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
49 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
50 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
52 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
53 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
54 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
55 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
56 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
57 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
58 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
59 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
64 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
65 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
66 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
67 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
68 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
69 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
70 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
71 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
72 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
73 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
74 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
75 import eu
.etaxonomy
.cdm
.test
.unitils
.CleanSweepInsertLoadStrategy
;
78 * Test class for {@link DerivedUnitFacade}
83 public class DerivedUnitFacadeTest
extends CdmTransactionalIntegrationTest
{
84 @SuppressWarnings("unused")
85 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeTest
.class);
89 private IOccurrenceService service
;
92 private ITermService termService
;
95 private IUserService userService
;
99 DerivationEvent derivationEvent
;
101 GatheringEvent gatheringEvent
;
102 Integer absoluteElevation
= 10;
103 Integer absoluteElevationMaximum
= 14;
104 AgentBase
<?
> collector
= Team
.NewInstance();
105 String collectingMethod
= "Collection Method";
106 Double distanceToGround
= 22.0;
107 Double distanceToSurface
= 0.3;
108 Double distanceToSurfaceMax
= 0.7;
110 ReferenceSystem referenceSystem
= ReferenceSystem
.WGS84();
111 Point exactLocation
= Point
.NewInstance(12.3, 10.567, referenceSystem
, 22);
112 String gatheringEventDescription
= "A nice gathering description";
113 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(1888, 1889);
115 String fieldNumber
= "15p23B";
116 String fieldNotes
= "such a beautiful specimen";
118 String individualCount
= "1";
119 DefinedTerm lifeStage
= DefinedTerm
.NewStageInstance("A wonderful stage", "stage", "st");
120 DefinedTerm sex
= DefinedTerm
.NewSexInstance("FemaleMale", "FM", "FM");
121 LanguageString locality
= LanguageString
.NewInstance("My locality",
123 DefinedTerm kindOfUnit
= DefinedTerm
.NewKindOfUnitInstance("Test kind of unit for field unit", "Test kind of unit", "Tkou");
126 String accessionNumber
= "888462535";
127 String catalogNumber
= "UU879873590";
128 TaxonName taxonName
= TaxonNameFactory
.NewBotanicalInstance(Rank
.GENUS(), "Abies",
129 null, null, null, null, null, null, null);
130 String collectorsNumber
= "234589913A34";
131 Collection collection
= Collection
.NewInstance();
132 PreservationMethod preservationMethod
= PreservationMethod
.NewInstance(null, "my prservation");
133 String originalLabelInfo
= "original label info";
134 URI stableUri
= URI
.create("http://www.abc.de");
137 DerivedUnitFacade specimenFacade
;
139 DerivedUnit collectionSpecimen
;
140 GatheringEvent existingGatheringEvent
;
141 DerivationEvent firstDerivationEvent
;
142 FieldUnit firstFieldObject
;
143 Media media1
= Media
.NewInstance();
145 DerivedUnitFacade emptyFacade
;
147 // ****************************** SET UP **********************************/
151 * @throws java.lang.Exception
154 public void setUp() throws Exception
{
156 specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
158 derivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
159 specimen
.setDerivedFrom(derivationEvent
);
160 fieldUnit
= FieldUnit
.NewInstance();
161 fieldUnit
.addDerivationEvent(derivationEvent
);
162 gatheringEvent
= GatheringEvent
.NewInstance();
163 fieldUnit
.setGatheringEvent(gatheringEvent
);
164 gatheringEvent
.setAbsoluteElevation(absoluteElevation
);
165 gatheringEvent
.setAbsoluteElevationMax(absoluteElevationMaximum
);
166 gatheringEvent
.setActor(collector
);
167 gatheringEvent
.setCollectingMethod(collectingMethod
);
168 gatheringEvent
.setDistanceToGround(distanceToGround
);
169 gatheringEvent
.setDistanceToWaterSurface(distanceToSurface
);
170 gatheringEvent
.setDistanceToWaterSurfaceMax(distanceToSurfaceMax
);
171 gatheringEvent
.setExactLocation(exactLocation
);
172 gatheringEvent
.setDescription(gatheringEventDescription
);
173 gatheringEvent
.setCountry(Country
.GERMANY());
175 gatheringEvent
.setTimeperiod(gatheringPeriod
);
176 gatheringEvent
.setLocality(locality
);
178 fieldUnit
.setFieldNumber(fieldNumber
);
179 fieldUnit
.setFieldNotes(fieldNotes
);
180 fieldUnit
.setIndividualCount(individualCount
);
181 fieldUnit
.setSex(sex
);
182 fieldUnit
.setLifeStage(lifeStage
);
183 fieldUnit
.setKindOfUnit(kindOfUnit
);
185 specimen
.setAccessionNumber(accessionNumber
);
186 specimen
.setCatalogNumber(catalogNumber
);
187 specimen
.setStoredUnder(taxonName
);
188 specimen
.setCollection(collection
);
189 specimen
.setPreservation(preservationMethod
);
190 specimen
.setOriginalLabelInfo(originalLabelInfo
);
191 specimen
.setPreferredStableUri(stableUri
);
193 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
195 // existing specimen with 2 derivation events in line
196 collectionSpecimen
= DerivedUnit
.NewPreservedSpecimenInstance();
197 DerivedUnit middleSpecimen
= DerivedUnit
.NewPreservedSpecimenInstance();
198 firstFieldObject
= FieldUnit
.NewInstance();
200 //TODO maybe we should define concrete event types here
201 DerivationEventType eventType
= DerivationEventType
.ACCESSIONING();
202 DerivationEvent lastDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
203 DerivationEvent middleDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
204 firstDerivationEvent
= DerivationEvent
.NewInstance(eventType
);
206 collectionSpecimen
.setDerivedFrom(lastDerivationEvent
);
208 lastDerivationEvent
.addOriginal(middleSpecimen
);
209 middleSpecimen
.setDerivedFrom(firstDerivationEvent
);
210 firstDerivationEvent
.addOriginal(firstFieldObject
);
211 existingGatheringEvent
= GatheringEvent
.NewInstance();
212 firstFieldObject
.setGatheringEvent(existingGatheringEvent
);
215 emptyFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
219 // ****************************** TESTS*****************************/
221 @Ignore //doesn't run in suite
223 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
225 public void testSetFieldObjectImageGallery() {
226 UUID imageFeatureUuid
= Feature
.IMAGE().getUuid();
227 Feature imageFeature
= (Feature
) termService
.find(imageFeatureUuid
);
229 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
230 facade
.innerDerivedUnit().setUuid(UUID
.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));
231 facade
.setFieldNumber("12345");
232 Media media
= Media
.NewInstance(URI
.create("www.abc.de"), 200, null,"jpeg");
235 SpecimenDescription imageGallery
= SpecimenDescription
.NewInstance();
236 imageGallery
.setDescribedSpecimenOrObservation(facade
.innerFieldUnit());
237 imageGallery
.setImageGallery(true);
238 TextData textData
= TextData
.NewInstance();
239 textData
.setFeature(imageFeature
);
240 imageGallery
.addElement(textData
);
241 textData
.addMedia(media
);
242 facade
.setFieldObjectImageGallery(imageGallery
);
244 } catch (DerivedUnitFacadeNotSupportedException e1
) {
245 e1
.printStackTrace();
246 fail(e1
.getLocalizedMessage());
248 this.service
.save(facade
.innerDerivedUnit());
250 setComplete(); endTransaction();
251 // try {if (true){printDataSet(System.out, new
252 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
253 // ,"DERIVATIONEVENT",
254 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
255 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
256 // } catch(Exception e) { logger.warn(e);}
262 // TODO generally works but has id problems when running together with above
263 // test ()setFieldObjectImageGallery. Therefore set to ignore.
264 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
266 public void testSetDerivedUnitImageGallery() {
267 // UUID specimenUUID =
268 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
269 // Specimen specimen = (Specimen)service.find(specimenUUID);
270 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
271 Media media
= Media
.NewInstance(URI
.create("www.derivedUnitImage.de"),200, null, "png");
274 SpecimenDescription imageGallery
= SpecimenDescription
276 imageGallery
.setDescribedSpecimenOrObservation(facade
.innerDerivedUnit());
277 imageGallery
.setImageGallery(true);
278 TextData textData
= TextData
.NewInstance();
279 imageGallery
.addElement(textData
);
280 textData
.addMedia(media
);
281 facade
.setDerivedUnitImageGallery(imageGallery
);
283 } catch (DerivedUnitFacadeNotSupportedException e1
) {
284 e1
.printStackTrace();
285 fail(e1
.getLocalizedMessage());
287 this.service
.save(facade
.innerDerivedUnit());
289 // setComplete(); endTransaction();
290 // try {if (true){printDataSet(System.out, new
291 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
292 // ,"DERIVATIONEVENT",
293 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
294 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
295 // } catch(Exception e) { logger.warn(e);}
302 @Ignore // TODO generally works has id problems with following tests when running in suite
303 public void testGetFieldObjectImageGalleryBooleanPersisted() {
304 UUID specimenUUID
= UUID
.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
305 DerivedUnit specimen
= (DerivedUnit
) service
.load(specimenUUID
);
306 assertNotNull("Specimen should exist (persisted)", specimen
);
308 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
309 SpecimenDescription imageGallery
= facade
.getFieldObjectImageGallery(true);
310 assertNotNull("Image gallery should exist", imageGallery
);
311 assertEquals("UUID should be equal to the persisted uuid",
312 UUID
.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
313 imageGallery
.getUuid());
314 assertEquals("The image gallery should be flagged as such",true, imageGallery
.isImageGallery());
315 assertEquals("There should be one TextData in image gallery", 1,
316 imageGallery
.getElements().size());
317 List
<Media
> media
= imageGallery
.getElements().iterator().next().getMedia();
318 assertEquals("There should be 1 media", 1, media
.size());
319 } catch (DerivedUnitFacadeNotSupportedException e
) {
327 // @Ignore // TODO generally works has id problems with following tests when running in suite
328 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
329 UUID specimenUUID
= UUID
.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
330 DerivedUnit specimen
= (DerivedUnit
) service
.load(specimenUUID
);
331 assertNotNull("Specimen should exist (persisted)", specimen
);
333 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
334 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
335 assertNotNull("Image gallery should exist", imageGallery
);
336 assertEquals("UUID should be equal to the persisted uuid",
337 UUID
.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
338 imageGallery
.getUuid());
339 assertEquals("The image gallery should be flagged as such",
340 true, imageGallery
.isImageGallery());
342 "There should be one TextData in image gallery", 1,
343 imageGallery
.getElements().size());
344 List
<Media
> media
= imageGallery
.getElements().iterator().next().getMedia();
345 assertEquals("There should be 1 media", 1, media
.size());
346 } catch (DerivedUnitFacadeNotSupportedException e
) {
353 public void testGetDerivedUnitImageGalleryBoolean() {
354 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
356 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
357 SpecimenDescription imageGallery
= facade
.getDerivedUnitImageGallery(true);
358 assertNotNull("Image Gallery should have been created",imageGallery
);
359 assertEquals("The image gallery should be flagged as such",true, imageGallery
.isImageGallery());
360 } catch (DerivedUnitFacadeNotSupportedException e
) {
369 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
372 public void testNewInstanceGatheringEventCreated() {
373 assertNotNull("The specimen should have been created",
374 specimenFacade
.innerDerivedUnit());
376 assertNotNull("The derivation event should have been created",
377 specimenFacade
.innerDerivedUnit().getDerivedFrom());
378 assertNotNull("The field unit should have been created",
379 specimenFacade
.innerFieldUnit());
380 assertNotNull("The gathering event should have been created",
381 specimenFacade
.innerGatheringEvent());
389 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
393 public void testNewInstanceSpecimen() {
394 assertSame("Specimen should be same", specimen
,
395 specimenFacade
.innerDerivedUnit());
396 assertSame("Derivation event should be same", derivationEvent
,
397 specimenFacade
.innerDerivedUnit().getDerivedFrom());
398 assertSame("Field unit should be same", fieldUnit
,
399 specimenFacade
.innerFieldUnit());
400 assertSame("Gathering event should be same", gatheringEvent
,
401 specimenFacade
.innerGatheringEvent());
405 public void testNewInstanceSpecimenWithoutFieldUnit() {
406 DerivedUnit parent
= DerivedUnit
.NewPreservedSpecimenInstance();
407 DerivedUnit child
= DerivedUnit
.NewPreservedSpecimenInstance();
408 DerivationEvent
.NewSimpleInstance(parent
, child
, DerivationEventType
.ACCESSIONING());
410 DerivedUnitFacade facade
;
412 facade
= DerivedUnitFacade
.NewInstance(child
);
413 assertTrue(facade
.innerDerivedUnit().getDerivedFrom().getOriginals().size() == 1);
414 assertNull(facade
.getFieldUnit(false));
415 DerivationEvent
.NewSimpleInstance(FieldUnit
.NewInstance(), parent
, DerivationEventType
.ACCESSIONING());
417 } catch (DerivedUnitFacadeNotSupportedException e
) {
425 public void testGatheringEventIsConnectedToDerivedUnit() {
426 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
427 DerivedUnitFacade specimenFacade
;
429 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
430 specimenFacade
.setDistanceToGround(2.0);
431 FieldUnit specimenFieldUnit
= (FieldUnit
) specimen
.getDerivedFrom().getOriginals().iterator().next();
433 "Facade gathering event and specimen gathering event should be the same",
434 specimenFacade
.innerGatheringEvent(),
435 specimenFieldUnit
.getGatheringEvent());
436 } catch (DerivedUnitFacadeNotSupportedException e
) {
437 fail("An error should not occur in NewInstance()");
442 public void testNoGatheringEventAndFieldUnit() {
443 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
444 DerivedUnitFacade specimenFacade
;
446 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
447 assertNull("No field unit should exists",
448 specimenFacade
.innerFieldUnit());
449 } catch (DerivedUnitFacadeNotSupportedException e
) {
450 fail("An error should not occur in NewInstance()");
455 public void testInititializeTextDataWithSupportTest() {
457 DerivedUnit specimen
= DerivedUnit
.NewPreservedSpecimenInstance();
458 DerivedUnitFacade specimenFacade
;
460 specimenFacade
= DerivedUnitFacade
.NewInstance(specimen
);
461 specimenFacade
.setEcology("Ecology");
462 String plantDescription
= specimenFacade
.getPlantDescription();
464 "No plantDescription should exist yet and no NPE should be thrown until now",
466 } catch (DerivedUnitFacadeNotSupportedException e
) {
467 fail("An error should not occur in NewInstance()");
472 public void testGetSetType() {
473 assertEquals("Type must be same", SpecimenOrObservationType
.PreservedSpecimen
, specimenFacade
.getType());
474 SpecimenOrObservationType newType
= SpecimenOrObservationType
.Fossil
;
475 specimenFacade
.setType(newType
);
476 assertEquals("New type must be Fossil", newType
, specimenFacade
.getType());
477 assertEquals("DerivedUnit recordBasis must be set to Fossil", newType
, specimenFacade
.innerDerivedUnit().getRecordBasis());
482 public void testGetSetCountry() {
483 assertEquals("Country must be same", Country
.GERMANY(), specimenFacade
.getCountry());
484 specimenFacade
.setCountry(Country
.FRANCE());
485 assertEquals("New country must be France", Country
.FRANCE(), specimenFacade
.getCountry());
490 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
494 public void testAddGetRemoveCollectingArea() {
495 String tdwgLabel
= "GER";
496 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
497 NamedArea newCollectingArea
= NamedArea
.NewInstance("A nice area",
499 specimenFacade
.addCollectingArea(newCollectingArea
);
500 assertEquals("Exactly 1 area must exist", 1, specimenFacade
501 .getCollectingAreas().size());
502 assertSame("Areas should be same", newCollectingArea
,
503 specimenFacade
.innerFieldUnit().getGatheringEvent()
504 .getCollectingAreas().iterator().next());
505 specimenFacade
.addCollectingArea(tdwgArea
);
506 assertEquals("Exactly 2 areas must exist", 2, specimenFacade
507 .getCollectingAreas().size());
508 specimenFacade
.removeCollectingArea(newCollectingArea
);
509 assertEquals("Exactly 1 area must exist", 1, specimenFacade
510 .getCollectingAreas().size());
511 NamedArea remainingArea
= specimenFacade
.getCollectingAreas()
513 assertEquals("Areas should be same", tdwgArea
, remainingArea
);
514 specimenFacade
.removeCollectingArea(tdwgArea
);
515 assertEquals("No area should remain", 0, specimenFacade
516 .getCollectingAreas().size());
521 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
525 public void testAddCollectingAreas() {
526 NamedArea firstArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
527 assertEquals("No area must exist", 0, specimenFacade
.getCollectingAreas().size());
528 specimenFacade
.addCollectingArea(firstArea
);
529 assertEquals("Exactly 1 area must exist", 1, specimenFacade
.getCollectingAreas().size());
531 String tdwgLabel
= "GER";
532 NamedArea tdwgArea
= termService
.getAreaByTdwgAbbreviation(tdwgLabel
);
533 NamedArea secondArea
= NamedArea
.NewInstance("A nice area", "nice", "n");
535 java
.util
.Collection
<NamedArea
> areaCollection
= new HashSet
<NamedArea
>();
536 areaCollection
.add(secondArea
);
537 areaCollection
.add(tdwgArea
);
538 specimenFacade
.addCollectingAreas(areaCollection
);
539 assertEquals("Exactly 3 areas must exist", 3, specimenFacade
540 .getCollectingAreas().size());
545 * Test method for getting and setting absolute elevation.
546 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
550 public void testGetSetAbsoluteElevation() {
551 assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
552 specimenFacade
.setAbsoluteElevation(400);
553 assertEquals("Absolute elevation must be 400",Integer
.valueOf(400), specimenFacade
.getAbsoluteElevation());
558 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
562 public void testGetSetAbsoluteElevationMaximum() {
563 assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
564 assertEquals("Absolute elevation maximum must be same",absoluteElevationMaximum
, specimenFacade
.getAbsoluteElevationMaximum());
565 specimenFacade
.setAbsoluteElevationMax(4);
566 assertEquals("Absolute elevation maximum must be 4", Integer
.valueOf(4), specimenFacade
.getAbsoluteElevationMaximum());
567 assertEquals("Absolute elevation must be same",absoluteElevation
, specimenFacade
.getAbsoluteElevation());
572 public void testGetSetAbsoluteElevationRange() {
573 assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
574 assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
576 specimenFacade
.setAbsoluteElevationRange(30, 36);
577 assertEquals("", Integer
.valueOf(36),specimenFacade
.getAbsoluteElevationMaximum());
578 assertEquals("", Integer
.valueOf(30),specimenFacade
.getAbsoluteElevation());
579 assertEquals("", "30" + UTF8
.EN_DASH_SPATIUM
+ "36 m",specimenFacade
.absoluteElevationToString());
580 assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
582 specimenFacade
.setAbsoluteElevationRange(30, 35);
583 assertEquals("Odd range should not throw an exception anymore",
584 String
.format("30%s35 m", UTF8
.EN_DASH_SPATIUM
),specimenFacade
.absoluteElevationToString());
586 specimenFacade
.setAbsoluteElevationRange(41, null);
587 assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
588 assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
589 assertEquals("", Integer
.valueOf(41),specimenFacade
.getAbsoluteElevation());
590 assertNull("", specimenFacade
.getAbsoluteElevationText());
591 assertEquals("", "41 m",specimenFacade
.absoluteElevationToString());
593 specimenFacade
.setAbsoluteElevationRange(null, null);
594 assertNull("", specimenFacade
.getAbsoluteElevation());
595 assertNull("", specimenFacade
.getAbsoluteElevationMaximum());
596 assertNull("", specimenFacade
.absoluteElevationToString());
601 public void testGetSetAbsoluteElevationText() {
602 assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
603 assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
604 assertEquals("", null,specimenFacade
.getAbsoluteElevationText());
606 String elevText
= "approx. 30 - 35";
607 specimenFacade
.setAbsoluteElevationText(elevText
);
608 assertEquals("", absoluteElevation
, specimenFacade
.getAbsoluteElevation());
609 assertEquals("", absoluteElevationMaximum
,specimenFacade
.getAbsoluteElevationMaximum());
610 assertEquals("", elevText
,specimenFacade
.absoluteElevationToString());
612 specimenFacade
.setAbsoluteElevationRange(30, 35);
613 assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
614 assertEquals("", Integer
.valueOf(30), specimenFacade
.getAbsoluteElevation());
615 assertEquals("", Integer
.valueOf(35),specimenFacade
.getAbsoluteElevationMaximum());
618 specimenFacade
.setAbsoluteElevationRange(41, null);
619 assertEquals("ToString should not change by setting range if text is set", elevText
,specimenFacade
.absoluteElevationToString());
620 assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
621 assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
624 specimenFacade
.setAbsoluteElevationText(null);
625 assertNull("", specimenFacade
.getAbsoluteElevationText());
626 assertEquals("ToString should change by setting text to null", "41 m",specimenFacade
.absoluteElevationToString());
627 assertEquals("", Integer
.valueOf(41), specimenFacade
.getAbsoluteElevation());
628 assertEquals("", null,specimenFacade
.getAbsoluteElevationMaximum());
635 public void testGetSetCollector() {
636 assertNotNull("Collector must not be null",
637 specimenFacade
.getCollector());
638 assertEquals("Collector must be same", collector
,
639 specimenFacade
.getCollector());
640 specimenFacade
.setCollector(null);
641 assertNull("Collector must be null",
642 specimenFacade
.getCollector());
647 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
651 public void testGetSetCollectingMethod() {
652 assertEquals("Collecting method must be same", collectingMethod
,
653 specimenFacade
.getCollectingMethod());
654 specimenFacade
.setCollectingMethod("new method");
655 assertEquals("Collecting method must be 'new method'",
656 "new method", specimenFacade
.getCollectingMethod());
661 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
665 public void testGetSetDistanceToGround() {
666 assertEquals("Distance to ground must be same",distanceToGround
, specimenFacade
.getDistanceToGround());
667 specimenFacade
.setDistanceToGround(5.0);
668 assertEquals("Distance to ground must be 5", Double
.valueOf(5), specimenFacade
.getDistanceToGround());
673 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
677 public void testGetDistanceToWaterSurface() {
678 assertEquals("Distance to surface must be same", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
679 specimenFacade
.setDistanceToWaterSurface(6.0);
680 assertEquals("Distance to surface must be 6", Double
.valueOf(6), specimenFacade
.getDistanceToWaterSurface());
681 // empty facade tests
682 assertNull("Empty facace must not have any gathering values", emptyFacade
.getDistanceToWaterSurface());
683 emptyFacade
.setDistanceToWaterSurface(13.0);
684 assertNotNull("Field unit must exist if distance to water exists", emptyFacade
.getFieldUnit(false));
685 assertNotNull("Gathering event must exist if distance to water exists", emptyFacade
.getGatheringEvent(false));
686 FieldUnit specimenFieldUnit
= (FieldUnit
) emptyFacade
687 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
688 assertSame("Gathering event of facade and of specimen must be the same",
689 specimenFieldUnit
.getGatheringEvent(), emptyFacade
.getGatheringEvent(false));
693 public void testGetSetDistanceToWaterText() {
694 assertEquals("", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
695 assertEquals("", distanceToSurfaceMax
,specimenFacade
.getDistanceToWaterSurfaceMax());
696 assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceText());
698 String distText
= "approx. 0.3 - 0.6";
699 specimenFacade
.setDistanceToWaterSurfaceText(distText
);
700 assertEquals("", distanceToSurface
, specimenFacade
.getDistanceToWaterSurface());
701 assertEquals("", distanceToSurfaceMax
,specimenFacade
.getDistanceToWaterSurfaceMax());
702 assertEquals("", distText
,specimenFacade
.distanceToWaterSurfaceToString());
704 specimenFacade
.setDistanceToWaterSurfaceRange(0.6, 1.4);
705 assertEquals("ToString should not change by setting range if text is set", distText
,specimenFacade
.distanceToWaterSurfaceToString());
706 assertEquals("", Double
.valueOf(0.6), specimenFacade
.getDistanceToWaterSurface());
707 assertEquals("", Double
.valueOf(1.4),specimenFacade
.getDistanceToWaterSurfaceMax());
709 specimenFacade
.setDistanceToWaterSurfaceRange(41.2, null);
710 assertEquals("ToString should not change by setting range if text is set", distText
,specimenFacade
.distanceToWaterSurfaceToString());
711 assertEquals("", Double
.valueOf(41.2), specimenFacade
.getDistanceToWaterSurface());
712 assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceMax());
714 specimenFacade
.setDistanceToWaterSurfaceText(null);
715 assertNull("", specimenFacade
.getDistanceToWaterSurfaceText());
716 assertEquals("ToString should change by setting text to null", "41.2 m",specimenFacade
.distanceToWaterSurfaceToString());
717 assertEquals("", Double
.valueOf(41.2), specimenFacade
.getDistanceToWaterSurface());
718 assertEquals("", null,specimenFacade
.getDistanceToWaterSurfaceMax());
724 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
727 public void testGetSetExactLocation() {
728 assertNotNull("Exact location must not be null",
729 specimenFacade
.getExactLocation());
730 assertEquals("Exact location must be same", exactLocation
,
731 specimenFacade
.getExactLocation());
732 specimenFacade
.setExactLocation(null);
733 assertNull("Exact location must be null",
734 specimenFacade
.getExactLocation());
738 public void testSetExactLocationByParsing() {
741 specimenFacade
.setExactLocationByParsing("112\u00B034'20\"W",
742 "34\u00B030,34'N", null, null);
743 point1
= specimenFacade
.getExactLocation();
744 assertNotNull("", point1
.getLatitude());
745 System
.out
.println(point1
.getLatitude().toString());
747 point1
.getLatitude().toString().startsWith("34.505"));
748 System
.out
.println(point1
.getLongitude().toString());
750 point1
.getLongitude().toString().startsWith("-112.5722"));
752 } catch (ParseException e
) {
753 fail("No parsing error should occur");
759 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
763 public void testGetSetGatheringEventDescription() {
764 assertEquals("Gathering event description must be same",
765 gatheringEventDescription
,
766 specimenFacade
.getGatheringEventDescription());
767 specimenFacade
.setGatheringEventDescription("new description");
769 "Gathering event description must be 'new description' now",
771 specimenFacade
.getGatheringEventDescription());
776 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
779 public void testGetTimeperiod() {
780 assertNotNull("Gathering period must not be null", specimenFacade
.getGatheringPeriod());
781 assertFalse("Gathering period must not be empty", specimenFacade
.getGatheringPeriod().isEmpty());
782 assertEquals("Gathering period must be same", gatheringPeriod
, specimenFacade
.getGatheringPeriod());
783 specimenFacade
.setGatheringPeriod(null);
784 assertTrue("Gathering period must be null", specimenFacade
.getGatheringPeriod().isEmpty());
788 public void testHasFieldObject() throws SecurityException
,
789 NoSuchFieldException
, IllegalArgumentException
,
790 IllegalAccessException
{
791 // this test depends on the current implementation of SpecimenFacade. In
793 // field unit may not be initialized from the beginning. Than the
795 // assert should be set to assertNull
796 assertTrue("field object should not be null (depends on specimen facade initialization !!)",
797 specimenFacade
.hasFieldObject());
799 Field fieldUnitField
= DerivedUnitFacade
.class.getDeclaredField("fieldUnit");
800 fieldUnitField
.setAccessible(true);
801 fieldUnitField
.set(specimenFacade
, null);
802 assertFalse("The field unit should be null now",
803 specimenFacade
.hasFieldObject());
805 specimenFacade
.setDistanceToGround(33.0);
807 "The field unit should have been created again",
808 specimenFacade
.hasFieldObject());
813 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
817 public void testAddGetRemoveFieldObjectDefinition() {
818 assertEquals("There should be no definition yet", 0,
819 specimenFacade
.getFieldObjectDefinition().size());
820 specimenFacade
.addFieldObjectDefinition("Tres interesant",
822 assertEquals("There should be exactly one definition", 1,
823 specimenFacade
.getFieldObjectDefinition().size());
825 "The French definition should be 'Tres interesant'",
826 "Tres interesant", specimenFacade
.getFieldObjectDefinition()
827 .get(Language
.FRENCH()).getText());
829 "The French definition should be 'Tres interesant'",
831 specimenFacade
.getFieldObjectDefinition(Language
.FRENCH()));
832 specimenFacade
.addFieldObjectDefinition("Sehr interessant",
834 assertEquals("There should be exactly 2 definition", 2,
835 specimenFacade
.getFieldObjectDefinition().size());
836 specimenFacade
.removeFieldObjectDefinition(Language
.FRENCH());
837 assertEquals("There should remain exactly 1 definition", 1,
838 specimenFacade
.getFieldObjectDefinition().size());
840 "The remaining German definition should be 'Sehr interessant'",
842 specimenFacade
.getFieldObjectDefinition(Language
.GERMAN()));
843 specimenFacade
.removeFieldObjectDefinition(Language
.GERMAN());
844 assertEquals("There should remain no definition", 0,
845 specimenFacade
.getFieldObjectDefinition().size());
850 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
854 public void testAddGetHasRemoveFieldObjectMedia() {
855 assertFalse("There should be no image gallery yet",
856 specimenFacade
.hasFieldObjectImageGallery());
857 assertFalse("There should be no specimen image gallery either",
858 specimenFacade
.hasDerivedUnitImageGallery());
860 List
<Media
> media
= specimenFacade
.getFieldObjectMedia();
861 assertFalse("There should still not be an image gallery now",
862 specimenFacade
.hasFieldObjectImageGallery());
863 assertEquals("There should be no media yet in the gallery", 0,
866 Media media1
= Media
.NewInstance();
867 specimenFacade
.addFieldObjectMedia(media1
);
868 assertEquals("There should be exactly one specimen media", 1,
869 specimenFacade
.getFieldObjectMedia().size());
870 assertEquals("The only media should be media 1", media1
,
871 specimenFacade
.getFieldObjectMedia().get(0));
873 "There should still no specimen image gallery exist",
874 specimenFacade
.hasDerivedUnitImageGallery());
876 Media media2
= Media
.NewInstance();
877 specimenFacade
.addFieldObjectMedia(media2
);
878 assertEquals("There should be exactly 2 specimen media", 2,
879 specimenFacade
.getFieldObjectMedia().size());
880 assertEquals("The first media should be media1", media1
,
881 specimenFacade
.getFieldObjectMedia().get(0));
882 assertEquals("The second media should be media2", media2
,
883 specimenFacade
.getFieldObjectMedia().get(1));
885 specimenFacade
.removeFieldObjectMedia(media1
);
886 assertEquals("There should be exactly one specimen media", 1,
887 specimenFacade
.getFieldObjectMedia().size());
888 assertEquals("The only media should be media2", media2
,
889 specimenFacade
.getFieldObjectMedia().get(0));
891 specimenFacade
.removeFieldObjectMedia(media1
);
892 assertEquals("There should still be exactly one specimen media",
893 1, specimenFacade
.getFieldObjectMedia().size());
895 specimenFacade
.removeFieldObjectMedia(media2
);
896 assertEquals("There should remain no media in the gallery", 0,
903 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getEcology()}
907 public void testGetSetEcology() {
909 "An empty ecology data should be created when calling getEcology()",
910 specimenFacade
.getEcologyAll());
912 "An empty ecology data should be created when calling getEcology()",
913 0, specimenFacade
.getEcologyAll().size());
914 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
915 assertEquals("Ecology data should exist for 1 language", 1,
916 specimenFacade
.getEcologyAll().size());
918 "Ecology data should be 'Tres jolie ici' for French",
919 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
921 "Ecology data should be null for the default language",
922 specimenFacade
.getEcology());
923 specimenFacade
.setEcology("Nice here");
924 assertEquals("Ecology data should exist for 2 languages", 2,
925 specimenFacade
.getEcologyAll().size());
926 assertEquals("Ecology data should be 'Tres jolie ici'",
927 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
929 "Ecology data should be 'Nice here' for the default language",
930 "Nice here", specimenFacade
.getEcology());
931 assertEquals("Ecology data should be 'Nice here' for english",
932 "Nice here", specimenFacade
.getEcology());
934 specimenFacade
.setEcology("Vert et rouge", Language
.FRENCH());
935 assertEquals("Ecology data should exist for 2 languages", 2,
936 specimenFacade
.getEcologyAll().size());
937 assertEquals("Ecology data should be 'Vert et rouge'",
938 "Vert et rouge", specimenFacade
.getEcology(Language
.FRENCH()));
940 "Ecology data should be 'Nice here' for the default language",
941 "Nice here", specimenFacade
.getEcology());
943 specimenFacade
.setEcology(null, Language
.FRENCH());
944 assertEquals("Ecology data should exist for 1 languages", 1,
945 specimenFacade
.getEcologyAll().size());
947 "Ecology data should be 'Nice here' for the default language",
948 "Nice here", specimenFacade
.getEcology());
949 assertNull("Ecology data should be 'null' for French",
950 specimenFacade
.getEcology(Language
.FRENCH()));
952 specimenFacade
.removeEcology(null);
953 assertEquals("There should be no ecology left", 0,
954 specimenFacade
.getEcologyAll().size());
955 assertNull("Ecology data should be 'null' for default language",
956 specimenFacade
.getEcology());
962 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPlantDescription()}
966 public void testGetSetPlantDescription() {
968 "An empty plant description data should be created when calling getPlantDescriptionAll()",
969 specimenFacade
.getPlantDescriptionAll());
971 "An empty plant description data should be created when calling getPlantDescription()",
972 0, specimenFacade
.getPlantDescriptionAll().size());
973 specimenFacade
.setPlantDescription("bleu", Language
.FRENCH());
975 "Plant description data should exist for 1 language", 1,
976 specimenFacade
.getPlantDescriptionAll().size());
978 "Plant description data should be 'bleu' for French", "bleu",
979 specimenFacade
.getPlantDescription(Language
.FRENCH()));
981 "Plant description data should be null for the default language",
982 specimenFacade
.getPlantDescription());
983 specimenFacade
.setPlantDescription("Nice here");
985 "Plant description data should exist for 2 languages", 2,
986 specimenFacade
.getPlantDescriptionAll().size());
987 assertEquals("Plant description data should be 'bleu'", "bleu",
988 specimenFacade
.getPlantDescription(Language
.FRENCH()));
990 "Plant description data should be 'Nice here' for the default language",
991 "Nice here", specimenFacade
.getPlantDescription());
993 "Plant description data should be 'Nice here' for english",
994 "Nice here", specimenFacade
.getPlantDescription());
996 specimenFacade
.setPlantDescription("Vert et rouge", Language
.FRENCH());
998 "Plant description data should exist for 2 languages", 2,
999 specimenFacade
.getPlantDescriptionAll().size());
1000 assertEquals("Plant description data should be 'Vert et rouge'",
1002 specimenFacade
.getPlantDescription(Language
.FRENCH()));
1004 "Plant description data should be 'Nice here' for the default language",
1005 "Nice here", specimenFacade
.getPlantDescription());
1007 specimenFacade
.setPlantDescription(null, Language
.FRENCH());
1009 "Plant description data should exist for 1 languages", 1,
1010 specimenFacade
.getPlantDescriptionAll().size());
1012 "Plant description data should be 'Nice here' for the default language",
1013 "Nice here", specimenFacade
.getPlantDescription());
1014 assertNull("Plant description data should be 'null' for French",
1015 specimenFacade
.getPlantDescription(Language
.FRENCH()));
1017 // test interference with ecology
1018 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
1019 assertEquals("Ecology data should exist for 1 language", 1,
1020 specimenFacade
.getEcologyAll().size());
1022 "Ecology data should be 'Tres jolie ici' for French",
1023 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
1025 "Ecology data should be null for the default language",
1026 specimenFacade
.getEcology());
1028 // repeat above test
1030 "Plant description data should exist for 1 languages", 1,
1031 specimenFacade
.getPlantDescriptionAll().size());
1033 "Plant description data should be 'Nice here' for the default language",
1034 "Nice here", specimenFacade
.getPlantDescription());
1035 assertNull("Plant description data should be 'null' for French",
1036 specimenFacade
.getPlantDescription(Language
.FRENCH()));
1038 specimenFacade
.removePlantDescription(null);
1039 assertEquals("There should be no plant description left", 0,
1040 specimenFacade
.getPlantDescriptionAll().size());
1042 "Plant description data should be 'null' for default language",
1043 specimenFacade
.getPlantDescription());
1049 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeform()}
1053 public void testGetSetLifeform() {
1054 Feature lifeform
= Feature
.LIFEFORM();
1055 assertNotNull("Lifeform must exist in testdata",lifeform
);
1057 "An empty life-form data should be created when calling getLifeformAll()",
1058 specimenFacade
.getLifeformAll());
1060 "An empty life-form data should be created when calling getLifeform()",
1061 0, specimenFacade
.getLifeformAll().size());
1062 specimenFacade
.setLifeform("grande", Language
.FRENCH());
1064 "Life-form data should exist for 1 language", 1,
1065 specimenFacade
.getLifeformAll().size());
1067 "Life-form data should be 'grande' for French", "grande",
1068 specimenFacade
.getLifeform(Language
.FRENCH()));
1070 "Lifeform data should be null for the default language",
1071 specimenFacade
.getLifeform());
1072 specimenFacade
.setLifeform("Very big");
1074 "Life-form data should exist for 2 languages", 2,
1075 specimenFacade
.getLifeformAll().size());
1076 assertEquals("French life-form data should be 'grande'", "grande",
1077 specimenFacade
.getLifeform(Language
.FRENCH()));
1079 "Default language life-form data should be 'Very big' for the default language",
1080 "Very big", specimenFacade
.getLifeform());
1082 "Life-form data should be 'Very big' for English",
1083 "Very big", specimenFacade
.getLifeform());
1085 specimenFacade
.setLifeform("Petite", Language
.FRENCH());
1087 "Plant description data should exist for 2 languages", 2,
1088 specimenFacade
.getLifeformAll().size());
1089 assertEquals("Life-form data should be 'Petite'",
1091 specimenFacade
.getLifeform(Language
.FRENCH()));
1093 "Plant description data should be 'Very big' for the default language",
1094 "Very big", specimenFacade
.getLifeform());
1096 specimenFacade
.setLifeform(null, Language
.FRENCH());
1098 "Life-form data should exist for 1 languages", 1,
1099 specimenFacade
.getLifeformAll().size());
1101 "Life-form data should be 'Very big' for the default language",
1102 "Very big", specimenFacade
.getLifeform());
1103 assertNull("Life-form data should be 'null' for French",
1104 specimenFacade
.getLifeform(Language
.FRENCH()));
1106 // test interference with ecology
1107 specimenFacade
.setEcology("Tres jolie ici", Language
.FRENCH());
1108 assertEquals("Ecology data should exist for 1 language", 1,
1109 specimenFacade
.getEcologyAll().size());
1111 "Ecology data should be 'Tres jolie ici' for French",
1112 "Tres jolie ici", specimenFacade
.getEcology(Language
.FRENCH()));
1114 "Ecology data should be null for the default language",
1115 specimenFacade
.getEcology());
1117 // repeat above test
1119 "Life-form data should exist for 1 languages", 1,
1120 specimenFacade
.getLifeformAll().size());
1122 "Lifeform data should be 'Very big' for the default language",
1123 "Very big", specimenFacade
.getLifeform());
1124 assertNull("Life-form data should be 'null' for French",
1125 specimenFacade
.getLifeform(Language
.FRENCH()));
1127 specimenFacade
.removeLifeform(null);
1128 assertEquals("There should be no life-form left", 0,
1129 specimenFacade
.getLifeformAll().size());
1131 "Life-form data should be 'null' for default language",
1132 specimenFacade
.getLifeform());
1137 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
1140 public void testGetSetFieldNumber() {
1141 assertEquals("Field number must be same", fieldNumber
,
1142 specimenFacade
.getFieldNumber());
1143 specimenFacade
.setFieldNumber("564AB");
1144 assertEquals("New field number must be '564AB'", "564AB",
1145 specimenFacade
.getFieldNumber());
1146 // empty facade tests
1147 assertNull("Empty facace must not have any field value",
1148 emptyFacade
.getFieldNumber());
1149 emptyFacade
.setFieldNumber("1256A");
1151 "Field unit must exist if field number exists",
1152 emptyFacade
.getFieldUnit(false));
1153 FieldUnit specimenFieldUnit
= (FieldUnit
) emptyFacade
1154 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
1157 "Field unit of facade and of specimen must be the same",
1159 emptyFacade
.getFieldUnit(false));
1160 assertEquals("1256A", emptyFacade
.getFieldNumber());
1165 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
1168 public void testGetSetFieldNotes() {
1169 assertEquals("Field notes must be same", fieldNotes
,
1170 specimenFacade
.getFieldNotes());
1171 specimenFacade
.setFieldNotes("A completely new info");
1172 assertEquals("New field note must be 'A completely new info'",
1173 "A completely new info", specimenFacade
.getFieldNotes());
1178 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1182 @Ignore // #######DerivationEvent ---------------------------------------- 1
1183 public void testSetGatheringEvent() {
1184 GatheringEvent newGatheringEvent
= GatheringEvent
.NewInstance();
1185 newGatheringEvent
.setDistanceToGround(43.0);
1186 assertFalse("The initial distance to ground should not be 43",
1187 specimenFacade
.getDistanceToGround() == 43.0);
1188 specimenFacade
.setGatheringEvent(newGatheringEvent
);
1189 assertTrue("The final distance to ground should be 43",
1190 specimenFacade
.getDistanceToGround() == 43.0);
1192 "The new gathering event should be 'newGatheringEvent'",
1193 newGatheringEvent
, specimenFacade
.innerGatheringEvent());
1198 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1202 public void testGetGatheringEvent() {
1203 assertNotNull("Gathering event must not be null",
1204 specimenFacade
.innerGatheringEvent());
1206 "Gathering event must be field unit's gathering event",
1207 specimenFacade
.innerFieldUnit().getGatheringEvent(),
1208 specimenFacade
.innerGatheringEvent());
1213 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1217 public void testGetSetIndividualCount() {
1218 assertEquals("Individual count must be same", individualCount
,
1219 specimenFacade
.getIndividualCount());
1220 specimenFacade
.setIndividualCount("4");
1221 assertEquals("New individual count must be '4'", "4", specimenFacade
.getIndividualCount());
1226 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1229 public void testGetSetLifeStage() {
1230 assertNotNull("Life stage must not be null", specimenFacade
.getLifeStage());
1231 assertEquals("Life stage must be same", lifeStage
, specimenFacade
.getLifeStage());
1232 specimenFacade
.setLifeStage(null);
1233 assertNull("Life stage must be null", specimenFacade
.getLifeStage());
1234 //don't create if null
1235 DerivedUnitFacade facade
= emptyFacade();
1236 emptyFacade().setLifeStage(null);
1237 assertNull(facade
.innerFieldUnit());
1242 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1245 public void testGetSetSex() {
1246 assertNotNull("Sex must not be null", specimenFacade
.getSex());
1247 assertEquals("Sex must be same", sex
, specimenFacade
.getSex());
1248 specimenFacade
.setSex(null);
1249 assertNull("Sex must be null", specimenFacade
.getSex());
1250 //don't create if null
1251 DerivedUnitFacade facade
= emptyFacade();
1252 emptyFacade().setSex(null);
1253 assertNull(facade
.innerFieldUnit());
1259 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1262 public void testGetSetKindOfUnit() {
1263 assertNotNull("Kind-of-unit must not be null", specimenFacade
.getFieldUnitKindOfUnit());
1264 assertEquals("Kind-of-unit must be same", kindOfUnit
, specimenFacade
.getFieldUnitKindOfUnit());
1265 specimenFacade
.setFieldUnitKindOfUnit(null);
1266 assertNull("Kind-of-unit must be null", specimenFacade
.getFieldUnitKindOfUnit());
1267 DerivedUnitFacade facade
= emptyFacade();
1268 facade
.setFieldUnitKindOfUnit(null);
1269 assertNull(facade
.innerFieldUnit());
1274 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1277 public void testGetSetLocality() {
1278 assertEquals("Locality must be same", locality
,
1279 specimenFacade
.getLocality());
1280 specimenFacade
.setLocality("A completely new place", Language
.FRENCH());
1281 assertEquals("New locality must be 'A completely new place'",
1282 "A completely new place", specimenFacade
.getLocalityText());
1283 assertEquals("New locality language must be French",
1284 Language
.FRENCH(), specimenFacade
.getLocalityLanguage());
1285 specimenFacade
.setLocality("Another place");
1286 assertEquals("New locality must be 'Another place'",
1287 "Another place", specimenFacade
.getLocalityText());
1288 assertEquals("New locality language must be default",
1289 Language
.DEFAULT(), specimenFacade
.getLocalityLanguage());
1294 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1298 public void testAddGetRemoveSpecimenDefinition() {
1299 assertEquals("There should be no definition yet", 0,
1300 specimenFacade
.getDerivedUnitDefinitions().size());
1301 specimenFacade
.addDerivedUnitDefinition("Tres interesant",
1303 assertEquals("There should be exactly one definition", 1,
1304 specimenFacade
.getDerivedUnitDefinitions().size());
1306 "The French definition should be 'Tres interesant'",
1307 "Tres interesant", specimenFacade
.getDerivedUnitDefinitions()
1308 .get(Language
.FRENCH()).getText());
1310 "The French definition should be 'Tres interesant'",
1312 specimenFacade
.getDerivedUnitDefinition(Language
.FRENCH()));
1313 specimenFacade
.addDerivedUnitDefinition("Sehr interessant",
1315 assertEquals("There should be exactly 2 definition", 2,
1316 specimenFacade
.getDerivedUnitDefinitions().size());
1317 specimenFacade
.removeDerivedUnitDefinition(Language
.FRENCH());
1318 assertEquals("There should remain exactly 1 definition", 1,
1319 specimenFacade
.getDerivedUnitDefinitions().size());
1321 "The remaining German definition should be 'Sehr interessant'",
1323 specimenFacade
.getDerivedUnitDefinition(Language
.GERMAN()));
1324 specimenFacade
.removeDerivedUnitDefinition(Language
.GERMAN());
1325 assertEquals("There should remain no definition", 0,
1326 specimenFacade
.getDerivedUnitDefinitions().size());
1331 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1335 public void testAddGetRemoveDetermination() {
1336 assertEquals("There should be no determination yet", 0,
1337 specimenFacade
.getDeterminations().size());
1338 DeterminationEvent determinationEvent1
= DeterminationEvent
1340 specimenFacade
.addDetermination(determinationEvent1
);
1341 assertEquals("There should be exactly one determination", 1,
1342 specimenFacade
.getDeterminations().size());
1343 assertEquals("The only determination should be determination 1",
1344 determinationEvent1
, specimenFacade
.getDeterminations()
1345 .iterator().next());
1347 DeterminationEvent determinationEvent2
= DeterminationEvent
1349 specimenFacade
.addDetermination(determinationEvent2
);
1350 assertEquals("There should be exactly 2 determinations", 2,
1351 specimenFacade
.getDeterminations().size());
1352 specimenFacade
.removeDetermination(determinationEvent1
);
1354 assertEquals("There should remain exactly 1 determination", 1,
1355 specimenFacade
.getDeterminations().size());
1357 "The remaining determinations should be determination 2",
1358 determinationEvent2
, specimenFacade
.getDeterminations()
1359 .iterator().next());
1361 specimenFacade
.removeDetermination(determinationEvent1
);
1362 assertEquals("There should remain exactly 1 determination", 1,
1363 specimenFacade
.getDeterminations().size());
1365 specimenFacade
.removeDetermination(determinationEvent2
);
1366 assertEquals("There should remain no definition", 0,
1367 specimenFacade
.getDerivedUnitDefinitions().size());
1374 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1378 public void testPreferredOtherDeterminations() {
1379 assertEquals("There should be no determination yet", 0,
1380 specimenFacade
.getDeterminations().size());
1381 DeterminationEvent determinationEvent1
= DeterminationEvent
.NewInstance();
1382 specimenFacade
.setPreferredDetermination(determinationEvent1
);
1384 assertEquals("There should be exactly one determination", 1,
1385 specimenFacade
.getDeterminations().size());
1386 assertEquals("The only determination should be determination 1",
1387 determinationEvent1
, specimenFacade
.getDeterminations()
1388 .iterator().next());
1389 assertEquals("determination 1 should be the preferred determination",
1390 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1391 assertEquals("There should be no 'non preferred' determination", 0,
1392 specimenFacade
.getOtherDeterminations().size());
1396 DeterminationEvent determinationEvent2
= DeterminationEvent
.NewInstance();
1397 specimenFacade
.addDetermination(determinationEvent2
);
1398 assertEquals("There should be exactly 2 determinations", 2,
1399 specimenFacade
.getDeterminations().size());
1400 assertEquals("determination 1 should be the preferred determination",
1401 determinationEvent1
, specimenFacade
.getPreferredDetermination());
1402 assertEquals("There should be one 'non preferred' determination", 1,
1403 specimenFacade
.getOtherDeterminations().size());
1404 assertEquals("The only 'non preferred' determination should be determination 2",
1405 determinationEvent2
, specimenFacade
.getOtherDeterminations().iterator().next());
1408 DeterminationEvent determinationEvent3
= DeterminationEvent
.NewInstance();
1409 specimenFacade
.setPreferredDetermination(determinationEvent3
);
1410 assertEquals("There should be exactly 3 determinations", 3,
1411 specimenFacade
.getDeterminations().size());
1412 assertEquals("determination 3 should be the preferred determination",
1413 determinationEvent3
, specimenFacade
.getPreferredDetermination());
1414 assertEquals("There should be 2 'non preferred' determination", 2,
1415 specimenFacade
.getOtherDeterminations().size());
1416 assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1417 specimenFacade
.getOtherDeterminations().contains(determinationEvent1
));
1418 assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1419 specimenFacade
.getOtherDeterminations().contains(determinationEvent2
));
1425 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1429 public void testAddGetHasRemoveSpecimenMedia() {
1430 assertFalse("There should be no image gallery yet",
1431 specimenFacade
.hasDerivedUnitImageGallery());
1433 "There should be also no field object image gallery yet",
1434 specimenFacade
.hasFieldObjectImageGallery());
1436 List
<Media
> media
= specimenFacade
.getDerivedUnitMedia();
1438 "There should still not be an empty image gallery now",
1439 specimenFacade
.hasDerivedUnitImageGallery());
1440 assertEquals("There should be no media yet in the gallery", 0,
1443 Media media1
= Media
.NewInstance();
1444 specimenFacade
.addDerivedUnitMedia(media1
);
1445 assertEquals("There should be exactly one specimen media", 1,
1446 specimenFacade
.getDerivedUnitMedia().size());
1447 assertEquals("The only media should be media 1", media1
,
1448 specimenFacade
.getDerivedUnitMedia().get(0));
1450 "There should be still no field object image gallery",
1451 specimenFacade
.hasFieldObjectImageGallery());
1453 Media media2
= Media
.NewInstance();
1454 specimenFacade
.addDerivedUnitMedia(media2
);
1455 assertEquals("There should be exactly 2 specimen media", 2,
1456 specimenFacade
.getDerivedUnitMedia().size());
1457 assertEquals("The first media should be media1", media1
,
1458 specimenFacade
.getDerivedUnitMedia().get(0));
1459 assertEquals("The second media should be media2", media2
,
1460 specimenFacade
.getDerivedUnitMedia().get(1));
1462 specimenFacade
.removeDerivedUnitMedia(media1
);
1463 assertEquals("There should be exactly one specimen media", 1,
1464 specimenFacade
.getDerivedUnitMedia().size());
1465 assertEquals("The only media should be media2", media2
,
1466 specimenFacade
.getDerivedUnitMedia().get(0));
1468 specimenFacade
.removeDerivedUnitMedia(media1
);
1469 assertEquals("There should still be exactly one specimen media",
1470 1, specimenFacade
.getDerivedUnitMedia().size());
1472 specimenFacade
.removeDerivedUnitMedia(media2
);
1473 assertEquals("There should remain no media in the gallery", 0,
1479 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1483 public void testGetSetAccessionNumber() {
1484 assertEquals("Accession number must be same", accessionNumber
,
1485 specimenFacade
.getAccessionNumber());
1486 specimenFacade
.setAccessionNumber("A12345693");
1487 assertEquals("New accession number must be 'A12345693'",
1488 "A12345693", specimenFacade
.getAccessionNumber());
1494 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1497 public void testGetCatalogNumber() {
1498 assertEquals("Catalog number must be same", catalogNumber
,
1499 specimenFacade
.getCatalogNumber());
1500 specimenFacade
.setCatalogNumber("B12345693");
1501 assertEquals("New catalog number must be 'B12345693'",
1502 "B12345693", specimenFacade
.getCatalogNumber());
1507 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1510 public void testGetPreservation() {
1512 assertNotNull("Preservation method must not be null",
1513 specimenFacade
.getPreservationMethod());
1514 assertEquals("Preservation method must be same",
1515 preservationMethod
, specimenFacade
.getPreservationMethod());
1516 specimenFacade
.setPreservationMethod(null);
1517 assertNull("Preservation method must be null",
1518 specimenFacade
.getPreservationMethod());
1519 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1520 fail("Method not supported should not be thrown for a specimen");
1522 specimenFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.Observation
);
1524 specimenFacade
.setPreservationMethod(preservationMethod
);
1525 fail("Method not supported should be thrown for an observation on set preservation method");
1527 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1530 specimenFacade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.LivingSpecimen
);
1532 specimenFacade
.getPreservationMethod();
1533 fail("Method not supported should be thrown for a living being on get preservation method");
1534 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
1541 public void testGetSetOriginalLabelInfo() {
1542 assertEquals("Original label info must be same", originalLabelInfo
,
1543 specimenFacade
.getOriginalLabelInfo());
1544 specimenFacade
.setOriginalLabelInfo("OrigLabel Info xxx");
1545 assertEquals("New accession number must be 'OrigLabel Info xxx'",
1546 "OrigLabel Info xxx", specimenFacade
.getOriginalLabelInfo());
1550 public void testGetSetStableUri() {
1551 assertEquals("Preferred stable URI must be same", stableUri
,
1552 specimenFacade
.getPreferredStableUri());
1553 URI newURI
= URI
.create("http://www.fgh.ij");
1554 specimenFacade
.setPreferredStableUri(newURI
);
1555 assertEquals("New preferred stable must be '" + newURI
.toString() + "'",
1556 newURI
, specimenFacade
.getPreferredStableUri());
1563 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1566 public void testGetStoredUnder() {
1567 assertNotNull("Stored under name must not be null",
1568 specimenFacade
.getStoredUnder());
1569 assertEquals("Stored under name must be same", taxonName
,
1570 specimenFacade
.getStoredUnder());
1571 specimenFacade
.setStoredUnder(null);
1572 assertNull("Stored under name must be null",
1573 specimenFacade
.getStoredUnder());
1577 // * Test method for
1578 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1582 // public void testGetSetCollectorsNumber() {
1583 // assertEquals("Collectors number must be same", collectorsNumber,
1584 // specimenFacade.getCollectorsNumber());
1585 // specimenFacade.setCollectorsNumber("C12345693");
1586 // assertEquals("New collectors number must be 'C12345693'",
1587 // "C12345693", specimenFacade.getCollectorsNumber());
1592 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1595 public void testGetTitleCache() {
1597 "The title cache should never return null if not protected",
1598 specimenFacade
.getTitleCache());
1599 specimenFacade
.setTitleCache(null, false);
1601 "The title cache should never return null if not protected",
1602 specimenFacade
.getTitleCache());
1607 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1611 public void testSetTitleCache() {
1612 String testTitle
= "Absdwk aksjlf";
1613 specimenFacade
.setTitleCache(testTitle
, true);
1615 "Protected title cache should returns the test title",
1616 testTitle
, specimenFacade
.getTitleCache());
1617 specimenFacade
.setTitleCache(testTitle
, false);
1619 "Unprotected title cache should not return the test title",
1620 testTitle
.equals(specimenFacade
.getTitleCache()));
1625 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1628 public void testGetSpecimen() {
1629 assertEquals("Specimen must be same", specimen
,
1630 specimenFacade
.innerDerivedUnit());
1635 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1638 public void testGetSetCollection() {
1639 assertNotNull("Collection must not be null",
1640 specimenFacade
.getCollection());
1641 assertEquals("Collection must be same", collection
,
1642 specimenFacade
.getCollection());
1643 specimenFacade
.setCollection(null);
1644 assertNull("Collection must be null",
1645 specimenFacade
.getCollection());
1649 public void testAddGetRemoveSource() {
1650 assertEquals("No sources should exist yet", 0, specimenFacade
.getSources().size());
1652 Reference reference
= ReferenceFactory
.newBook();
1653 IdentifiableSource source1
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference
, "54", "myName");
1654 assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1655 IdentifiableSource source2
= IdentifiableSource
.NewDataImportInstance("1", "myTable");
1656 specimenFacade
.addSource(source2
);
1657 assertEquals("One source should exist now", 2, specimenFacade
.getSources().size());
1658 specimenFacade
.removeSource(source1
);
1659 assertEquals("One source should exist now", 1, specimenFacade
.getSources().size());
1660 Reference reference2
= ReferenceFactory
.newJournal();
1661 IdentifiableSource sourceNotUsed
= specimenFacade
.addSource(OriginalSourceType
.PrimaryTaxonomicSource
, reference2
,null, null);
1662 specimenFacade
.removeSource(sourceNotUsed
);
1663 assertEquals("One source should still exist", 1, specimenFacade
.getSources().size());
1664 assertEquals("1", specimenFacade
.getSources().iterator().next().getIdInSource());
1665 specimenFacade
.removeSource(source2
);
1666 assertEquals("No sources should exist anymore", 0,specimenFacade
.getSources().size());
1670 public void testAddGetRemoveDuplicate() {
1671 assertEquals("No duplicates should be available yet", 0,specimenFacade
.getDuplicates().size());
1672 DerivedUnit newSpecimen1
= DerivedUnit
.NewPreservedSpecimenInstance();
1673 specimenFacade
.addDuplicate(newSpecimen1
);
1674 assertEquals("There should be 1 duplicate now", 1,specimenFacade
.getDuplicates().size());
1675 DerivedUnit newSpecimen2
= DerivedUnit
.NewPreservedSpecimenInstance();
1676 DerivationEvent newDerivationEvent
= DerivationEvent
.NewInstance(DerivationEventType
.ACCESSIONING());
1677 newSpecimen2
.setDerivedFrom(newDerivationEvent
);
1679 "The derivation event should be 'newDerivationEvent'",
1680 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1681 specimenFacade
.addDuplicate(newSpecimen2
);
1682 assertEquals("There should be 2 duplicates now", 2, specimenFacade
.getDuplicates().size());
1684 "The derivation event should not be 'newDerivationEvent' anymore",
1685 newDerivationEvent
, newSpecimen2
.getDerivedFrom());
1687 "The derivation event should not be the facades derivation event",
1688 derivationEvent
, newSpecimen2
.getDerivedFrom());
1689 specimenFacade
.removeDuplicate(newSpecimen1
);
1690 assertEquals("There should be 1 duplicate now", 1,
1691 specimenFacade
.getDuplicates().size());
1692 assertSame("The only duplicate should be 'newSpecimen2' now",
1693 newSpecimen2
, specimenFacade
.getDuplicates().iterator().next());
1694 specimenFacade
.addDuplicate(specimenFacade
.innerDerivedUnit());
1696 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1697 1, specimenFacade
.getDuplicates().size());
1699 Collection newCollection
= Collection
.NewInstance();
1700 String catalogNumber
= "1234890";
1701 String accessionNumber
= "345345";
1702 TaxonName storedUnder
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
1703 PreservationMethod method
= PreservationMethod
.NewInstance();
1704 DerivedUnit duplicateSpecimen
= specimenFacade
.addDuplicate(newCollection
,
1705 catalogNumber
, accessionNumber
, storedUnder
,
1707 assertEquals("There should be 2 duplicates now", 2,
1708 specimenFacade
.getDuplicates().size());
1709 specimenFacade
.removeDuplicate(newSpecimen2
);
1710 assertEquals("There should be 1 duplicates now", 1,
1711 specimenFacade
.getDuplicates().size());
1712 Collection sameCollection
= specimenFacade
.getDuplicates().iterator().next().getCollection();
1713 assertSame("Collections should be same", newCollection
, sameCollection
);
1716 // ************************** Existing Specimen with multiple derivation
1717 // events in line **************/
1720 public void testExistingSpecimen() {
1721 specimenFacade
= null;
1723 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1724 } catch (DerivedUnitFacadeNotSupportedException e
) {
1725 fail("Multiple derivation events in line should not throw a not supported exception");
1728 "Gathering event should derive from the derivation line",
1729 existingGatheringEvent
, specimenFacade
.innerGatheringEvent());
1731 "Mediasize should be 0. Only Imagegallery media are supported",
1732 0, specimenFacade
.getFieldObjectMedia().size());
1736 public void testMultipleFieldUnitNotSupported() {
1737 specimenFacade
= null;
1738 FieldUnit secondFieldObject
= FieldUnit
.NewInstance();
1739 firstDerivationEvent
.addOriginal(secondFieldObject
);
1741 specimenFacade
= DerivedUnitFacade
.NewInstance(collectionSpecimen
);
1742 fail("Multiple field units for one specimen should no be supported by the facade");
1743 } catch (DerivedUnitFacadeNotSupportedException e
) {
1746 assertNull("Specimen facade should not be initialized",
1750 // not required anymore #3597
1751 // @Test // #######DerivationEvent
1752 // public void testOnlyImageGallerySupported() {
1753 // specimenFacade = null;
1754 // firstFieldObject.addMedia(media1);
1756 // specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
1757 // fail("Only image galleries are supported by the facade but not direct media");
1758 // } catch (DerivedUnitFacadeNotSupportedException e) {
1761 // assertNull("Specimen facade should not be initialized",
1765 @Test // #######DerivationEvent
1766 public void testEventPropagation() {
1767 specimenFacade
.setDistanceToGround(24.0);
1771 // @Ignore // set to ignore because I did not want to check knowingly
1772 // failing tests. Remove @Ignore when this is fixed
1774 public void testSetBarcode() {
1775 String barcode
= "barcode";
1776 specimenFacade
.setBarcode(barcode
);
1778 assertEquals(barcode
, specimenFacade
.getBarcode());
1782 public void testIsEvenDistance() {
1783 Integer minimum
= 20;
1784 Integer maximum
= 1234;
1786 // this should not throw exceptions
1787 specimenFacade
.setAbsoluteElevationRange(minimum
, maximum
);
1792 * See https://dev.e-taxonomy.eu/redmine/issues/2426
1793 * This test doesn't handle the above issue yet as it doesn't fire events as
1794 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1795 * In the meanwhile the property change framework for the facade has been changed
1796 * so the original problem may have disappeared.
1801 @DataSet(loadStrategy
=CleanSweepInsertLoadStrategy
.class, value
="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
1802 @DataSet(value
="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
1805 public void testNoRecursiveChangeEvents(){
1806 String username
= "username";
1807 String password
= "password";
1808 User user
= User
.NewInstance(username
, password
);
1809 userService
.save(user
);
1810 UsernamePasswordAuthenticationToken token
= new UsernamePasswordAuthenticationToken(user
, password
);
1811 SecurityContextHolder
.getContext().setAuthentication(token
);
1813 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
1814 facade
.setLocality("testLocality");
1815 facade
.getTitleCache();
1816 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1817 this.service
.save(facade
.innerDerivedUnit());
1818 commitAndStartNewTransaction(null);
1822 public void testBaseUnit() throws DerivedUnitFacadeNotSupportedException
{
1823 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(specimen
);
1824 assertEquals("baseUnit is incorrect", specimen
, facade
.baseUnit());
1826 facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.FieldUnit
, fieldUnit
);
1827 assertEquals("baseUnit is incorrect", fieldUnit
, facade
.baseUnit());
1829 facade
= DerivedUnitFacade
.NewInstance(specimen
);
1830 facade
.getFieldUnit(true);
1831 assertEquals("baseUnit is incorrect", specimen
, facade
.baseUnit());
1836 * Returns an empty DU facade
1839 private DerivedUnitFacade
emptyFacade() {
1840 DerivedUnitFacade facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.DerivedUnit
);
1845 public void createTestDataSet() throws FileNotFoundException
{
1846 // TODO Auto-generated method stub