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