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