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