7e3441387ff3004199fa10076ec06b2e3c76a38d
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / facade / DerivedUnitFacadeTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.api.facade;
11
12 import java.lang.reflect.Field;
13 import java.text.ParseException;
14 import java.util.HashSet;
15 import java.util.List;
16
17 import org.apache.log4j.Logger;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22
23 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType;
24 import eu.etaxonomy.cdm.model.agent.AgentBase;
25 import eu.etaxonomy.cdm.model.agent.Team;
26 import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
27 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
28 import eu.etaxonomy.cdm.model.common.Language;
29 import eu.etaxonomy.cdm.model.common.LanguageString;
30 import eu.etaxonomy.cdm.model.common.TimePeriod;
31 import eu.etaxonomy.cdm.model.description.Sex;
32 import eu.etaxonomy.cdm.model.description.Stage;
33 import eu.etaxonomy.cdm.model.location.NamedArea;
34 import eu.etaxonomy.cdm.model.location.Point;
35 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
36 import eu.etaxonomy.cdm.model.location.TdwgArea;
37 import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
38 import eu.etaxonomy.cdm.model.media.Media;
39 import eu.etaxonomy.cdm.model.name.BotanicalName;
40 import eu.etaxonomy.cdm.model.name.Rank;
41 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42 import eu.etaxonomy.cdm.model.occurrence.Collection;
43 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
44 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
45 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
46 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
47 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
48 import eu.etaxonomy.cdm.model.occurrence.Specimen;
49 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
50 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
51
52 /**
53 * @author a.mueller
54 * @date 17.05.2010
55 *
56 */
57 public class DerivedUnitFacadeTest {
58 @SuppressWarnings("unused")
59 private static final Logger logger = Logger.getLogger(DerivedUnitFacadeTest.class);
60
61 Specimen specimen;
62 DerivationEvent derivationEvent;
63 FieldObservation fieldObservation;
64 GatheringEvent gatheringEvent;
65 Integer absoluteElevation = 10;
66 Integer absoluteElevationError = 2;
67 AgentBase collector = Team.NewInstance();
68 String collectingMethod = "Collection Method";
69 Integer distanceToGround = 22;
70 Integer distanceToSurface = 50;
71 ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
72 Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
73 String gatheringEventDescription = "A nice gathering description";
74 TimePeriod gatheringPeriod = TimePeriod.NewInstance(1888, 1889);
75
76 String fieldNumber = "15p23B";
77 String fieldNotes = "such a beautiful specimen";
78
79 Integer individualCount = 1;
80 Stage lifeStage = Stage.NewInstance("A wonderful stage", "stage", "st");
81 Sex sex = Sex.NewInstance("FemaleMale", "FM", "FM");
82 LanguageString locality = LanguageString.NewInstance("My locality", Language.DEFAULT());
83
84 String accessionNumber = "888462535";
85 String catalogNumber = "UU879873590";
86 TaxonNameBase taxonName = BotanicalName.NewInstance(Rank.GENUS(), "Abies", null, null, null, null, null, null, null);
87 String collectorsNumber = "234589913A34";
88 Collection collection = Collection.NewInstance();
89 PreservationMethod preservationMethod = PreservationMethod.NewInstance("my prservation", null, null);
90
91 DerivedUnitFacade specimenFacade;
92
93 Specimen collectionSpecimen;
94 GatheringEvent existingGatheringEvent;
95 DerivationEvent firstDerivationEvent;
96 FieldObservation firstFieldObject;
97 Media media1 = Media.NewInstance();
98
99 DerivedUnitFacade emptyFacade;
100
101 NamedArea country = WaterbodyOrCountry.GERMANY();
102
103
104 //****************************** SET UP *****************************************/
105
106 /**
107 * @throws java.lang.Exception
108 */
109 @BeforeClass
110 public static void setUpBeforeClass() throws Exception {
111 new DefaultTermInitializer().initialize();
112 }
113
114 /**
115 * @throws java.lang.Exception
116 */
117 @Before
118 public void setUp() throws Exception {
119 specimen = Specimen.NewInstance();
120
121 derivationEvent = DerivationEvent.NewInstance();
122 specimen.setDerivedFrom(derivationEvent);
123 fieldObservation = FieldObservation.NewInstance();
124 fieldObservation.addDerivationEvent(derivationEvent);
125 gatheringEvent = GatheringEvent.NewInstance();
126 fieldObservation.setGatheringEvent(gatheringEvent);
127 gatheringEvent.setAbsoluteElevation(absoluteElevation);
128 gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
129 gatheringEvent.setActor(collector);
130 gatheringEvent.setCollectingMethod(collectingMethod);
131 gatheringEvent.setDistanceToGround(distanceToGround);
132 gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
133 gatheringEvent.setExactLocation(exactLocation);
134 gatheringEvent.setDescription(gatheringEventDescription);
135 gatheringEvent.setCountry(country);
136
137 gatheringEvent.setTimeperiod(gatheringPeriod);
138 gatheringEvent.setLocality(locality);
139
140 fieldObservation.setFieldNumber(fieldNumber);
141 fieldObservation.setFieldNotes(fieldNotes);
142 fieldObservation.setIndividualCount(individualCount);
143 fieldObservation.setSex(sex);
144 fieldObservation.setLifeStage(lifeStage);
145
146 specimen.setAccessionNumber(accessionNumber);
147 specimen.setCatalogNumber(catalogNumber);
148 specimen.setStoredUnder(taxonName);
149 specimen.setCollectorsNumber(collectorsNumber);
150 specimen.setCollection(collection);
151 specimen.setPreservation(preservationMethod);
152
153 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
154
155 //existing specimen with 2 derivation events in line
156 collectionSpecimen = Specimen.NewInstance();
157 Specimen middleSpecimen = Specimen.NewInstance();
158 firstFieldObject = FieldObservation.NewInstance();
159
160 DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();
161 DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance();
162 firstDerivationEvent = DerivationEvent.NewInstance();
163
164 collectionSpecimen.setDerivedFrom(lastDerivationEvent);
165
166 lastDerivationEvent.addOriginal(middleSpecimen);
167 middleSpecimen.setDerivedFrom(firstDerivationEvent);
168 firstDerivationEvent.addOriginal(firstFieldObject);
169 existingGatheringEvent = GatheringEvent.NewInstance();
170 firstFieldObject.setGatheringEvent(existingGatheringEvent);
171
172 //empty facade
173 emptyFacade = DerivedUnitFacade.NewInstance(DerivedUnitType.Specimen);
174
175 }
176
177
178 //****************************** TESTS *****************************************/
179
180 /**
181 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance()}.
182 */
183 @Test
184 public void testNewInstance() {
185 Assert.assertNotNull("The specimen should have been created", specimenFacade.getDerivedUnit());
186 //???
187 // Assert.assertNotNull("The derivation event should have been created", specimenFacade.getSpecimen().getDerivedFrom());
188 // Assert.assertNotNull("The field observation should have been created", specimenFacade.getFieldObservation());
189 // Assert.assertNotNull("The gathering event should have been created", specimenFacade.getGatheringEvent());
190 }
191
192 /**
193 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#NewInstance(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
194 */
195 @Test
196 public void testNewInstanceSpecimen() {
197 Assert.assertSame("Specimen should be same", specimen, specimenFacade.getDerivedUnit());
198 Assert.assertSame("Derivation event should be same", derivationEvent, specimenFacade.getDerivedUnit().getDerivedFrom());
199 Assert.assertSame("Field observation should be same", fieldObservation, specimenFacade.getFieldObservation());
200 Assert.assertSame("Gathering event should be same", gatheringEvent, specimenFacade.getGatheringEvent());
201
202 }
203
204 @Test
205 public void testGatheringEventIsConnectedToDerivedUnit(){
206 Specimen specimen = Specimen.NewInstance();
207 DerivedUnitFacade specimenFacade;
208 try {
209 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
210 specimenFacade.setDistanceToGround(2);
211 FieldObservation specimenFieldObservation = (FieldObservation)specimen.getDerivedFrom().getOriginals().iterator().next();
212 Assert.assertSame("Facade gathering event and specimen gathering event should be the same",specimenFacade.getGatheringEvent(), specimenFieldObservation.getGatheringEvent());
213 } catch (DerivedUnitFacadeNotSupportedException e) {
214 Assert.fail("An error should not occur in NewInstance()");
215 }
216 }
217
218 @Test
219 public void testNoGatheringEventAndFieldObservation(){
220 Specimen specimen = Specimen.NewInstance();
221 DerivedUnitFacade specimenFacade;
222 try {
223 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
224 Assert.assertNull("No field observation should exists", specimenFacade.getFieldObservation());
225 } catch (DerivedUnitFacadeNotSupportedException e) {
226 Assert.fail("An error should not occur in NewInstance()");
227 }
228 }
229
230 @Test
231 public void testGetSetCountry(){
232
233 }
234
235
236 /**
237 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}.
238 */
239 @Test
240 public void testAddGetRemoveCollectingArea() {
241 String tdwgLabel = "GER";
242 NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgLabel);
243 NamedArea newCollectingArea = NamedArea.NewInstance("A nice area", "nice", "n");
244 specimenFacade.addCollectingArea(newCollectingArea);
245 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade.getCollectingAreas().size());
246 Assert.assertSame("Areas should be same", newCollectingArea, specimenFacade.getFieldObservation().getGatheringEvent().getCollectingAreas().iterator().next());
247 specimenFacade.addCollectingArea(tdwgArea);
248 Assert.assertEquals("Exactly 2 areas must exist", 2, specimenFacade.getCollectingAreas().size());
249 specimenFacade.removeCollectingArea(newCollectingArea);
250 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade.getCollectingAreas().size());
251 NamedArea remainingArea = specimenFacade.getCollectingAreas().iterator().next();
252 Assert.assertEquals("Areas should be same", tdwgArea, remainingArea);
253 specimenFacade.removeCollectingArea(tdwgArea);
254 Assert.assertEquals("No area should remain", 0, specimenFacade.getCollectingAreas().size());
255 }
256
257 /**
258 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addCollectingArea(eu.etaxonomy.cdm.model.location.NamedArea)}.
259 */
260 @Test
261 public void testAddCollectingAreas() {
262 NamedArea firstArea = NamedArea.NewInstance("A nice area", "nice", "n");
263 Assert.assertEquals("No area must exist", 0, specimenFacade.getCollectingAreas().size());
264 specimenFacade.addCollectingArea(firstArea);
265 Assert.assertEquals("Exactly 1 area must exist", 1, specimenFacade.getCollectingAreas().size());
266
267 String tdwgLabel = "GER";
268 NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwgLabel);
269 NamedArea secondArea = NamedArea.NewInstance("A nice area", "nice", "n");
270
271 java.util.Collection<NamedArea> areaCollection = new HashSet<NamedArea>();
272 areaCollection.add(secondArea);
273 areaCollection.add(tdwgArea);
274 specimenFacade.addCollectingAreas(areaCollection);
275 Assert.assertEquals("Exactly 3 areas must exist", 3, specimenFacade.getCollectingAreas().size());
276
277 }
278
279
280
281 /**
282 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevation()}.
283 */
284 @Test
285 public void testGetSetAbsoluteElevation() {
286 Assert.assertEquals("Absolute elevation must be same",absoluteElevation, specimenFacade.getAbsoluteElevation());
287 specimenFacade.setAbsoluteElevation(400);
288 Assert.assertEquals("Absolute elevation must be 400", Integer.valueOf(400), specimenFacade.getAbsoluteElevation());
289 }
290
291
292 /**
293 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAbsoluteElevationError()}.
294 */
295 @Test
296 public void testGetSetAbsoluteElevationError() {
297 Assert.assertEquals("Absolute elevation error must be same",absoluteElevationError, specimenFacade.getAbsoluteElevationError());
298 specimenFacade.setAbsoluteElevationError(4);
299 Assert.assertEquals("Absolute elevation error must be 4", Integer.valueOf(4), specimenFacade.getAbsoluteElevationError());
300 }
301
302 @Test()
303 public void testGetSetAbsoluteElevationRange(){
304 Integer expected = absoluteElevation - 2 ;
305 Assert.assertEquals("", expected,specimenFacade.getAbsoluteElevationMinimum());
306 expected = absoluteElevation + 2 ;
307 Assert.assertEquals("", expected,specimenFacade.getAbsoluteElevationMaximum());
308 specimenFacade.setAbsoluteElevationRange(30, 36);
309 Assert.assertEquals("", Integer.valueOf(36), specimenFacade.getAbsoluteElevationMaximum());
310 Assert.assertEquals("", Integer.valueOf(30), specimenFacade.getAbsoluteElevationMinimum());
311 try {
312 specimenFacade.setAbsoluteElevationRange(30, 35);
313 Assert.fail("Odd distance needs to throw IllegalArgumentException");
314 } catch (IllegalArgumentException e) {
315 Assert.assertTrue("Exception needs to be thrown", true);
316 }
317 specimenFacade.setAbsoluteElevationRange(41, null);
318 Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevationMaximum());
319 Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevationMinimum());
320 Assert.assertEquals("", Integer.valueOf(41), specimenFacade.getAbsoluteElevation());
321 Assert.assertNotNull("", specimenFacade.getAbsoluteElevationError());
322 Assert.assertEquals("", Integer.valueOf(0), specimenFacade.getAbsoluteElevationError());
323 specimenFacade.setAbsoluteElevationRange(null, null);
324 Assert.assertNull("", specimenFacade.getAbsoluteElevation());
325 Assert.assertNull("", specimenFacade.getAbsoluteElevationError());
326
327
328 }
329
330
331 /**
332 */
333 @Test
334 public void testGetSetCollector() {
335 Assert.assertNotNull("Collector must not be null", specimenFacade.getCollector());
336 Assert.assertEquals("Collector must be same",collector, specimenFacade.getCollector());
337 specimenFacade.setCollector(null);
338 Assert.assertNull("Collector must be null", specimenFacade.getCollector());
339 }
340
341 /**
342 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectingMethod()}.
343 */
344 @Test
345 public void testGetSetCollectingMethod() {
346 Assert.assertEquals("Collecting method must be same", collectingMethod, specimenFacade.getCollectingMethod());
347 specimenFacade.setCollectingMethod("new method");
348 Assert.assertEquals("Collecting method must be 'new method'","new method", specimenFacade.getCollectingMethod());
349 }
350
351
352 /**
353 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToGround()}.
354 */
355 @Test
356 public void testGetSetDistanceToGround() {
357 Assert.assertEquals("Distance to ground must be same",distanceToGround, specimenFacade.getDistanceToGround());
358 specimenFacade.setDistanceToGround(5);
359 Assert.assertEquals("Distance to ground must be 5", Integer.valueOf(5), specimenFacade.getDistanceToGround());
360 }
361
362 /**
363 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDistanceToWaterSurface()}.
364 */
365 @Test
366 public void testGetDistanceToWaterSurface() {
367 Assert.assertEquals("Distance to surface must be same", distanceToSurface, specimenFacade.getDistanceToWaterSurface());
368 specimenFacade.setDistanceToWaterSurface(6);
369 Assert.assertEquals("Distance to surface must be 6", Integer.valueOf(6), specimenFacade.getDistanceToWaterSurface());
370 //empty facade tests
371 Assert.assertNull("Empty facace must not have any gathering values" ,emptyFacade.getDistanceToWaterSurface());
372 emptyFacade.setDistanceToWaterSurface(13);
373 Assert.assertNotNull("Field observation must exist if distance to water exists", emptyFacade.getFieldObservation(false));
374 Assert.assertNotNull("Gathering event must exist if distance to water exists", emptyFacade.getGatheringEvent(false));
375 FieldObservation specimenFieldObservation = (FieldObservation)emptyFacade.getDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
376 Assert.assertSame("Gathering event of facade and of specimen must be the same", specimenFieldObservation.getGatheringEvent(), emptyFacade.getGatheringEvent(false));
377 }
378
379 /**
380 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getExactLocation()}.
381 */
382 @Test
383 public void testGetSetExactLocation() {
384 Assert.assertNotNull("Exact location must not be null", specimenFacade.getExactLocation());
385 Assert.assertEquals("Exact location must be same", exactLocation, specimenFacade.getExactLocation());
386 specimenFacade.setExactLocation(null);
387 Assert.assertNull("Exact location must be null", specimenFacade.getExactLocation());
388 }
389
390 @Test
391 public void testSetExactLocationByParsing(){
392 Point point1;
393 try {
394 specimenFacade.setExactLocationByParsing("112\u00B034'20\"W", "34\u00B030,34'N", null, null);
395 point1 = specimenFacade.getExactLocation();
396 Assert.assertNotNull("", point1.getLatitude());
397 System.out.println(point1.getLatitude().toString());
398 Assert.assertTrue("", point1.getLatitude().toString().startsWith("34.505"));
399 System.out.println(point1.getLongitude().toString());
400 Assert.assertTrue("", point1.getLongitude().toString().startsWith("-112.5722"));
401
402 } catch (ParseException e) {
403 Assert.fail("No parsing error should occur");
404 }
405 }
406
407
408 /**
409 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEventDescription()}.
410 */
411 @Test
412 public void testGetSetGatheringEventDescription() {
413 Assert.assertEquals("Gathering event description must be same", gatheringEventDescription, specimenFacade.getGatheringEventDescription());
414 specimenFacade.setGatheringEventDescription("new description");
415 Assert.assertEquals("Gathering event description must be 'new description' now","new description", specimenFacade.getGatheringEventDescription());
416 }
417
418 /**
419 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTimeperiod()}.
420 */
421 @Test
422 public void testGetTimeperiod() {
423 Assert.assertNotNull("Gathering period must not be null", specimenFacade.getGatheringPeriod());
424 Assert.assertEquals("Gathering period must be same", gatheringPeriod, specimenFacade.getGatheringPeriod());
425 specimenFacade.setGatheringPeriod(null);
426 Assert.assertNull("Gathering period must be null", specimenFacade.getGatheringPeriod());
427 }
428
429 @Test
430 public void testHasFieldObject() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
431 // this test depends on the current implementation of SpecimenFacade. In future
432 // field observation may not be initialized from the beginning. Than the following
433 // assert should be set to assertNull
434 Assert.assertTrue("field object should not be null (depends on specimen facade initialization !!)", specimenFacade.hasFieldObject());
435
436 Field fieldObservationField = DerivedUnitFacade.class.getDeclaredField("fieldObservation");
437 fieldObservationField.setAccessible(true);
438 fieldObservationField.set(specimenFacade, null);
439 Assert.assertFalse("The field observation should be null now", specimenFacade.hasFieldObject());
440
441 specimenFacade.setDistanceToGround(33);
442 Assert.assertTrue("The field observation should have been created again", specimenFacade.hasFieldObject());
443 }
444
445 /**
446 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
447 */
448 @Test
449 public void testAddGetRemoveFieldObjectDefinition() {
450 Assert.assertEquals("There should be no definition yet", 0, specimenFacade.getFieldObjectDefinition().size());
451 specimenFacade.addFieldObjectDefinition("Tres interesant", Language.FRENCH());
452 Assert.assertEquals("There should be exactly one definition", 1, specimenFacade.getFieldObjectDefinition().size());
453 Assert.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade.getFieldObjectDefinition().get(Language.FRENCH()).getText());
454 Assert.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade.getFieldObjectDefinition(Language.FRENCH()));
455 specimenFacade.addFieldObjectDefinition("Sehr interessant", Language.GERMAN());
456 Assert.assertEquals("There should be exactly 2 definition", 2, specimenFacade.getFieldObjectDefinition().size());
457 specimenFacade.removeFieldObjectDefinition(Language.FRENCH());
458 Assert.assertEquals("There should remain exactly 1 definition", 1, specimenFacade.getFieldObjectDefinition().size());
459 Assert.assertEquals("The remaining German definition should be 'Sehr interessant'", "Sehr interessant", specimenFacade.getFieldObjectDefinition(Language.GERMAN()));
460 specimenFacade.removeFieldObjectDefinition(Language.GERMAN());
461 Assert.assertEquals("There should remain no definition", 0, specimenFacade.getFieldObjectDefinition().size());
462 }
463
464 /**
465 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
466 */
467 @Test
468 public void testAddGetHasRemoveFieldObjectMedia() {
469 Assert.assertFalse("There should be no image gallery yet", specimenFacade.hasFieldObjectImageGallery());
470 Assert.assertFalse("There should be no specimen image gallery either", specimenFacade.hasDerivedUnitImageGallery());
471
472 List<Media> media = specimenFacade.getFieldObjectMedia();
473 Assert.assertFalse("There should still not be an image gallery now", specimenFacade.hasFieldObjectImageGallery());
474 Assert.assertEquals("There should be no media yet in the gallery", 0, media.size());
475
476 Media media1 = Media.NewInstance();
477 specimenFacade.addFieldObjectMedia(media1);
478 Assert.assertEquals("There should be exactly one specimen media", 1, specimenFacade.getFieldObjectMedia().size());
479 Assert.assertEquals("The only media should be media 1", media1, specimenFacade.getFieldObjectMedia().get(0));
480 Assert.assertFalse("There should still no specimen image gallery exist", specimenFacade.hasDerivedUnitImageGallery());
481
482 Media media2 = Media.NewInstance();
483 specimenFacade.addFieldObjectMedia(media2);
484 Assert.assertEquals("There should be exactly 2 specimen media", 2, specimenFacade.getFieldObjectMedia().size());
485 Assert.assertEquals("The first media should be media1", media1, specimenFacade.getFieldObjectMedia().get(0));
486 Assert.assertEquals("The second media should be media2", media2, specimenFacade.getFieldObjectMedia().get(1));
487
488 specimenFacade.removeFieldObjectMedia(media1);
489 Assert.assertEquals("There should be exactly one specimen media", 1, specimenFacade.getFieldObjectMedia().size());
490 Assert.assertEquals("The only media should be media2", media2, specimenFacade.getFieldObjectMedia().get(0));
491
492 specimenFacade.removeFieldObjectMedia(media1);
493 Assert.assertEquals("There should still be exactly one specimen media", 1, specimenFacade.getFieldObjectMedia().size());
494
495 specimenFacade.removeFieldObjectMedia(media2);
496 Assert.assertEquals("There should remain no media in the gallery", 0, media.size());
497
498 }
499
500 /**
501 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
502 */
503 @Test
504 public void testGetSetEcology() {
505 Assert.assertNotNull("An empty ecology data should be created when calling getEcology()", specimenFacade.getEcologyAll());
506 Assert.assertEquals("An empty ecology data should be created when calling getEcology()", 0, specimenFacade.getEcologyAll().size());
507 specimenFacade.setEcology("Tres jolie ici", Language.FRENCH());
508 Assert.assertEquals("Ecology data should exist for 1 language", 1, specimenFacade.getEcologyAll().size());
509 Assert.assertEquals("Ecology data should be 'Tres jolie ici' for French", "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
510 Assert.assertNull("Ecology data should be null for the default language", specimenFacade.getEcology());
511 specimenFacade.setEcology("Nice here");
512 Assert.assertEquals("Ecology data should exist for 2 languages", 2, specimenFacade.getEcologyAll().size());
513 Assert.assertEquals("Ecology data should be 'Tres jolie ici'", "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
514 Assert.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade.getEcology());
515 Assert.assertEquals("Ecology data should be 'Nice here' for english", "Nice here", specimenFacade.getEcology());
516
517 specimenFacade.setEcology("Vert et rouge", Language.FRENCH());
518 Assert.assertEquals("Ecology data should exist for 2 languages", 2, specimenFacade.getEcologyAll().size());
519 Assert.assertEquals("Ecology data should be 'Vert et rouge'", "Vert et rouge", specimenFacade.getEcology(Language.FRENCH()));
520 Assert.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade.getEcology());
521
522 specimenFacade.setEcology(null, Language.FRENCH());
523 Assert.assertEquals("Ecology data should exist for 1 languages", 1, specimenFacade.getEcologyAll().size());
524 Assert.assertEquals("Ecology data should be 'Nice here' for the default language", "Nice here", specimenFacade.getEcology());
525 Assert.assertNull("Ecology data should be 'null' for French", specimenFacade.getEcology(Language.FRENCH()));
526
527 specimenFacade.removeEcology(null);
528 Assert.assertEquals("There should be no ecology left", 0, specimenFacade.getEcologyAll().size());
529 Assert.assertNull("Ecology data should be 'null' for default language", specimenFacade.getEcology());
530
531 }
532
533 /**
534 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addFieldObjectMedia(eu.etaxonomy.cdm.model.media.Media)}.
535 */
536 @Test
537 public void testGetSetPlantDescription() {
538 Assert.assertNotNull("An empty plant description data should be created when calling getPlantDescriptionAll()", specimenFacade.getPlantDescriptionAll());
539 Assert.assertEquals("An empty plant description data should be created when calling getPlantDescription()", 0, specimenFacade.getPlantDescriptionAll().size());
540 specimenFacade.setPlantDescription("bleu", Language.FRENCH());
541 Assert.assertEquals("Plant description data should exist for 1 language", 1, specimenFacade.getPlantDescriptionAll().size());
542 Assert.assertEquals("Plant description data should be 'bleu' for French", "bleu", specimenFacade.getPlantDescription(Language.FRENCH()));
543 Assert.assertNull("Plant description data should be null for the default language", specimenFacade.getPlantDescription());
544 specimenFacade.setPlantDescription("Nice here");
545 Assert.assertEquals("Plant description data should exist for 2 languages", 2, specimenFacade.getPlantDescriptionAll().size());
546 Assert.assertEquals("Plant description data should be 'bleu'", "bleu", specimenFacade.getPlantDescription(Language.FRENCH()));
547 Assert.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade.getPlantDescription());
548 Assert.assertEquals("Plant description data should be 'Nice here' for english", "Nice here", specimenFacade.getPlantDescription());
549
550 specimenFacade.setPlantDescription("Vert et rouge", Language.FRENCH());
551 Assert.assertEquals("Plant description data should exist for 2 languages", 2, specimenFacade.getPlantDescriptionAll().size());
552 Assert.assertEquals("Plant description data should be 'Vert et rouge'", "Vert et rouge", specimenFacade.getPlantDescription(Language.FRENCH()));
553 Assert.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade.getPlantDescription());
554
555 specimenFacade.setPlantDescription(null, Language.FRENCH());
556 Assert.assertEquals("Plant description data should exist for 1 languages", 1, specimenFacade.getPlantDescriptionAll().size());
557 Assert.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade.getPlantDescription());
558 Assert.assertNull("Plant description data should be 'null' for French", specimenFacade.getPlantDescription(Language.FRENCH()));
559
560 //test interference with ecology
561 specimenFacade.setEcology("Tres jolie ici", Language.FRENCH());
562 Assert.assertEquals("Ecology data should exist for 1 language", 1, specimenFacade.getEcologyAll().size());
563 Assert.assertEquals("Ecology data should be 'Tres jolie ici' for French", "Tres jolie ici", specimenFacade.getEcology(Language.FRENCH()));
564 Assert.assertNull("Ecology data should be null for the default language", specimenFacade.getEcology());
565
566 //repeat above test
567 Assert.assertEquals("Plant description data should exist for 1 languages", 1, specimenFacade.getPlantDescriptionAll().size());
568 Assert.assertEquals("Plant description data should be 'Nice here' for the default language", "Nice here", specimenFacade.getPlantDescription());
569 Assert.assertNull("Plant description data should be 'null' for French", specimenFacade.getPlantDescription(Language.FRENCH()));
570
571
572 specimenFacade.removePlantDescription(null);
573 Assert.assertEquals("There should be no plant description left", 0, specimenFacade.getPlantDescriptionAll().size());
574 Assert.assertNull("Plant description data should be 'null' for default language", specimenFacade.getPlantDescription());
575
576 }
577
578 /**
579 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNumber()}.
580 */
581 @Test
582 public void testGetSetFieldNumber() {
583 Assert.assertEquals("Field number must be same", fieldNumber, specimenFacade.getFieldNumber());
584 specimenFacade.setFieldNumber("564AB");
585 Assert.assertEquals("New field number must be '564AB'", "564AB", specimenFacade.getFieldNumber());
586 //empty facade tests
587 Assert.assertNull("Empty facace must not have any field value" ,emptyFacade.getFieldNumber());
588 emptyFacade.setFieldNumber("1256A");
589 Assert.assertNotNull("Field observation must exist if field number exists", emptyFacade.getFieldObservation(false));
590 FieldObservation specimenFieldObservation = (FieldObservation)emptyFacade.getDerivedUnit().getDerivedFrom().getOriginals().iterator().next();
591 Assert.assertSame("Field observation of facade and of specimen must be the same", specimenFieldObservation, emptyFacade.getFieldObservation(false));
592 Assert.assertEquals("1256A", emptyFacade.getFieldNumber());
593 }
594
595 /**
596 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getFieldNotes()}.
597 */
598 @Test
599 public void testGetSetFieldNotes() {
600 Assert.assertEquals("Field notes must be same", fieldNotes, specimenFacade.getFieldNotes());
601 specimenFacade.setFieldNotes("A completely new info");
602 Assert.assertEquals("New field note must be 'A completely new info'", "A completely new info", specimenFacade.getFieldNotes());
603 }
604
605 /**
606 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setGatheringEvent(eu.etaxonomy.cdm.model.occurrence.GatheringEvent)}.
607 */
608 @Test
609 public void testSetGatheringEvent() {
610 GatheringEvent newGatheringEvent = GatheringEvent.NewInstance();
611 newGatheringEvent.setDistanceToGround(43);
612 Assert.assertFalse("The initial distance to ground should not be 43", specimenFacade.getDistanceToGround() == 43);
613 specimenFacade.setGatheringEvent(newGatheringEvent);
614 Assert.assertTrue("The final distance to ground should be 43", specimenFacade.getDistanceToGround() == 43);
615 Assert.assertSame("The new gathering event should be 'newGatheringEvent'", newGatheringEvent, specimenFacade.getGatheringEvent());
616 }
617
618 /**
619 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getGatheringEvent()}.
620 */
621 @Test
622 public void testGetGatheringEvent() {
623 Assert.assertNotNull("Gathering event must not be null", specimenFacade.getGatheringEvent());
624 Assert.assertEquals("Gathering event must be field observations gathering event", specimenFacade.getFieldObservation().getGatheringEvent(), specimenFacade.getGatheringEvent());
625 }
626
627 /**
628 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getIndividualCount()}.
629 */
630 @Test
631 public void testGetSetIndividualCount(){
632 Assert.assertEquals("Individual count must be same", individualCount, specimenFacade.getIndividualCount());
633 specimenFacade.setIndividualCount(4);
634 Assert.assertEquals("New individual count must be '4'", Integer.valueOf(4), specimenFacade.getIndividualCount());
635
636 }
637
638
639 /**
640 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLifeStage()}.
641 */
642 @Test
643 public void testGetSetLifeStage(){
644 Assert.assertNotNull("Life stage must not be null", specimenFacade.getLifeStage());
645 Assert.assertEquals("Life stage must be same", lifeStage, specimenFacade.getLifeStage());
646 specimenFacade.setLifeStage(null);
647 Assert.assertNull("Life stage must be null", specimenFacade.getLifeStage());
648 }
649
650 /**
651 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getSex()}.
652 */
653 @Test
654 public void testGetSetSex() {
655 Assert.assertNotNull("Sex must not be null", specimenFacade.getSex());
656 Assert.assertEquals("Sex must be same", sex, specimenFacade.getSex());
657 specimenFacade.setSex(null);
658 Assert.assertNull("Sex must be null", specimenFacade.getSex());
659 }
660
661 /**
662 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getLocality()}.
663 */
664 @Test
665 public void testGetSetLocality() {
666 Assert.assertEquals("Locality must be same", locality, specimenFacade.getLocality());
667 specimenFacade.setLocality("A completely new place", Language.FRENCH());
668 Assert.assertEquals("New locality must be 'A completely new place'", "A completely new place", specimenFacade.getLocalityText());
669 Assert.assertEquals("New locality language must be French", Language.FRENCH(), specimenFacade.getLocalityLanguage());
670 specimenFacade.setLocality("Another place");
671 Assert.assertEquals("New locality must be 'Another place'", "Another place", specimenFacade.getLocalityText());
672 Assert.assertEquals("New locality language must be default", Language.DEFAULT(), specimenFacade.getLocalityLanguage());
673 }
674
675 /**
676 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitDefinition(java.lang.String, eu.etaxonomy.cdm.model.common.Language)}.
677 */
678 @Test
679 public void testAddGetRemoveSpecimenDefinition() {
680 Assert.assertEquals("There should be no definition yet", 0, specimenFacade.getDerivedUnitDefinitions().size());
681 specimenFacade.addDerivedUnitDefinition("Tres interesant", Language.FRENCH());
682 Assert.assertEquals("There should be exactly one definition", 1, specimenFacade.getDerivedUnitDefinitions().size());
683 Assert.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade.getDerivedUnitDefinitions().get(Language.FRENCH()).getText());
684 Assert.assertEquals("The French definition should be 'Tres interesant'", "Tres interesant", specimenFacade.getDerivedUnitDefinition(Language.FRENCH()));
685 specimenFacade.addDerivedUnitDefinition("Sehr interessant", Language.GERMAN());
686 Assert.assertEquals("There should be exactly 2 definition", 2, specimenFacade.getDerivedUnitDefinitions().size());
687 specimenFacade.removeDerivedUnitDefinition(Language.FRENCH());
688 Assert.assertEquals("There should remain exactly 1 definition", 1, specimenFacade.getDerivedUnitDefinitions().size());
689 Assert.assertEquals("The remaining German definition should be 'Sehr interessant'", "Sehr interessant", specimenFacade.getDerivedUnitDefinition(Language.GERMAN()));
690 specimenFacade.removeDerivedUnitDefinition(Language.GERMAN());
691 Assert.assertEquals("There should remain no definition", 0, specimenFacade.getDerivedUnitDefinitions().size());
692 }
693
694 /**
695 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDetermination(eu.etaxonomy.cdm.model.occurrence.DeterminationEvent)}.
696 */
697 @Test
698 public void testAddGetRemoveDetermination() {
699 Assert.assertEquals("There should be no determination yet", 0, specimenFacade.getDeterminations().size());
700 DeterminationEvent determinationEvent1 = DeterminationEvent.NewInstance();
701 specimenFacade.addDetermination(determinationEvent1);
702 Assert.assertEquals("There should be exactly one determination", 1, specimenFacade.getDeterminations().size());
703 Assert.assertEquals("The only determination should be determination 1", determinationEvent1, specimenFacade.getDeterminations().iterator().next());
704
705
706 DeterminationEvent determinationEvent2 = DeterminationEvent.NewInstance();
707 specimenFacade.addDetermination(determinationEvent2);
708 Assert.assertEquals("There should be exactly 2 determinations", 2, specimenFacade.getDeterminations().size());
709 specimenFacade.removeDetermination(determinationEvent1);
710
711 Assert.assertEquals("There should remain exactly 1 determination", 1, specimenFacade.getDeterminations().size());
712 Assert.assertEquals("The remaining determinations should be determination 2", determinationEvent2, specimenFacade.getDeterminations().iterator().next());
713
714 specimenFacade.removeDetermination(determinationEvent1);
715 Assert.assertEquals("There should remain exactly 1 determination", 1, specimenFacade.getDeterminations().size());
716
717 specimenFacade.removeDetermination(determinationEvent2);
718 Assert.assertEquals("There should remain no definition", 0, specimenFacade.getDerivedUnitDefinitions().size());
719
720 }
721
722 /**
723 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#addDerivedUnitMedia(eu.etaxonomy.cdm.model.media.Media)}.
724 */
725 @Test
726 public void testAddGetHasRemoveSpecimenMedia() {
727 Assert.assertFalse("There should be no image gallery yet", specimenFacade.hasDerivedUnitImageGallery());
728 Assert.assertFalse("There should be also no field object image gallery yet", specimenFacade.hasFieldObjectImageGallery());
729
730 List<Media> media = specimenFacade.getDerivedUnitMedia();
731 Assert.assertFalse("There should still not be an empty image gallery now", specimenFacade.hasDerivedUnitImageGallery());
732 Assert.assertEquals("There should be no media yet in the gallery", 0, media.size());
733
734 Media media1 = Media.NewInstance();
735 specimenFacade.addDerivedUnitMedia(media1);
736 Assert.assertEquals("There should be exactly one specimen media", 1, specimenFacade.getDerivedUnitMedia().size());
737 Assert.assertEquals("The only media should be media 1", media1, specimenFacade.getDerivedUnitMedia().get(0));
738 Assert.assertFalse("There should be still no field object image gallery", specimenFacade.hasFieldObjectImageGallery());
739
740 Media media2 = Media.NewInstance();
741 specimenFacade.addDerivedUnitMedia(media2);
742 Assert.assertEquals("There should be exactly 2 specimen media", 2, specimenFacade.getDerivedUnitMedia().size());
743 Assert.assertEquals("The first media should be media1", media1, specimenFacade.getDerivedUnitMedia().get(0));
744 Assert.assertEquals("The second media should be media2", media2, specimenFacade.getDerivedUnitMedia().get(1));
745
746 specimenFacade.removeDerivedUnitMedia(media1);
747 Assert.assertEquals("There should be exactly one specimen media", 1, specimenFacade.getDerivedUnitMedia().size());
748 Assert.assertEquals("The only media should be media2", media2, specimenFacade.getDerivedUnitMedia().get(0));
749
750 specimenFacade.removeDerivedUnitMedia(media1);
751 Assert.assertEquals("There should still be exactly one specimen media", 1, specimenFacade.getDerivedUnitMedia().size());
752
753 specimenFacade.removeDerivedUnitMedia(media2);
754 Assert.assertEquals("There should remain no media in the gallery", 0, media.size());
755 }
756
757 /**
758 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getAccessionNumber()}.
759 */
760 @Test
761 public void testGetSetAccessionNumber() {
762 Assert.assertEquals("Accession number must be same", accessionNumber, specimenFacade.getAccessionNumber());
763 specimenFacade.setAccessionNumber("A12345693");
764 Assert.assertEquals("New accession number must be 'A12345693'", "A12345693", specimenFacade.getAccessionNumber());
765 }
766
767 /**
768 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCatalogNumber()}.
769 */
770 @Test
771 public void testGetCatalogNumber() {
772 Assert.assertEquals("Catalog number must be same", catalogNumber, specimenFacade.getCatalogNumber());
773 specimenFacade.setCatalogNumber("B12345693");
774 Assert.assertEquals("New catalog number must be 'B12345693'", "B12345693", specimenFacade.getCatalogNumber());
775 }
776
777 /**
778 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getPreservation()}.
779 */
780 @Test
781 public void testGetPreservation() {
782 try {
783 Assert.assertNotNull("Preservation method must not be null", specimenFacade.getPreservationMethod());
784 Assert.assertEquals("Preservation method must be same", preservationMethod, specimenFacade.getPreservationMethod());
785 specimenFacade.setPreservationMethod(null);
786 Assert.assertNull("Preservation method must be null", specimenFacade.getPreservationMethod());
787 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
788 Assert.fail("Method not supported should not be thrown for a specimen");
789 }
790 specimenFacade = DerivedUnitFacade.NewInstance(DerivedUnitType.Observation);
791 try {
792 specimenFacade.setPreservationMethod(preservationMethod);
793 Assert.fail("Method not supported should be thrown for an observation on set preservation method");
794
795 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
796 //ok
797 }
798 specimenFacade = DerivedUnitFacade.NewInstance(DerivedUnitType.LivingBeing);
799 try {
800 specimenFacade.getPreservationMethod();
801 Assert.fail("Method not supported should be thrown for a living being on get preservation method");
802 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
803 //ok
804 }
805
806
807 }
808
809 /**
810 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getStoredUnder()}.
811 */
812 @Test
813 public void testGetStoredUnder() {
814 Assert.assertNotNull("Stored under name must not be null", specimenFacade.getStoredUnder());
815 Assert.assertEquals("Stored under name must be same", taxonName, specimenFacade.getStoredUnder());
816 specimenFacade.setStoredUnder(null);
817 Assert.assertNull("Stored under name must be null", specimenFacade.getStoredUnder());
818 }
819
820 /**
821 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollectorsNumber()}.
822 */
823 @Test
824 public void testGetSetCollectorsNumber() {
825 Assert.assertEquals("Collectors number must be same", collectorsNumber, specimenFacade.getCollectorsNumber());
826 specimenFacade.setCollectorsNumber("C12345693");
827 Assert.assertEquals("New collectors number must be 'C12345693'", "C12345693", specimenFacade.getCollectorsNumber());
828 }
829
830 /**
831 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getTitleCache()}.
832 */
833 @Test
834 public void testGetTitleCache() {
835 Assert.assertNotNull("The title cache should never return null if not protected", specimenFacade.getTitleCache());
836 specimenFacade.setTitleCache(null, false);
837 Assert.assertNotNull("The title cache should never return null if not protected", specimenFacade.getTitleCache());
838 }
839
840 /**
841 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#setTitleCache(java.lang.String)}.
842 */
843 @Test
844 public void testSetTitleCache() {
845 String testTitle = "Absdwk aksjlf";
846 specimenFacade.setTitleCache(testTitle, true);
847 Assert.assertEquals("Protected title cache should returns the test title", testTitle, specimenFacade.getTitleCache());
848 specimenFacade.setTitleCache(testTitle, false);
849 Assert.assertFalse("Unprotected title cache should not return the test title", testTitle.equals(specimenFacade.getTitleCache()));
850 }
851
852 /**
853 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getDerivedUnit()}.
854 */
855 @Test
856 public void testGetSpecimen() {
857 Assert.assertEquals("Specimen must be same", specimen, specimenFacade.getDerivedUnit());
858 }
859
860 /**
861 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade#getCollection()}.
862 */
863 @Test
864 public void testGetSetCollection() {
865 Assert.assertNotNull("Collection must not be null", specimenFacade.getCollection());
866 Assert.assertEquals("Collection must be same", collection, specimenFacade.getCollection());
867 specimenFacade.setCollection(null);
868 Assert.assertNull("Collection must be null", specimenFacade.getCollection());
869 }
870
871 @Test
872 public void testAddGetRemoveSource(){
873 Assert.assertEquals("No sources should exist yet", 0, specimenFacade.getSources().size());
874 ReferenceBase reference = ReferenceFactory.newBook();
875 IdentifiableSource source1 = specimenFacade.addSource(reference, "54", "myName");
876 Assert.assertEquals("One source should exist now", 1, specimenFacade.getSources().size());
877 IdentifiableSource source2 = IdentifiableSource.NewInstance("1", "myTable");
878 specimenFacade.addSource(source2);
879 Assert.assertEquals("One source should exist now", 2, specimenFacade.getSources().size());
880 specimenFacade.removeSource(source1);
881 Assert.assertEquals("One source should exist now", 1, specimenFacade.getSources().size());
882 ReferenceBase reference2 = ReferenceFactory.newJournal();
883 IdentifiableSource sourceNotUsed = specimenFacade.addSource(reference2, null, null);
884 specimenFacade.removeSource(sourceNotUsed);
885 Assert.assertEquals("One source should still exist", 1, specimenFacade.getSources().size());
886 Assert.assertEquals("1", specimenFacade.getSources().iterator().next().getIdInSource()) ;
887 specimenFacade.removeSource(source2);
888 Assert.assertEquals("No sources should exist anymore", 0, specimenFacade.getSources().size());
889 }
890
891 @Test
892 public void testAddGetRemoveDuplicate(){
893 Assert.assertEquals("No duplicates should be available yet", 0, specimenFacade.getDuplicates().size());
894 Specimen newSpecimen1 = Specimen.NewInstance();
895 specimenFacade.addDuplicate(newSpecimen1);
896 Assert.assertEquals("There should be 1 duplicate now", 1, specimenFacade.getDuplicates().size());
897 Specimen newSpecimen2 = Specimen.NewInstance();
898 DerivationEvent newDerivationEvent = DerivationEvent.NewInstance();
899 newSpecimen2.setDerivedFrom(newDerivationEvent);
900 Assert.assertSame("The derivation event should be 'newDerivationEvent'", newDerivationEvent, newSpecimen2.getDerivedFrom());
901 specimenFacade.addDuplicate(newSpecimen2);
902 Assert.assertEquals("There should be 2 duplicates now", 2, specimenFacade.getDuplicates().size());
903 Assert.assertNotSame("The derivation event should not be 'newDerivationEvent' anymore", newDerivationEvent, newSpecimen2.getDerivedFrom());
904 Assert.assertSame("The derivation event should not be the facades derivation event", derivationEvent, newSpecimen2.getDerivedFrom());
905 specimenFacade.removeDuplicate(newSpecimen1);
906 Assert.assertEquals("There should be 1 duplicate now", 1, specimenFacade.getDuplicates().size());
907 Assert.assertSame("The only duplicate should be 'newSpecimen2' now", newSpecimen2, specimenFacade.getDuplicates().iterator().next());
908 specimenFacade.addDuplicate(specimenFacade.getDerivedUnit());
909 Assert.assertEquals("There should be still 1 duplicate because the facade specimen is not a duplicate", 1, specimenFacade.getDuplicates().size());
910
911 Collection newCollection = Collection.NewInstance();
912 String catalogNumber = "1234890";
913 String accessionNumber = "345345";
914 String collectorsNumber = "lkjewe";
915 TaxonNameBase storedUnder = BotanicalName.NewInstance(Rank.SPECIES());
916 PreservationMethod method = PreservationMethod.NewInstance();
917 Specimen duplicateSpecimen = specimenFacade.addDuplicate(newCollection, catalogNumber, accessionNumber, collectorsNumber, storedUnder, method);
918 Assert.assertEquals("There should be 2 duplicates now", 2, specimenFacade.getDuplicates().size());
919 specimenFacade.removeDuplicate(newSpecimen2);
920 Assert.assertEquals("There should be 1 duplicates now", 1, specimenFacade.getDuplicates().size());
921 Collection sameCollection = specimenFacade.getDuplicates().iterator().next().getCollection();
922 Assert.assertSame("Collections should be same", newCollection, sameCollection);
923 }
924
925 // ************************** Existing Specimen with multiple derivation events in line **************/
926
927 @Test
928 public void testExistingSpecimen(){
929 specimenFacade = null;
930 try {
931 specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
932 } catch (DerivedUnitFacadeNotSupportedException e) {
933 Assert.fail("Multiple derivation events in line should not throw a not supported exception");
934 }
935 Assert.assertSame("Gathering event should derive from the derivation line", existingGatheringEvent, specimenFacade.getGatheringEvent());
936 Assert.assertEquals("Mediasize should be 0. Only Imagegallery media are supported", 0, specimenFacade.getFieldObjectMedia().size());
937 }
938
939 @Test
940 public void testMultipleFieldObservationsNotSupported(){
941 specimenFacade = null;
942 FieldObservation secondFieldObject = FieldObservation.NewInstance();
943 firstDerivationEvent.addOriginal(secondFieldObject);
944 try {
945 specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
946 Assert.fail("Multiple field observations for one specimen should no be supported by the facade");
947 } catch (DerivedUnitFacadeNotSupportedException e) {
948 //ok
949 }
950 Assert.assertNull("Specimen facade should not be initialized", specimenFacade);
951 }
952
953 @Test
954 public void testOnlyImageGallerySupported(){
955 specimenFacade = null;
956 firstFieldObject.addMedia(media1);
957 try {
958 specimenFacade = DerivedUnitFacade.NewInstance(collectionSpecimen);
959 Assert.fail("Only image galleries are supported by the facade but not direct media");
960 } catch (DerivedUnitFacadeNotSupportedException e) {
961 //ok
962 }
963 Assert.assertNull("Specimen facade should not be initialized", specimenFacade);
964 }
965
966 @Test
967 public void testEventPropagation(){
968 specimenFacade.setDistanceToGround(24);
969
970 }
971
972
973 }