Change WaterbodyOrCountry name to Country #3700
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / facade / DerivedUnitFacadeTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.cdm.api.facade;
11
12 import java.lang.reflect.Field;
13 import java.net.URI;
14 import java.text.ParseException;
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.UUID;
18
19 import org.apache.log4j.Logger;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Ignore;
23 import org.junit.Test;
24 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
25 import org.springframework.security.core.context.SecurityContextHolder;
26 import org.unitils.dbunit.annotation.DataSet;
27 import org.unitils.dbunit.annotation.ExpectedDataSet;
28 import org.unitils.spring.annotation.SpringBeanByType;
29
30 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
31 import eu.etaxonomy.cdm.api.service.ITermService;
32 import eu.etaxonomy.cdm.api.service.IUserService;
33 import eu.etaxonomy.cdm.common.UTF8;
34 import eu.etaxonomy.cdm.model.agent.AgentBase;
35 import eu.etaxonomy.cdm.model.agent.Team;
36 import eu.etaxonomy.cdm.model.common.DefinedTerm;
37 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
38 import eu.etaxonomy.cdm.model.common.Language;
39 import eu.etaxonomy.cdm.model.common.LanguageString;
40 import eu.etaxonomy.cdm.model.common.OriginalSourceType;
41 import eu.etaxonomy.cdm.model.common.TimePeriod;
42 import eu.etaxonomy.cdm.model.common.User;
43 import eu.etaxonomy.cdm.model.description.Feature;
44 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
45 import eu.etaxonomy.cdm.model.description.TextData;
46 import eu.etaxonomy.cdm.model.location.NamedArea;
47 import eu.etaxonomy.cdm.model.location.Point;
48 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
49 import eu.etaxonomy.cdm.model.location.Country;
50 import eu.etaxonomy.cdm.model.media.Media;
51 import eu.etaxonomy.cdm.model.name.BotanicalName;
52 import eu.etaxonomy.cdm.model.name.Rank;
53 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
54 import eu.etaxonomy.cdm.model.occurrence.Collection;
55 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
56 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
57 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
58 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
59 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
60 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
61 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
62 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
63 import eu.etaxonomy.cdm.model.reference.Reference;
64 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
65 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
66
67
68
69 /**
70 * @author a.mueller
71 * @date 17.05.2010
72 *
73 */
74
75 public class DerivedUnitFacadeTest extends CdmTransactionalIntegrationTest {
76 private static final Logger logger = Logger.getLogger(DerivedUnitFacadeTest.class);
77
78 @SpringBeanByType
79 private IOccurrenceService service;
80
81 @SpringBeanByType
82 private ITermService termService;
83
84 @SpringBeanByType
85 private IUserService userService;
86
87
88 DerivedUnit specimen;
89 DerivationEvent derivationEvent;
90 FieldUnit fieldUnit;
91 GatheringEvent gatheringEvent;
92 Integer absoluteElevation = 10;
93 Integer absoluteElevationMaximum = 14;
94 AgentBase<?> collector = Team.NewInstance();
95 String collectingMethod = "Collection Method";
96 Double distanceToGround = 22.0;
97 Double distanceToSurface = 0.3;
98 Double distanceToSurfaceMax = 0.7;
99
100 ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
101 Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
102 String gatheringEventDescription = "A nice gathering description";
103 TimePeriod gatheringPeriod = TimePeriod.NewInstance(1888, 1889);
104
105 String fieldNumber = "15p23B";
106 String fieldNotes = "such a beautiful specimen";
107
108 Integer individualCount = 1;
109 DefinedTerm lifeStage = DefinedTerm.NewStageInstance("A wonderful stage", "stage", "st");
110 DefinedTerm sex = DefinedTerm.NewSexInstance("FemaleMale", "FM", "FM");
111 LanguageString locality = LanguageString.NewInstance("My locality",
112 Language.DEFAULT());
113
114 String accessionNumber = "888462535";
115 String catalogNumber = "UU879873590";
116 TaxonNameBase<?,?> taxonName = BotanicalName.NewInstance(Rank.GENUS(), "Abies",
117 null, null, null, null, null, null, null);
118 String collectorsNumber = "234589913A34";
119 Collection collection = Collection.NewInstance();
120 PreservationMethod preservationMethod = PreservationMethod.NewInstance(
121 "my prservation", null, null);
122
123 DerivedUnitFacade specimenFacade;
124
125 DerivedUnit collectionSpecimen;
126 GatheringEvent existingGatheringEvent;
127 DerivationEvent firstDerivationEvent;
128 FieldUnit firstFieldObject;
129 Media media1 = Media.NewInstance();
130
131 DerivedUnitFacade emptyFacade;
132
133 NamedArea country = Country.GERMANY();
134
135 // ****************************** SET UP **********************************/
136
137
138 /**
139 * @throws java.lang.Exception
140 */
141 @Before
142 public void setUp() throws Exception {
143
144 specimen = DerivedUnit.NewPreservedSpecimenInstance();
145
146 derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
147 specimen.setDerivedFrom(derivationEvent);
148 fieldUnit = FieldUnit.NewInstance();
149 fieldUnit.addDerivationEvent(derivationEvent);
150 gatheringEvent = GatheringEvent.NewInstance();
151 fieldUnit.setGatheringEvent(gatheringEvent);
152 gatheringEvent.setAbsoluteElevation(absoluteElevation);
153 gatheringEvent.setAbsoluteElevationMax(absoluteElevationMaximum);
154 gatheringEvent.setActor(collector);
155 gatheringEvent.setCollectingMethod(collectingMethod);
156 gatheringEvent.setDistanceToGround(distanceToGround);
157 gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
158 gatheringEvent.setDistanceToWaterSurfaceMax(distanceToSurfaceMax);
159 gatheringEvent.setExactLocation(exactLocation);
160 gatheringEvent.setDescription(gatheringEventDescription);
161 gatheringEvent.setCountry(country);
162
163 gatheringEvent.setTimeperiod(gatheringPeriod);
164 gatheringEvent.setLocality(locality);
165
166 fieldUnit.setFieldNumber(fieldNumber);
167 fieldUnit.setFieldNotes(fieldNotes);
168 fieldUnit.setIndividualCount(individualCount);
169 fieldUnit.setSex(sex);
170 fieldUnit.setLifeStage(lifeStage);
171
172 specimen.setAccessionNumber(accessionNumber);
173 specimen.setCatalogNumber(catalogNumber);
174 specimen.setStoredUnder(taxonName);
175 specimen.setCollection(collection);
176 specimen.setPreservation(preservationMethod);
177
178 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
179
180 // existing specimen with 2 derivation events in line
181 collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
182 DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
183 firstFieldObject = FieldUnit.NewInstance();
184
185 //TODO maybe we should define concrete event types here
186 DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();
187 DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance();
188 firstDerivationEvent = DerivationEvent.NewInstance();
189
190 collectionSpecimen.setDerivedFrom(lastDerivationEvent);
191
192 lastDerivationEvent.addOriginal(middleSpecimen);
193 middleSpecimen.setDerivedFrom(firstDerivationEvent);
194 firstDerivationEvent.addOriginal(firstFieldObject);
195 existingGatheringEvent = GatheringEvent.NewInstance();
196 firstFieldObject.setGatheringEvent(existingGatheringEvent);
197
198 // empty facade
199 emptyFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
200
201 }
202
203 // ****************************** TESTS*****************************/
204
205 @Ignore //doesn't run in suite
206 @Test
207 @DataSet("DerivedUnitFacadeTest.testSetFieldObjectImageGallery.xml")
208 @ExpectedDataSet
209 public void testSetFieldObjectImageGallery() {
210 UUID imageFeatureUuid = Feature.IMAGE().getUuid();
211 Feature imageFeature = (Feature) termService.find(imageFeatureUuid);
212
213 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
214 facade.innerDerivedUnit().setUuid(UUID.fromString("77af784f-931b-4857-be9a-48ccf31ed3f1"));
215 facade.setFieldNumber("12345");
216 Media media = Media.NewInstance(URI.create("www.abc.de"), 200, null,"jpeg");
217
218 try {
219 SpecimenDescription imageGallery = SpecimenDescription.NewInstance();
220 imageGallery.setDescribedSpecimenOrObservation(facade.innerFieldUnit());
221 imageGallery.setImageGallery(true);
222 TextData textData = TextData.NewInstance();
223 textData.setFeature(imageFeature);
224 imageGallery.addElement(textData);
225 textData.addMedia(media);
226 facade.setFieldObjectImageGallery(imageGallery);
227
228 } catch (DerivedUnitFacadeNotSupportedException e1) {
229 e1.printStackTrace();
230 Assert.fail(e1.getLocalizedMessage());
231 }
232 this.service.save(facade.innerDerivedUnit());
233
234 setComplete(); endTransaction();
235 // try {if (true){printDataSet(System.out, new
236 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
237 // ,"DERIVATIONEVENT",
238 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
239 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
240 // } catch(Exception e) { logger.warn(e);}
241
242 }
243
244 @Test
245 @Ignore
246 // TODO generally works but has id problems when running together with above
247 // test ()setFieldObjectImageGallery. Therefore set to ignore.
248 @DataSet("DerivedUnitFacadeTest.testSetDerivedUnitImageGallery.xml")
249 @ExpectedDataSet
250 public void testSetDerivedUnitImageGallery() {
251 // UUID specimenUUID =
252 // UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
253 // Specimen specimen = (Specimen)service.find(specimenUUID);
254 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
255 Media media = Media.NewInstance(URI.create("www.derivedUnitImage.de"),200, null, "png");
256
257 try {
258 SpecimenDescription imageGallery = SpecimenDescription
259 .NewInstance();
260 imageGallery.setDescribedSpecimenOrObservation(facade.innerDerivedUnit());
261 imageGallery.setImageGallery(true);
262 TextData textData = TextData.NewInstance();
263 imageGallery.addElement(textData);
264 textData.addMedia(media);
265 facade.setDerivedUnitImageGallery(imageGallery);
266
267 } catch (DerivedUnitFacadeNotSupportedException e1) {
268 e1.printStackTrace();
269 Assert.fail(e1.getLocalizedMessage());
270 }
271 this.service.save(facade.innerDerivedUnit());
272
273 // setComplete(); endTransaction();
274 // try {if (true){printDataSet(System.out, new
275 // String[]{"HIBERNATE_SEQUENCES","SPECIMENOROBSERVATIONBASE","SPECIMENOROBSERVATIONBASE_DERIVATIONEVENT"
276 // ,"DERIVATIONEVENT",
277 // "DESCRIPTIONBASE","DESCRIPTIONELEMENTBASE","DESCRIPTIONELEMENTBASE_MEDIA",
278 // "MEDIA", "MEDIAREPRESENTATION","MEDIAREPRESENTATIONPART"});}
279 // } catch(Exception e) { logger.warn(e);}
280
281
282 }
283
284 @Test
285 @DataSet
286 @Ignore // TODO generally works causes has id problems with following tests when running in suite
287 public void testGetFieldObjectImageGalleryBooleanPersisted() {
288 UUID specimenUUID = UUID
289 .fromString("25383fc8-789b-4eff-92d3-a770d0622351");
290 DerivedUnit specimen = (DerivedUnit) service.load(specimenUUID);
291 Assert.assertNotNull("Specimen should exist (persisted)", specimen);
292 try {
293 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);
294 SpecimenDescription imageGallery = facade.getFieldObjectImageGallery(true);
295 Assert.assertNotNull("Image gallery should exist", imageGallery);
296 Assert.assertEquals("UUID should be equal to the persisted uuid",
297 UUID.fromString("8cb772e9-1577-45c6-91ab-dbec1413c060"),
298 imageGallery.getUuid());
299 Assert.assertEquals("The image gallery should be flagged as such",true, imageGallery.isImageGallery());
300 Assert.assertEquals(
301 "There should be one TextData in image gallery", 1,
302 imageGallery.getElements().size());
303 List<Media> media = imageGallery.getElements().iterator().next().getMedia();
304 Assert.assertEquals("There should be 1 media", 1, media.size());
305 } catch (DerivedUnitFacadeNotSupportedException e) {
306 e.printStackTrace();
307 Assert.fail();
308 }
309 }
310
311 @Test
312 @DataSet
313 // @Ignore // TODO generally works causes has id problems with following tests when running in suite
314 public void testGetDerivedUnitImageGalleryBooleanPersisted() {
315 UUID specimenUUID = UUID.fromString("25383fc8-789b-4eff-92d3-a770d0622351");
316 DerivedUnit specimen = (DerivedUnit) service.load(specimenUUID);
317 Assert.assertNotNull("Specimen should exist (persisted)", specimen);
318 try {
319 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);
320 SpecimenDescription imageGallery = facade.getDerivedUnitImageGallery(true);
321 Assert.assertNotNull("Image gallery should exist", imageGallery);
322 Assert.assertEquals("UUID should be equal to the persisted uuid",
323 UUID.fromString("cb03acc4-8363-4020-aeef-ea8a8bcc0fe9"),
324 imageGallery.getUuid());
325 Assert.assertEquals("The image gallery should be flagged as such",
326 true, imageGallery.isImageGallery());
327 Assert.assertEquals(
328 "There should be one TextData in image gallery", 1,
329 imageGallery.getElements().size());
330 List<Media> media = imageGallery.getElements().iterator().next().getMedia();
331 Assert.assertEquals("There should be 1 media", 1, media.size());
332 } catch (DerivedUnitFacadeNotSupportedException e) {
333 e.printStackTrace();
334 Assert.fail();
335 }
336 }
337
338 @Test
339 public void testGetDerivedUnitImageGalleryBoolean() {
340 DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
341 try {
342 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(specimen);
343 SpecimenDescription imageGallery = facade.getDerivedUnitImageGallery(true);
344 Assert.assertNotNull("Image Gallery should have been created",imageGallery);
345 Assert.assertEquals("The image gallery should be flagged as such",true, imageGallery.isImageGallery());
346 } catch (DerivedUnitFacadeNotSupportedException e) {
347 e.printStackTrace();
348 Assert.fail();
349 }
350
351 }
352
353 /**
354 * Test method for
355 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
356 */
357 @Test
358 public void testNewInstance() {
359 Assert.assertNotNull("The specimen should have been created",
360 specimenFacade.innerDerivedUnit());
361 // ???
362 // Assert.assertNotNull("The derivation event should have been created",
363 // specimenFacade.getSpecimen().getDerivedFrom());
364 // Assert.assertNotNull("The field unit should have been created",
365 // specimenFacade.getFieldUnit());
366 // Assert.assertNotNull("The gathering event should have been created",
367 // specimenFacade.getGatheringEvent());
368 }
369
370 /**
371 * Test method for
372 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}
373 * .
374 */
375 @Test
376 public void testNewInstanceSpecimen() {
377 Assert.assertSame("Specimen should be same", specimen,
378 specimenFacade.innerDerivedUnit());
379 Assert.assertSame("Derivation event should be same", derivationEvent,
380 specimenFacade.innerDerivedUnit().getDerivedFrom());
381 Assert.assertSame("Field unit should be same", fieldUnit,
382 specimenFacade.innerFieldUnit());
383 Assert.assertSame("Gathering event should be same", gatheringEvent,
384 specimenFacade.innerGatheringEvent());
385
386 }
387
388 @Test
389 public void testGatheringEventIsConnectedToDerivedUnit() {
390 DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
391 DerivedUnitFacade specimenFacade;
392 try {
393 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
394 specimenFacade.setDistanceToGround(2.0);
395 FieldUnit specimenFieldUnit = (FieldUnit) specimen.getDerivedFrom().getOriginals().iterator().next();
396 Assert.assertSame(
397 "Facade gathering event and specimen gathering event should be the same",
398 specimenFacade.innerGatheringEvent(),
399 specimenFieldUnit.getGatheringEvent());
400 } catch (DerivedUnitFacadeNotSupportedException e) {
401 Assert.fail("An error should not occur in NewInstance()");
402 }
403 }
404
405 @Test
406 public void testNoGatheringEventAndFieldUnit() {
407 DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
408 DerivedUnitFacade specimenFacade;
409 try {
410 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
411 Assert.assertNull("No field unit should exists",
412 specimenFacade.innerFieldUnit());
413 } catch (DerivedUnitFacadeNotSupportedException e) {
414 Assert.fail("An error should not occur in NewInstance()");
415 }
416 }
417
418 @Test
419 public void testInititializeTextDataWithSupportTest() {
420 // TODO
421 DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance();
422 DerivedUnitFacade specimenFacade;
423 try {
424 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
425 specimenFacade.setEcology("Ecology");
426 String plantDescription = specimenFacade.getPlantDescription();
427 Assert.assertNull(
428 "No plantDescription should exist yet and no NPE should be thrown until now",
429 plantDescription);
430 } catch (DerivedUnitFacadeNotSupportedException e) {
431 Assert.fail("An error should not occur in NewInstance()");
432 }
433 }
434
435 @Test
436 public void testGetSetCountry() {
437 logger.warn("Not yet implemented");
438 }
439
440 /**
441 * Test method for
442 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
443 * .
444 */
445 @Test
446 public void testAddGetRemoveCollectingArea() {
447 String tdwgLabel = "GER";
448 NamedArea tdwgArea = termService.getAreaByTdwgAbbreviation(tdwgLabel);
449 NamedArea newCollectingArea = NamedArea.NewInstance("A nice area",
450 "nice", "n");
451 specimenFacade.addCollectingArea(newCollectingArea);
452 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade
453 .getCollectingAreas().size());
454 Assert.assertSame("Areas should be same", newCollectingArea,
455 specimenFacade.innerFieldUnit().getGatheringEvent()
456 .getCollectingAreas().iterator().next());
457 specimenFacade.addCollectingArea(tdwgArea);
458 Assert.assertEquals("Exactly 2 areas must exist", 2, specimenFacade
459 .getCollectingAreas().size());
460 specimenFacade.removeCollectingArea(newCollectingArea);
461 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade
462 .getCollectingAreas().size());
463 NamedArea remainingArea = specimenFacade.getCollectingAreas()
464 .iterator().next();
465 Assert.assertEquals("Areas should be same", tdwgArea, remainingArea);
466 specimenFacade.removeCollectingArea(tdwgArea);
467 Assert.assertEquals("No area should remain", 0, specimenFacade
468 .getCollectingAreas().size());
469 }
470
471 /**
472 * Test method for
473 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}
474 * .
475 */
476 @Test
477 public void testAddCollectingAreas() {
478 NamedArea firstArea = NamedArea.NewInstance("A nice area", "nice", "n");
479 Assert.assertEquals("No area must exist", 0, specimenFacade.getCollectingAreas().size());
480 specimenFacade.addCollectingArea(firstArea);
481 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade.getCollectingAreas().size());
482
483 String tdwgLabel = "GER";
484 NamedArea tdwgArea = termService.getAreaByTdwgAbbreviation(tdwgLabel);
485 NamedArea secondArea = NamedArea.NewInstance("A nice area", "nice", "n");
486
487 java.util.Collection<NamedArea> areaCollection = new HashSet<NamedArea>();
488 areaCollection.add(secondArea);
489 areaCollection.add(tdwgArea);
490 specimenFacade.addCollectingAreas(areaCollection);
491 Assert.assertEquals("Exactly 3 areas must exist", 3, specimenFacade
492 .getCollectingAreas().size());
493
494 }
495
496 /**
497 * Test method for getting and setting absolute elevation.
498 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}
499 * .
500 */
501 @Test
502 public void testGetSetAbsoluteElevation() {
503 Assert.assertEquals("Absolute elevation must be same",absoluteElevation, specimenFacade.getAbsoluteElevation());
504 specimenFacade.setAbsoluteElevation(400);
505 Assert.assertEquals("Absolute elevation must be 400",Integer.valueOf(400), specimenFacade.getAbsoluteElevation());
506 }
507
508 /**
509 * Test method for
510 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}
511 * .
512 */
513 @Test
514 public void testGetSetAbsoluteElevationMaximum() {
515 Assert.assertEquals("Absolute elevation must be same",absoluteElevation, specimenFacade.getAbsoluteElevation());
516 Assert.assertEquals("Absolute elevation maximum must be same",absoluteElevationMaximum, specimenFacade.getAbsoluteElevationMaximum());
517 specimenFacade.setAbsoluteElevationMax(4);
518 Assert.assertEquals("Absolute elevation maximum must be 4", Integer.valueOf(4), specimenFacade.getAbsoluteElevationMaximum());
519 Assert.assertEquals("Absolute elevation must be same",absoluteElevation, specimenFacade.getAbsoluteElevation());
520
521 }
522
523 @Test
524 public void testGetSetAbsoluteElevationRange() {
525 Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());
526 Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());
527
528 specimenFacade.setAbsoluteElevationRange(30, 36);
529 Assert.assertEquals("", Integer.valueOf(36),specimenFacade.getAbsoluteElevationMaximum());
530 Assert.assertEquals("", Integer.valueOf(30),specimenFacade.getAbsoluteElevation());
531 Assert.assertEquals("", "30" + UTF8.EN_DASH_SPATIUM + "36",specimenFacade.absoluteElevationToString());
532 Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationText());
533
534 specimenFacade.setAbsoluteElevationRange(30, 35);
535 Assert.assertEquals("Odd range should not throw an exception anymore", String.format("30%s35", UTF8.EN_DASH_SPATIUM),specimenFacade.absoluteElevationToString());
536
537 specimenFacade.setAbsoluteElevationRange(41, null);
538 Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
539 Assert.assertEquals("", Integer.valueOf(41),specimenFacade.getAbsoluteElevation());
540 Assert.assertEquals("", Integer.valueOf(41),specimenFacade.getAbsoluteElevation());
541 Assert.assertNull("", specimenFacade.getAbsoluteElevationText());
542 Assert.assertEquals("", "41",specimenFacade.absoluteElevationToString());
543
544 specimenFacade.setAbsoluteElevationRange(null, null);
545 Assert.assertNull("", specimenFacade.getAbsoluteElevation());
546 Assert.assertNull("", specimenFacade.getAbsoluteElevationMaximum());
547 Assert.assertNull("", specimenFacade.absoluteElevationToString());
548
549 }
550
551 @Test
552 public void testGetSetAbsoluteElevationText() {
553 Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());
554 Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());
555 Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationText());
556
557 String elevText = "approx. 30 - 35";
558 specimenFacade.setAbsoluteElevationText(elevText);
559 Assert.assertEquals("", absoluteElevation, specimenFacade.getAbsoluteElevation());
560 Assert.assertEquals("", absoluteElevationMaximum,specimenFacade.getAbsoluteElevationMaximum());
561 Assert.assertEquals("", elevText,specimenFacade.absoluteElevationToString());
562
563 specimenFacade.setAbsoluteElevationRange(30, 35);
564 Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());
565 Assert.assertEquals("", Integer.valueOf(30), specimenFacade.getAbsoluteElevation());
566 Assert.assertEquals("", Integer.valueOf(35),specimenFacade.getAbsoluteElevationMaximum());
567
568
569 specimenFacade.setAbsoluteElevationRange(41, null);
570 Assert.assertEquals("ToString should not change by setting range if text is set", elevText,specimenFacade.absoluteElevationToString());
571 Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());
572 Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
573
574
575 specimenFacade.setAbsoluteElevationText(null);
576 Assert.assertNull("", specimenFacade.getAbsoluteElevationText());
577 Assert.assertEquals("ToString should change by setting text to null", "41",specimenFacade.absoluteElevationToString());
578 Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());
579 Assert.assertEquals("", null,specimenFacade.getAbsoluteElevationMaximum());
580 }
581
582
583 /**
584 */
585 @Test
586 public void testGetSetCollector() {
587 Assert.assertNotNull("Collector must not be null",
588 specimenFacade.getCollector());
589 Assert.assertEquals("Collector must be same", collector,
590 specimenFacade.getCollector());
591 specimenFacade.setCollector(null);
592 Assert.assertNull("Collector must be null",
593 specimenFacade.getCollector());
594 }
595
596 /**
597 * Test method for
598 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}
599 * .
600 */
601 @Test
602 public void testGetSetCollectingMethod() {
603 Assert.assertEquals("Collecting method must be same", collectingMethod,
604 specimenFacade.getCollectingMethod());
605 specimenFacade.setCollectingMethod("new method");
606 Assert.assertEquals("Collecting method must be 'new method'",
607 "new method", specimenFacade.getCollectingMethod());
608 }
609
610 /**
611 * Test method for
612 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}
613 * .
614 */
615 @Test
616 public void testGetSetDistanceToGround() {
617 Assert.assertEquals("Distance to ground must be same",distanceToGround, specimenFacade.getDistanceToGround());
618 specimenFacade.setDistanceToGround(5.0);
619 Assert.assertEquals("Distance to ground must be 5", Double.valueOf(5), specimenFacade.getDistanceToGround());
620 }
621
622 /**
623 * Test method for
624 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}
625 * .
626 */
627 @Test
628 public void testGetDistanceToWaterSurface() {
629 Assert.assertEquals("Distance to surface must be same", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
630 specimenFacade.setDistanceToWaterSurface(6.0);
631 Assert.assertEquals("Distance to surface must be 6", Double.valueOf(6), specimenFacade.getDistanceToWaterSurface());
632 // empty facade tests
633 Assert.assertNull("Empty facace must not have any gathering values", emptyFacade.getDistanceToWaterSurface());
634 emptyFacade.setDistanceToWaterSurface(13.0);
635 Assert.assertNotNull("Field unit must exist if distance to water exists", emptyFacade.getFieldUnit(false));
636 Assert.assertNotNull("Gathering event must exist if distance to water exists", emptyFacade.getGatheringEvent(false));
637 FieldUnit specimenFieldUnit = (FieldUnit) emptyFacade
638 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
639 Assert.assertSame("Gathering event of facade and of specimen must be the same",
640 specimenFieldUnit.getGatheringEvent(), emptyFacade.getGatheringEvent(false));
641 }
642
643 @Test
644 public void testGetSetDistanceToWaterText() {
645 Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
646 Assert.assertEquals("", distanceToSurfaceMax ,specimenFacade.getDistanceToWaterSurfaceMax());
647 Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceText());
648
649 String distText = "approx. 0.3 - 0.6";
650 specimenFacade.setDistanceToWaterSurfaceText(distText);
651 Assert.assertEquals("", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
652 Assert.assertEquals("", distanceToSurfaceMax,specimenFacade.getDistanceToWaterSurfaceMax());
653 Assert.assertEquals("", distText,specimenFacade.distanceToWaterSurfaceToString());
654
655 specimenFacade.setDistanceToWaterSurfaceRange(0.6, 1.4);
656 Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());
657 Assert.assertEquals("", Double.valueOf(0.6), specimenFacade.getDistanceToWaterSurface());
658 Assert.assertEquals("", Double.valueOf(1.4),specimenFacade.getDistanceToWaterSurfaceMax());
659
660 specimenFacade.setDistanceToWaterSurfaceRange(41.2, null);
661 Assert.assertEquals("ToString should not change by setting range if text is set", distText,specimenFacade.distanceToWaterSurfaceToString());
662 Assert.assertEquals("", Double.valueOf(41.2), specimenFacade.getDistanceToWaterSurface());
663 Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceMax());
664
665 specimenFacade.setDistanceToWaterSurfaceText(null);
666 Assert.assertNull("", specimenFacade.getDistanceToWaterSurfaceText());
667 Assert.assertEquals("ToString should change by setting text to null", "41.2",specimenFacade.distanceToWaterSurfaceToString());
668 Assert.assertEquals("", Double.valueOf(41.2), specimenFacade.getDistanceToWaterSurface());
669 Assert.assertEquals("", null,specimenFacade.getDistanceToWaterSurfaceMax());
670 }
671
672
673 /**
674 * Test method for
675 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
676 */
677 @Test
678 public void testGetSetExactLocation() {
679 Assert.assertNotNull("Exact location must not be null",
680 specimenFacade.getExactLocation());
681 Assert.assertEquals("Exact location must be same", exactLocation,
682 specimenFacade.getExactLocation());
683 specimenFacade.setExactLocation(null);
684 Assert.assertNull("Exact location must be null",
685 specimenFacade.getExactLocation());
686 }
687
688 @Test
689 public void testSetExactLocationByParsing() {
690 Point point1;
691 try {
692 specimenFacade.setExactLocationByParsing("112\u00B034'20\"W",
693 "34\u00B030,34'N", null, null);
694 point1 = specimenFacade.getExactLocation();
695 Assert.assertNotNull("", point1.getLatitude());
696 System.out.println(point1.getLatitude().toString());
697 Assert.assertTrue("",
698 point1.getLatitude().toString().startsWith("34.505"));
699 System.out.println(point1.getLongitude().toString());
700 Assert.assertTrue("",
701 point1.getLongitude().toString().startsWith("-112.5722"));
702
703 } catch (ParseException e) {
704 Assert.fail("No parsing error should occur");
705 }
706 }
707
708 /**
709 * Test method for
710 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}
711 * .
712 */
713 @Test
714 public void testGetSetGatheringEventDescription() {
715 Assert.assertEquals("Gathering event description must be same",
716 gatheringEventDescription,
717 specimenFacade.getGatheringEventDescription());
718 specimenFacade.setGatheringEventDescription("new description");
719 Assert.assertEquals(
720 "Gathering event description must be 'new description' now",
721 "new description",
722 specimenFacade.getGatheringEventDescription());
723 }
724
725 /**
726 * Test method for
727 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
728 */
729 @Test
730 public void testGetTimeperiod() {
731 Assert.assertNotNull("Gathering period must not be null", specimenFacade.getGatheringPeriod());
732 Assert.assertFalse("Gathering period must not be empty", specimenFacade.getGatheringPeriod().isEmpty());
733 Assert.assertEquals("Gathering period must be same", gatheringPeriod, specimenFacade.getGatheringPeriod());
734 specimenFacade.setGatheringPeriod(null);
735 Assert.assertTrue("Gathering period must be null", specimenFacade.getGatheringPeriod().isEmpty());
736 }
737
738 @Test
739 public void testHasFieldObject() throws SecurityException,
740 NoSuchFieldException, IllegalArgumentException,
741 IllegalAccessException {
742 // this test depends on the current implementation of SpecimenFacade. In
743 // future
744 // field unit may not be initialized from the beginning. Than the
745 // following
746 // assert should be set to assertNull
747 Assert.assertTrue("field object should not be null (depends on specimen facade initialization !!)",
748 specimenFacade.hasFieldObject());
749
750 Field fieldUnitField = DerivedUnitFacade.class
751 .getDeclaredField("fieldUnit");
752 fieldUnitField.setAccessible(true);
753 fieldUnitField.set(specimenFacade, null);
754 Assert.assertFalse("The field unit should be null now",
755 specimenFacade.hasFieldObject());
756
757 specimenFacade.setDistanceToGround(33.0);
758 Assert.assertTrue(
759 "The field unit should have been created again",
760 specimenFacade.hasFieldObject());
761 }
762
763 /**
764 * Test method for
765 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
766 * .
767 */
768 @Test
769 public void testAddGetRemoveFieldObjectDefinition() {
770 Assert.assertEquals("There should be no definition yet", 0,
771 specimenFacade.getFieldObjectDefinition().size());
772 specimenFacade.addFieldObjectDefinition("Tres interesant",
773 Language.FRENCH());
774 Assert.assertEquals("There should be exactly one definition", 1,
775 specimenFacade.getFieldObjectDefinition().size());
776 Assert.assertEquals(
777 "The French definition should be 'Tres interesant'",
778 "Tres interesant", specimenFacade.getFieldObjectDefinition()
779 .get(Language.FRENCH()).getText());
780 Assert.assertEquals(
781 "The French definition should be 'Tres interesant'",
782 "Tres interesant",
783 specimenFacade.getFieldObjectDefinition(Language.FRENCH()));
784 specimenFacade.addFieldObjectDefinition("Sehr interessant",
785 Language.GERMAN());
786 Assert.assertEquals("There should be exactly 2 definition", 2,
787 specimenFacade.getFieldObjectDefinition().size());
788 specimenFacade.removeFieldObjectDefinition(Language.FRENCH());
789 Assert.assertEquals("There should remain exactly 1 definition", 1,
790 specimenFacade.getFieldObjectDefinition().size());
791 Assert.assertEquals(
792 "The remaining German definition should be 'Sehr interessant'",
793 "Sehr interessant",
794 specimenFacade.getFieldObjectDefinition(Language.GERMAN()));
795 specimenFacade.removeFieldObjectDefinition(Language.GERMAN());
796 Assert.assertEquals("There should remain no definition", 0,
797 specimenFacade.getFieldObjectDefinition().size());
798 }
799
800 /**
801 * Test method for
802 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
803 * .
804 */
805 @Test
806 public void testAddGetHasRemoveFieldObjectMedia() {
807 Assert.assertFalse("There should be no image gallery yet",
808 specimenFacade.hasFieldObjectImageGallery());
809 Assert.assertFalse("There should be no specimen image gallery either",
810 specimenFacade.hasDerivedUnitImageGallery());
811
812 List<Media> media = specimenFacade.getFieldObjectMedia();
813 Assert.assertFalse("There should still not be an image gallery now",
814 specimenFacade.hasFieldObjectImageGallery());
815 Assert.assertEquals("There should be no media yet in the gallery", 0,
816 media.size());
817
818 Media media1 = Media.NewInstance();
819 specimenFacade.addFieldObjectMedia(media1);
820 Assert.assertEquals("There should be exactly one specimen media", 1,
821 specimenFacade.getFieldObjectMedia().size());
822 Assert.assertEquals("The only media should be media 1", media1,
823 specimenFacade.getFieldObjectMedia().get(0));
824 Assert.assertFalse(
825 "There should still no specimen image gallery exist",
826 specimenFacade.hasDerivedUnitImageGallery());
827
828 Media media2 = Media.NewInstance();
829 specimenFacade.addFieldObjectMedia(media2);
830 Assert.assertEquals("There should be exactly 2 specimen media", 2,
831 specimenFacade.getFieldObjectMedia().size());
832 Assert.assertEquals("The first media should be media1", media1,
833 specimenFacade.getFieldObjectMedia().get(0));
834 Assert.assertEquals("The second media should be media2", media2,
835 specimenFacade.getFieldObjectMedia().get(1));
836
837 specimenFacade.removeFieldObjectMedia(media1);
838 Assert.assertEquals("There should be exactly one specimen media", 1,
839 specimenFacade.getFieldObjectMedia().size());
840 Assert.assertEquals("The only media should be media2", media2,
841 specimenFacade.getFieldObjectMedia().get(0));
842
843 specimenFacade.removeFieldObjectMedia(media1);
844 Assert.assertEquals("There should still be exactly one specimen media",
845 1, specimenFacade.getFieldObjectMedia().size());
846
847 specimenFacade.removeFieldObjectMedia(media2);
848 Assert.assertEquals("There should remain no media in the gallery", 0,
849 media.size());
850
851 }
852
853 /**
854 * Test method for
855 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
856 * .
857 */
858 @Test
859 public void testGetSetEcology() {
860 Assert.assertNotNull(
861 "An empty ecology data should be created when calling getEcology()",
862 specimenFacade.getEcologyAll());
863 Assert.assertEquals(
864 "An empty ecology data should be created when calling getEcology()",
865 0, specimenFacade.getEcologyAll().size());
866 specimenFacade.setEcology("Tres jolie ici", Language.FRENCH());
867 Assert.assertEquals("Ecology data should exist for 1 language", 1,
868 specimenFacade.getEcologyAll().size());
869 Assert.assertEquals(
870 "Ecology data should be 'Tres jolie ici' for French",
871 "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
872 Assert.assertNull(
873 "Ecology data should be null for the default language",
874 specimenFacade.getEcology());
875 specimenFacade.setEcology("Nice here");
876 Assert.assertEquals("Ecology data should exist for 2 languages", 2,
877 specimenFacade.getEcologyAll().size());
878 Assert.assertEquals("Ecology data should be 'Tres jolie ici'",
879 "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
880 Assert.assertEquals(
881 "Ecology data should be 'Nice here' for the default language",
882 "Nice here", specimenFacade.getEcology());
883 Assert.assertEquals("Ecology data should be 'Nice here' for english",
884 "Nice here", specimenFacade.getEcology());
885
886 specimenFacade.setEcology("Vert et rouge", Language.FRENCH());
887 Assert.assertEquals("Ecology data should exist for 2 languages", 2,
888 specimenFacade.getEcologyAll().size());
889 Assert.assertEquals("Ecology data should be 'Vert et rouge'",
890 "Vert et rouge", specimenFacade.getEcology(Language.FRENCH()));
891 Assert.assertEquals(
892 "Ecology data should be 'Nice here' for the default language",
893 "Nice here", specimenFacade.getEcology());
894
895 specimenFacade.setEcology(null, Language.FRENCH());
896 Assert.assertEquals("Ecology data should exist for 1 languages", 1,
897 specimenFacade.getEcologyAll().size());
898 Assert.assertEquals(
899 "Ecology data should be 'Nice here' for the default language",
900 "Nice here", specimenFacade.getEcology());
901 Assert.assertNull("Ecology data should be 'null' for French",
902 specimenFacade.getEcology(Language.FRENCH()));
903
904 specimenFacade.removeEcology(null);
905 Assert.assertEquals("There should be no ecology left", 0,
906 specimenFacade.getEcologyAll().size());
907 Assert.assertNull("Ecology data should be 'null' for default language",
908 specimenFacade.getEcology());
909
910 }
911
912 /**
913 * Test method for
914 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}
915 * .
916 */
917 @Test
918 public void testGetSetPlantDescription() {
919 Assert.assertNotNull(
920 "An empty plant description data should be created when calling getPlantDescriptionAll()",
921 specimenFacade.getPlantDescriptionAll());
922 Assert.assertEquals(
923 "An empty plant description data should be created when calling getPlantDescription()",
924 0, specimenFacade.getPlantDescriptionAll().size());
925 specimenFacade.setPlantDescription("bleu", Language.FRENCH());
926 Assert.assertEquals(
927 "Plant description data should exist for 1 language", 1,
928 specimenFacade.getPlantDescriptionAll().size());
929 Assert.assertEquals(
930 "Plant description data should be 'bleu' for French", "bleu",
931 specimenFacade.getPlantDescription(Language.FRENCH()));
932 Assert.assertNull(
933 "Plant description data should be null for the default language",
934 specimenFacade.getPlantDescription());
935 specimenFacade.setPlantDescription("Nice here");
936 Assert.assertEquals(
937 "Plant description data should exist for 2 languages", 2,
938 specimenFacade.getPlantDescriptionAll().size());
939 Assert.assertEquals("Plant description data should be 'bleu'", "bleu",
940 specimenFacade.getPlantDescription(Language.FRENCH()));
941 Assert.assertEquals(
942 "Plant description data should be 'Nice here' for the default language",
943 "Nice here", specimenFacade.getPlantDescription());
944 Assert.assertEquals(
945 "Plant description data should be 'Nice here' for english",
946 "Nice here", specimenFacade.getPlantDescription());
947
948 specimenFacade.setPlantDescription("Vert et rouge", Language.FRENCH());
949 Assert.assertEquals(
950 "Plant description data should exist for 2 languages", 2,
951 specimenFacade.getPlantDescriptionAll().size());
952 Assert.assertEquals("Plant description data should be 'Vert et rouge'",
953 "Vert et rouge",
954 specimenFacade.getPlantDescription(Language.FRENCH()));
955 Assert.assertEquals(
956 "Plant description data should be 'Nice here' for the default language",
957 "Nice here", specimenFacade.getPlantDescription());
958
959 specimenFacade.setPlantDescription(null, Language.FRENCH());
960 Assert.assertEquals(
961 "Plant description data should exist for 1 languages", 1,
962 specimenFacade.getPlantDescriptionAll().size());
963 Assert.assertEquals(
964 "Plant description data should be 'Nice here' for the default language",
965 "Nice here", specimenFacade.getPlantDescription());
966 Assert.assertNull("Plant description data should be 'null' for French",
967 specimenFacade.getPlantDescription(Language.FRENCH()));
968
969 // test interference with ecology
970 specimenFacade.setEcology("Tres jolie ici", Language.FRENCH());
971 Assert.assertEquals("Ecology data should exist for 1 language", 1,
972 specimenFacade.getEcologyAll().size());
973 Assert.assertEquals(
974 "Ecology data should be 'Tres jolie ici' for French",
975 "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
976 Assert.assertNull(
977 "Ecology data should be null for the default language",
978 specimenFacade.getEcology());
979
980 // repeat above test
981 Assert.assertEquals(
982 "Plant description data should exist for 1 languages", 1,
983 specimenFacade.getPlantDescriptionAll().size());
984 Assert.assertEquals(
985 "Plant description data should be 'Nice here' for the default language",
986 "Nice here", specimenFacade.getPlantDescription());
987 Assert.assertNull("Plant description data should be 'null' for French",
988 specimenFacade.getPlantDescription(Language.FRENCH()));
989
990 specimenFacade.removePlantDescription(null);
991 Assert.assertEquals("There should be no plant description left", 0,
992 specimenFacade.getPlantDescriptionAll().size());
993 Assert.assertNull(
994 "Plant description data should be 'null' for default language",
995 specimenFacade.getPlantDescription());
996
997 }
998
999 /**
1000 * Test method for
1001 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
1002 */
1003 @Test
1004 public void testGetSetFieldNumber() {
1005 Assert.assertEquals("Field number must be same", fieldNumber,
1006 specimenFacade.getFieldNumber());
1007 specimenFacade.setFieldNumber("564AB");
1008 Assert.assertEquals("New field number must be '564AB'", "564AB",
1009 specimenFacade.getFieldNumber());
1010 // empty facade tests
1011 Assert.assertNull("Empty facace must not have any field value",
1012 emptyFacade.getFieldNumber());
1013 emptyFacade.setFieldNumber("1256A");
1014 Assert.assertNotNull(
1015 "Field unit must exist if field number exists",
1016 emptyFacade.getFieldUnit(false));
1017 FieldUnit specimenFieldUnit = (FieldUnit) emptyFacade
1018 .innerDerivedUnit().getDerivedFrom().getOriginals().iterator()
1019 .next();
1020 Assert.assertSame(
1021 "Field unit of facade and of specimen must be the same",
1022 specimenFieldUnit,
1023 emptyFacade.getFieldUnit(false));
1024 Assert.assertEquals("1256A", emptyFacade.getFieldNumber());
1025 }
1026
1027 /**
1028 * Test method for
1029 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
1030 */
1031 @Test
1032 public void testGetSetFieldNotes() {
1033 Assert.assertEquals("Field notes must be same", fieldNotes,
1034 specimenFacade.getFieldNotes());
1035 specimenFacade.setFieldNotes("A completely new info");
1036 Assert.assertEquals("New field note must be 'A completely new info'",
1037 "A completely new info", specimenFacade.getFieldNotes());
1038 }
1039
1040 /**
1041 * Test method for
1042 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}
1043 * .
1044 */
1045 @Test
1046 @Ignore // #######DerivationEvent ---------------------------------------- 1
1047 public void testSetGatheringEvent() {
1048 GatheringEvent newGatheringEvent = GatheringEvent.NewInstance();
1049 newGatheringEvent.setDistanceToGround(43.0);
1050 Assert.assertFalse("The initial distance to ground should not be 43",
1051 specimenFacade.getDistanceToGround() == 43.0);
1052 specimenFacade.setGatheringEvent(newGatheringEvent);
1053 Assert.assertTrue("The final distance to ground should be 43",
1054 specimenFacade.getDistanceToGround() == 43.0);
1055 Assert.assertSame(
1056 "The new gathering event should be 'newGatheringEvent'",
1057 newGatheringEvent, specimenFacade.innerGatheringEvent());
1058 }
1059
1060 /**
1061 * Test method for
1062 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerGatheringEvent()}
1063 * .
1064 */
1065 @Test
1066 public void testGetGatheringEvent() {
1067 Assert.assertNotNull("Gathering event must not be null",
1068 specimenFacade.innerGatheringEvent());
1069 Assert.assertEquals(
1070 "Gathering event must be field unit's gathering event",
1071 specimenFacade.innerFieldUnit().getGatheringEvent(),
1072 specimenFacade.innerGatheringEvent());
1073 }
1074
1075 /**
1076 * Test method for
1077 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}
1078 * .
1079 */
1080 @Test
1081 public void testGetSetIndividualCount() {
1082 Assert.assertEquals("Individual count must be same", individualCount,
1083 specimenFacade.getIndividualCount());
1084 specimenFacade.setIndividualCount(4);
1085 Assert.assertEquals("New individual count must be '4'",
1086 Integer.valueOf(4), specimenFacade.getIndividualCount());
1087
1088 }
1089
1090 /**
1091 * Test method for
1092 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
1093 */
1094 @Test
1095 public void testGetSetLifeStage() {
1096 Assert.assertNotNull("Life stage must not be null",
1097 specimenFacade.getLifeStage());
1098 Assert.assertEquals("Life stage must be same", lifeStage,
1099 specimenFacade.getLifeStage());
1100 specimenFacade.setLifeStage(null);
1101 Assert.assertNull("Life stage must be null",
1102 specimenFacade.getLifeStage());
1103 }
1104
1105 /**
1106 * Test method for
1107 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
1108 */
1109 @Test
1110 public void testGetSetSex() {
1111 Assert.assertNotNull("Sex must not be null", specimenFacade.getSex());
1112 Assert.assertEquals("Sex must be same", sex, specimenFacade.getSex());
1113 specimenFacade.setSex(null);
1114 Assert.assertNull("Sex must be null", specimenFacade.getSex());
1115 }
1116
1117 /**
1118 * Test method for
1119 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
1120 */
1121 @Test
1122 public void testGetSetLocality() {
1123 Assert.assertEquals("Locality must be same", locality,
1124 specimenFacade.getLocality());
1125 specimenFacade.setLocality("A completely new place", Language.FRENCH());
1126 Assert.assertEquals("New locality must be 'A completely new place'",
1127 "A completely new place", specimenFacade.getLocalityText());
1128 Assert.assertEquals("New locality language must be French",
1129 Language.FRENCH(), specimenFacade.getLocalityLanguage());
1130 specimenFacade.setLocality("Another place");
1131 Assert.assertEquals("New locality must be 'Another place'",
1132 "Another place", specimenFacade.getLocalityText());
1133 Assert.assertEquals("New locality language must be default",
1134 Language.DEFAULT(), specimenFacade.getLocalityLanguage());
1135 }
1136
1137 /**
1138 * Test method for
1139 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}
1140 * .
1141 */
1142 @Test
1143 public void testAddGetRemoveSpecimenDefinition() {
1144 Assert.assertEquals("There should be no definition yet", 0,
1145 specimenFacade.getDerivedUnitDefinitions().size());
1146 specimenFacade.addDerivedUnitDefinition("Tres interesant",
1147 Language.FRENCH());
1148 Assert.assertEquals("There should be exactly one definition", 1,
1149 specimenFacade.getDerivedUnitDefinitions().size());
1150 Assert.assertEquals(
1151 "The French definition should be 'Tres interesant'",
1152 "Tres interesant", specimenFacade.getDerivedUnitDefinitions()
1153 .get(Language.FRENCH()).getText());
1154 Assert.assertEquals(
1155 "The French definition should be 'Tres interesant'",
1156 "Tres interesant",
1157 specimenFacade.getDerivedUnitDefinition(Language.FRENCH()));
1158 specimenFacade.addDerivedUnitDefinition("Sehr interessant",
1159 Language.GERMAN());
1160 Assert.assertEquals("There should be exactly 2 definition", 2,
1161 specimenFacade.getDerivedUnitDefinitions().size());
1162 specimenFacade.removeDerivedUnitDefinition(Language.FRENCH());
1163 Assert.assertEquals("There should remain exactly 1 definition", 1,
1164 specimenFacade.getDerivedUnitDefinitions().size());
1165 Assert.assertEquals(
1166 "The remaining German definition should be 'Sehr interessant'",
1167 "Sehr interessant",
1168 specimenFacade.getDerivedUnitDefinition(Language.GERMAN()));
1169 specimenFacade.removeDerivedUnitDefinition(Language.GERMAN());
1170 Assert.assertEquals("There should remain no definition", 0,
1171 specimenFacade.getDerivedUnitDefinitions().size());
1172 }
1173
1174 /**
1175 * Test method for
1176 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1177 * .
1178 */
1179 @Test
1180 public void testAddGetRemoveDetermination() {
1181 Assert.assertEquals("There should be no determination yet", 0,
1182 specimenFacade.getDeterminations().size());
1183 DeterminationEvent determinationEvent1 = DeterminationEvent
1184 .NewInstance();
1185 specimenFacade.addDetermination(determinationEvent1);
1186 Assert.assertEquals("There should be exactly one determination", 1,
1187 specimenFacade.getDeterminations().size());
1188 Assert.assertEquals("The only determination should be determination 1",
1189 determinationEvent1, specimenFacade.getDeterminations()
1190 .iterator().next());
1191
1192 DeterminationEvent determinationEvent2 = DeterminationEvent
1193 .NewInstance();
1194 specimenFacade.addDetermination(determinationEvent2);
1195 Assert.assertEquals("There should be exactly 2 determinations", 2,
1196 specimenFacade.getDeterminations().size());
1197 specimenFacade.removeDetermination(determinationEvent1);
1198
1199 Assert.assertEquals("There should remain exactly 1 determination", 1,
1200 specimenFacade.getDeterminations().size());
1201 Assert.assertEquals(
1202 "The remaining determinations should be determination 2",
1203 determinationEvent2, specimenFacade.getDeterminations()
1204 .iterator().next());
1205
1206 specimenFacade.removeDetermination(determinationEvent1);
1207 Assert.assertEquals("There should remain exactly 1 determination", 1,
1208 specimenFacade.getDeterminations().size());
1209
1210 specimenFacade.removeDetermination(determinationEvent2);
1211 Assert.assertEquals("There should remain no definition", 0,
1212 specimenFacade.getDerivedUnitDefinitions().size());
1213
1214 }
1215
1216
1217 /**
1218 * Test method for
1219 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}
1220 * .
1221 */
1222 @Test
1223 public void testPreferredOtherDeterminations() {
1224 Assert.assertEquals("There should be no determination yet", 0,
1225 specimenFacade.getDeterminations().size());
1226 DeterminationEvent determinationEvent1 = DeterminationEvent.NewInstance();
1227 specimenFacade.setPreferredDetermination(determinationEvent1);
1228
1229 Assert.assertEquals("There should be exactly one determination", 1,
1230 specimenFacade.getDeterminations().size());
1231 Assert.assertEquals("The only determination should be determination 1",
1232 determinationEvent1, specimenFacade.getDeterminations()
1233 .iterator().next());
1234 Assert.assertEquals("determination 1 should be the preferred determination",
1235 determinationEvent1, specimenFacade.getPreferredDetermination());
1236 Assert.assertEquals("There should be no 'non preferred' determination", 0,
1237 specimenFacade.getOtherDeterminations().size());
1238
1239
1240
1241 DeterminationEvent determinationEvent2 = DeterminationEvent.NewInstance();
1242 specimenFacade.addDetermination(determinationEvent2);
1243 Assert.assertEquals("There should be exactly 2 determinations", 2,
1244 specimenFacade.getDeterminations().size());
1245 Assert.assertEquals("determination 1 should be the preferred determination",
1246 determinationEvent1, specimenFacade.getPreferredDetermination());
1247 Assert.assertEquals("There should be one 'non preferred' determination", 1,
1248 specimenFacade.getOtherDeterminations().size());
1249 Assert.assertEquals("The only 'non preferred' determination should be determination 2",
1250 determinationEvent2, specimenFacade.getOtherDeterminations().iterator().next());
1251
1252
1253 DeterminationEvent determinationEvent3 = DeterminationEvent.NewInstance();
1254 specimenFacade.setPreferredDetermination(determinationEvent3);
1255 Assert.assertEquals("There should be exactly 3 determinations", 3,
1256 specimenFacade.getDeterminations().size());
1257 Assert.assertEquals("determination 3 should be the preferred determination",
1258 determinationEvent3, specimenFacade.getPreferredDetermination());
1259 Assert.assertEquals("There should be 2 'non preferred' determination", 2,
1260 specimenFacade.getOtherDeterminations().size());
1261 Assert.assertTrue("determination 1 should be contained in the set of 'non preferred' determinations",
1262 specimenFacade.getOtherDeterminations().contains(determinationEvent1));
1263 Assert.assertTrue("determination 2 should be contained in the set of 'non preferred' determinations",
1264 specimenFacade.getOtherDeterminations().contains(determinationEvent2));
1265
1266 }
1267
1268 /**
1269 * Test method for
1270 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}
1271 * .
1272 */
1273 @Test
1274 public void testAddGetHasRemoveSpecimenMedia() {
1275 Assert.assertFalse("There should be no image gallery yet",
1276 specimenFacade.hasDerivedUnitImageGallery());
1277 Assert.assertFalse(
1278 "There should be also no field object image gallery yet",
1279 specimenFacade.hasFieldObjectImageGallery());
1280
1281 List<Media> media = specimenFacade.getDerivedUnitMedia();
1282 Assert.assertFalse(
1283 "There should still not be an empty image gallery now",
1284 specimenFacade.hasDerivedUnitImageGallery());
1285 Assert.assertEquals("There should be no media yet in the gallery", 0,
1286 media.size());
1287
1288 Media media1 = Media.NewInstance();
1289 specimenFacade.addDerivedUnitMedia(media1);
1290 Assert.assertEquals("There should be exactly one specimen media", 1,
1291 specimenFacade.getDerivedUnitMedia().size());
1292 Assert.assertEquals("The only media should be media 1", media1,
1293 specimenFacade.getDerivedUnitMedia().get(0));
1294 Assert.assertFalse(
1295 "There should be still no field object image gallery",
1296 specimenFacade.hasFieldObjectImageGallery());
1297
1298 Media media2 = Media.NewInstance();
1299 specimenFacade.addDerivedUnitMedia(media2);
1300 Assert.assertEquals("There should be exactly 2 specimen media", 2,
1301 specimenFacade.getDerivedUnitMedia().size());
1302 Assert.assertEquals("The first media should be media1", media1,
1303 specimenFacade.getDerivedUnitMedia().get(0));
1304 Assert.assertEquals("The second media should be media2", media2,
1305 specimenFacade.getDerivedUnitMedia().get(1));
1306
1307 specimenFacade.removeDerivedUnitMedia(media1);
1308 Assert.assertEquals("There should be exactly one specimen media", 1,
1309 specimenFacade.getDerivedUnitMedia().size());
1310 Assert.assertEquals("The only media should be media2", media2,
1311 specimenFacade.getDerivedUnitMedia().get(0));
1312
1313 specimenFacade.removeDerivedUnitMedia(media1);
1314 Assert.assertEquals("There should still be exactly one specimen media",
1315 1, specimenFacade.getDerivedUnitMedia().size());
1316
1317 specimenFacade.removeDerivedUnitMedia(media2);
1318 Assert.assertEquals("There should remain no media in the gallery", 0,
1319 media.size());
1320 }
1321
1322 /**
1323 * Test method for
1324 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}
1325 * .
1326 */
1327 @Test
1328 public void testGetSetAccessionNumber() {
1329 Assert.assertEquals("Accession number must be same", accessionNumber,
1330 specimenFacade.getAccessionNumber());
1331 specimenFacade.setAccessionNumber("A12345693");
1332 Assert.assertEquals("New accession number must be 'A12345693'",
1333 "A12345693", specimenFacade.getAccessionNumber());
1334 }
1335
1336 /**
1337 * Test method for
1338 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
1339 */
1340 @Test
1341 public void testGetCatalogNumber() {
1342 Assert.assertEquals("Catalog number must be same", catalogNumber,
1343 specimenFacade.getCatalogNumber());
1344 specimenFacade.setCatalogNumber("B12345693");
1345 Assert.assertEquals("New catalog number must be 'B12345693'",
1346 "B12345693", specimenFacade.getCatalogNumber());
1347 }
1348
1349 /**
1350 * Test method for
1351 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
1352 */
1353 @Test
1354 public void testGetPreservation() {
1355 try {
1356 Assert.assertNotNull("Preservation method must not be null",
1357 specimenFacade.getPreservationMethod());
1358 Assert.assertEquals("Preservation method must be same",
1359 preservationMethod, specimenFacade.getPreservationMethod());
1360 specimenFacade.setPreservationMethod(null);
1361 Assert.assertNull("Preservation method must be null",
1362 specimenFacade.getPreservationMethod());
1363 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
1364 Assert.fail("Method not supported should not be thrown for a specimen");
1365 }
1366 specimenFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.Observation);
1367 try {
1368 specimenFacade.setPreservationMethod(preservationMethod);
1369 Assert.fail("Method not supported should be thrown for an observation on set preservation method");
1370
1371 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
1372 // ok
1373 }
1374 specimenFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.LivingSpecimen);
1375 try {
1376 specimenFacade.getPreservationMethod();
1377 Assert.fail("Method not supported should be thrown for a living being on get preservation method");
1378 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
1379 // ok
1380 }
1381
1382 }
1383
1384 /**
1385 * Test method for
1386 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
1387 */
1388 @Test
1389 public void testGetStoredUnder() {
1390 Assert.assertNotNull("Stored under name must not be null",
1391 specimenFacade.getStoredUnder());
1392 Assert.assertEquals("Stored under name must be same", taxonName,
1393 specimenFacade.getStoredUnder());
1394 specimenFacade.setStoredUnder(null);
1395 Assert.assertNull("Stored under name must be null",
1396 specimenFacade.getStoredUnder());
1397 }
1398
1399 // /**
1400 // * Test method for
1401 // * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}
1402 // * .
1403 // */
1404 // @Test
1405 // public void testGetSetCollectorsNumber() {
1406 // Assert.assertEquals("Collectors number must be same", collectorsNumber,
1407 // specimenFacade.getCollectorsNumber());
1408 // specimenFacade.setCollectorsNumber("C12345693");
1409 // Assert.assertEquals("New collectors number must be 'C12345693'",
1410 // "C12345693", specimenFacade.getCollectorsNumber());
1411 // }
1412
1413 /**
1414 * Test method for
1415 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
1416 */
1417 @Test
1418 public void testGetTitleCache() {
1419 Assert.assertNotNull(
1420 "The title cache should never return null if not protected",
1421 specimenFacade.getTitleCache());
1422 specimenFacade.setTitleCache(null, false);
1423 Assert.assertNotNull(
1424 "The title cache should never return null if not protected",
1425 specimenFacade.getTitleCache());
1426 }
1427
1428 /**
1429 * Test method for
1430 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}
1431 * .
1432 */
1433 @Test
1434 public void testSetTitleCache() {
1435 String testTitle = "Absdwk aksjlf";
1436 specimenFacade.setTitleCache(testTitle, true);
1437 Assert.assertEquals(
1438 "Protected title cache should returns the test title",
1439 testTitle, specimenFacade.getTitleCache());
1440 specimenFacade.setTitleCache(testTitle, false);
1441 Assert.assertFalse(
1442 "Unprotected title cache should not return the test title",
1443 testTitle.equals(specimenFacade.getTitleCache()));
1444 }
1445
1446 /**
1447 * Test method for
1448 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#innerDerivedUnit()}.
1449 */
1450 @Test
1451 public void testGetSpecimen() {
1452 Assert.assertEquals("Specimen must be same", specimen,
1453 specimenFacade.innerDerivedUnit());
1454 }
1455
1456 /**
1457 * Test method for
1458 * {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
1459 */
1460 @Test
1461 public void testGetSetCollection() {
1462 Assert.assertNotNull("Collection must not be null",
1463 specimenFacade.getCollection());
1464 Assert.assertEquals("Collection must be same", collection,
1465 specimenFacade.getCollection());
1466 specimenFacade.setCollection(null);
1467 Assert.assertNull("Collection must be null",
1468 specimenFacade.getCollection());
1469 }
1470
1471 @Test
1472 public void testAddGetRemoveSource() {
1473 Assert.assertEquals("No sources should exist yet", 0, specimenFacade.getSources().size());
1474
1475 Reference<?> reference = ReferenceFactory.newBook();
1476 IdentifiableSource source1 = specimenFacade.addSource(OriginalSourceType.PrimaryTaxonomicSource, reference, "54", "myName");
1477 Assert.assertEquals("One source should exist now", 1, specimenFacade.getSources().size());
1478 IdentifiableSource source2 = IdentifiableSource.NewDataImportInstance("1", "myTable");
1479 specimenFacade.addSource(source2);
1480 Assert.assertEquals("One source should exist now", 2, specimenFacade.getSources().size());
1481 specimenFacade.removeSource(source1);
1482 Assert.assertEquals("One source should exist now", 1, specimenFacade.getSources().size());
1483 Reference<?> reference2 = ReferenceFactory.newJournal();
1484 IdentifiableSource sourceNotUsed = specimenFacade.addSource(OriginalSourceType.PrimaryTaxonomicSource, reference2,null, null);
1485 specimenFacade.removeSource(sourceNotUsed);
1486 Assert.assertEquals("One source should still exist", 1, specimenFacade.getSources().size());
1487 Assert.assertEquals("1", specimenFacade.getSources().iterator().next().getIdInSource());
1488 specimenFacade.removeSource(source2);
1489 Assert.assertEquals("No sources should exist anymore", 0,specimenFacade.getSources().size());
1490 }
1491
1492 @Test
1493 public void testAddGetRemoveDuplicate() {
1494 Assert.assertEquals("No duplicates should be available yet", 0,specimenFacade.getDuplicates().size());
1495 DerivedUnit newSpecimen1 = DerivedUnit.NewPreservedSpecimenInstance();
1496 specimenFacade.addDuplicate(newSpecimen1);
1497 Assert.assertEquals("There should be 1 duplicate now", 1,specimenFacade.getDuplicates().size());
1498 DerivedUnit newSpecimen2 = DerivedUnit.NewPreservedSpecimenInstance();
1499 DerivationEvent newDerivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
1500 newSpecimen2.setDerivedFrom(newDerivationEvent);
1501 Assert.assertSame(
1502 "The derivation event should be 'newDerivationEvent'",
1503 newDerivationEvent, newSpecimen2.getDerivedFrom());
1504 specimenFacade.addDuplicate(newSpecimen2);
1505 Assert.assertEquals("There should be 2 duplicates now", 2, specimenFacade.getDuplicates().size());
1506 Assert.assertNotSame(
1507 "The derivation event should not be 'newDerivationEvent' anymore",
1508 newDerivationEvent, newSpecimen2.getDerivedFrom());
1509 Assert.assertSame(
1510 "The derivation event should not be the facades derivation event",
1511 derivationEvent, newSpecimen2.getDerivedFrom());
1512 specimenFacade.removeDuplicate(newSpecimen1);
1513 Assert.assertEquals("There should be 1 duplicate now", 1,
1514 specimenFacade.getDuplicates().size());
1515 Assert.assertSame("The only duplicate should be 'newSpecimen2' now",
1516 newSpecimen2, specimenFacade.getDuplicates().iterator().next());
1517 specimenFacade.addDuplicate(specimenFacade.innerDerivedUnit());
1518 Assert.assertEquals(
1519 "There should be still 1 duplicate because the facade specimen is not a duplicate",
1520 1, specimenFacade.getDuplicates().size());
1521
1522 Collection newCollection = Collection.NewInstance();
1523 String catalogNumber = "1234890";
1524 String accessionNumber = "345345";
1525 String collectorsNumber = "lkjewe";
1526 TaxonNameBase<?,?> storedUnder = BotanicalName.NewInstance(Rank.SPECIES());
1527 PreservationMethod method = PreservationMethod.NewInstance();
1528 DerivedUnit duplicateSpecimen = specimenFacade.addDuplicate(newCollection,
1529 catalogNumber, accessionNumber, storedUnder,
1530 method);
1531 Assert.assertEquals("There should be 2 duplicates now", 2,
1532 specimenFacade.getDuplicates().size());
1533 specimenFacade.removeDuplicate(newSpecimen2);
1534 Assert.assertEquals("There should be 1 duplicates now", 1,
1535 specimenFacade.getDuplicates().size());
1536 Collection sameCollection = specimenFacade.getDuplicates().iterator().next().getCollection();
1537 Assert.assertSame("Collections should be same", newCollection, sameCollection);
1538 }
1539
1540 // ************************** Existing Specimen with multiple derivation
1541 // events in line **************/
1542
1543 @Test
1544 public void testExistingSpecimen() {
1545 specimenFacade = null;
1546 try {
1547 specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
1548 } catch (DerivedUnitFacadeNotSupportedException e) {
1549 Assert.fail("Multiple derivation events in line should not throw a not supported exception");
1550 }
1551 Assert.assertSame(
1552 "Gathering event should derive from the derivation line",
1553 existingGatheringEvent, specimenFacade.innerGatheringEvent());
1554 Assert.assertEquals(
1555 "Mediasize should be 0. Only Imagegallery media are supported",
1556 0, specimenFacade.getFieldObjectMedia().size());
1557 }
1558
1559 @Test
1560 public void testMultipleFieldUnitNotSupported() {
1561 specimenFacade = null;
1562 FieldUnit secondFieldObject = FieldUnit.NewInstance();
1563 firstDerivationEvent.addOriginal(secondFieldObject);
1564 try {
1565 specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
1566 Assert.fail("Multiple field units for one specimen should no be supported by the facade");
1567 } catch (DerivedUnitFacadeNotSupportedException e) {
1568 // ok
1569 }
1570 Assert.assertNull("Specimen facade should not be initialized",
1571 specimenFacade);
1572 }
1573
1574 // not required anymore #3597
1575 // @Test // #######DerivationEvent
1576 // public void testOnlyImageGallerySupported() {
1577 // specimenFacade = null;
1578 // firstFieldObject.addMedia(media1);
1579 // try {
1580 // specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
1581 // Assert.fail("Only image galleries are supported by the facade but not direct media");
1582 // } catch (DerivedUnitFacadeNotSupportedException e) {
1583 // // ok
1584 // }
1585 // Assert.assertNull("Specimen facade should not be initialized",
1586 // specimenFacade);
1587 // }
1588
1589 @Test // #######DerivationEvent
1590 public void testEventPropagation() {
1591 specimenFacade.setDistanceToGround(24.0);
1592
1593 }
1594
1595 // @Ignore // set to ignore because I did not want to check knowingly
1596 // failing tests. Remove @Ignore when this is fixed
1597 @Test
1598 public void testSetBarcode() {
1599 String barcode = "barcode";
1600 specimenFacade.setBarcode(barcode);
1601
1602 Assert.assertEquals(barcode, specimenFacade.getBarcode());
1603 }
1604
1605 @Test
1606 public void testIsEvenDistance() {
1607 Integer minimum = 20;
1608 Integer maximum = 1234;
1609
1610 // this should not throw exceptions
1611 specimenFacade.setAbsoluteElevationRange(minimum, maximum);
1612 }
1613
1614 /**
1615 *
1616 * See https://dev.e-taxonomy.eu/trac/ticket/2426
1617 * This test doesn't handle the above issue yet as it doesn't fire events as
1618 * expected (at least it does not reproduce the behaviour in the Taxonomic Editor).
1619 * In the meanwhile the property change framework for the facade has been changed
1620 * so the original problem may have disappeared.
1621 *
1622 */
1623 @Test
1624 public void testNoRecursiveChangeEvents(){
1625 String username = "username";
1626 String password = "password";
1627 User user = User.NewInstance(username, password);
1628 userService.save(user);
1629 UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user, password);
1630 SecurityContextHolder.getContext().setAuthentication(token);
1631
1632 DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
1633 facade.setLocality("testLocality");
1634 facade.getTitleCache();
1635 // facade.innerGatheringEvent().firePropertyChange("createdBy", null, user);
1636 this.service.save(facade.innerDerivedUnit());
1637 commitAndStartNewTransaction(null);
1638 }
1639
1640 }