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