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