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