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 java.io.FileNotFoundException;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.junit.Assert;
|
15
|
import org.junit.Before;
|
16
|
import org.junit.Test;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.agent.Person;
|
19
|
import eu.etaxonomy.cdm.model.agent.Team;
|
20
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
21
|
import eu.etaxonomy.cdm.model.common.Language;
|
22
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
23
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
24
|
import eu.etaxonomy.cdm.model.location.Country;
|
25
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
26
|
import eu.etaxonomy.cdm.model.location.Point;
|
27
|
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
|
28
|
import eu.etaxonomy.cdm.model.media.Media;
|
29
|
import eu.etaxonomy.cdm.model.name.Rank;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
31
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
|
39
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
40
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
41
|
|
42
|
/**
|
43
|
* @author a.mueller
|
44
|
* @date 03.06.2010
|
45
|
*
|
46
|
*/
|
47
|
public class DerivedUnitFacadeCacheStrategyTest extends CdmIntegrationTest {
|
48
|
@SuppressWarnings("unused")
|
49
|
private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.class);
|
50
|
|
51
|
DerivedUnit specimen;
|
52
|
DerivationEvent derivationEvent;
|
53
|
FieldUnit fieldUnit;
|
54
|
GatheringEvent gatheringEvent;
|
55
|
Integer absoluteElevation = 40;
|
56
|
Integer absoluteElevationError = 2;
|
57
|
Team collector = Team.NewInstance();
|
58
|
String collectingMethod = "Collection Method";
|
59
|
Double distanceToGround = 22.0;
|
60
|
Double distanceToSurface = 50.0;
|
61
|
ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
|
62
|
Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
|
63
|
String gatheringEventDescription = "A nice gathering description";
|
64
|
TimePeriod gatheringPeriod = TimePeriodParser.parseString("03.05.2005");
|
65
|
String ecology = "sand dunes";
|
66
|
String plantDescription = "flowers blue";
|
67
|
|
68
|
String fieldNumber = "5678";
|
69
|
String fieldNotes = "such a beautiful specimen";
|
70
|
Person primaryCollector;
|
71
|
|
72
|
Integer individualCount = 1;
|
73
|
DefinedTerm lifeStage = DefinedTerm.NewStageInstance("A wonderful stage", "stage", "st");
|
74
|
DefinedTerm sex = DefinedTerm.NewSexInstance("FemaleMale", "FM", "FM");
|
75
|
LanguageString locality = LanguageString.NewInstance("Berlin-Dahlem, E side of Englerallee", Language.DEFAULT());
|
76
|
NamedArea country = Country.GERMANY();
|
77
|
|
78
|
String exsiccatum = "Greuter, Pl. Dahlem. 456";
|
79
|
String accessionNumber = "8909756";
|
80
|
String catalogNumber = "UU879873590";
|
81
|
TaxonNameBase<?,?> taxonName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS(), "Abies", null, null, null, null, null, null, null);
|
82
|
String collectorsNumber = "234589913A34";
|
83
|
Collection collection = Collection.NewInstance();
|
84
|
|
85
|
PreservationMethod preservationMethod = PreservationMethod.NewInstance(null, "my prservation");
|
86
|
|
87
|
DerivedUnitFacade specimenFacade;
|
88
|
|
89
|
DerivedUnit collectionSpecimen;
|
90
|
GatheringEvent existingGatheringEvent;
|
91
|
DerivationEvent firstDerivationEvent;
|
92
|
FieldUnit firstFieldObject;
|
93
|
Media media1 = Media.NewInstance();
|
94
|
|
95
|
|
96
|
//****************************** SET UP *****************************************/
|
97
|
|
98
|
// /**
|
99
|
// * @throws java.lang.Exception
|
100
|
// */
|
101
|
// @BeforeClass
|
102
|
// public static void setUpBeforeClass() throws Exception {
|
103
|
// // FIXME maybe this will cause problems in other tests
|
104
|
// // INDEED !!!! it causes problems thus this is replaced by making this test a CdmIntegrationTest !!!
|
105
|
// new DefaultTermInitializer().initialize();
|
106
|
// }
|
107
|
|
108
|
/**
|
109
|
* @throws java.lang.Exception
|
110
|
*/
|
111
|
@Before
|
112
|
public void setUp() throws Exception {
|
113
|
specimen = DerivedUnit.NewPreservedSpecimenInstance();
|
114
|
|
115
|
derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
|
116
|
specimen.setDerivedFrom(derivationEvent);
|
117
|
fieldUnit = FieldUnit.NewInstance();
|
118
|
fieldUnit.addDerivationEvent(derivationEvent);
|
119
|
gatheringEvent = GatheringEvent.NewInstance();
|
120
|
fieldUnit.setGatheringEvent(gatheringEvent);
|
121
|
gatheringEvent.setAbsoluteElevation(absoluteElevation);
|
122
|
// gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
|
123
|
gatheringEvent.setActor(collector);
|
124
|
gatheringEvent.setCollectingMethod(collectingMethod);
|
125
|
gatheringEvent.setDistanceToGround(distanceToGround);
|
126
|
gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
|
127
|
gatheringEvent.setExactLocation(exactLocation);
|
128
|
gatheringEvent.setDescription(gatheringEventDescription);
|
129
|
|
130
|
gatheringEvent.setTimeperiod(gatheringPeriod);
|
131
|
gatheringEvent.setLocality(locality);
|
132
|
gatheringEvent.setCountry(country);
|
133
|
|
134
|
fieldUnit.setFieldNumber(fieldNumber);
|
135
|
fieldUnit.setFieldNotes(fieldNotes);
|
136
|
fieldUnit.setIndividualCount(individualCount);
|
137
|
fieldUnit.setSex(sex);
|
138
|
fieldUnit.setLifeStage(lifeStage);
|
139
|
primaryCollector = Person.NewTitledInstance("Kilian");
|
140
|
collector.addTeamMember(primaryCollector);
|
141
|
Person secondCollector = Person.NewInstance();
|
142
|
secondCollector.setFirstname("Andreas");
|
143
|
secondCollector.setLastname("Muller");
|
144
|
collector.addTeamMember(secondCollector);
|
145
|
Person thirdCollector = Person.NewTitledInstance("Kohlbecker");
|
146
|
collector.addTeamMember(thirdCollector);
|
147
|
fieldUnit.setPrimaryCollector(primaryCollector);
|
148
|
|
149
|
specimen.setAccessionNumber(accessionNumber);
|
150
|
specimen.setCatalogNumber(catalogNumber);
|
151
|
specimen.setStoredUnder(taxonName);
|
152
|
specimen.setCollection(collection);
|
153
|
specimen.setPreservation(preservationMethod);
|
154
|
specimen.setExsiccatum(exsiccatum);
|
155
|
|
156
|
specimenFacade = DerivedUnitFacade.NewInstance(specimen);
|
157
|
|
158
|
//existing specimen with 2 derivation events in line
|
159
|
collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
|
160
|
DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
|
161
|
firstFieldObject = FieldUnit.NewInstance();
|
162
|
|
163
|
//TODO maybe we should define concrete event types here
|
164
|
DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance(null);
|
165
|
DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance(null);
|
166
|
firstDerivationEvent = DerivationEvent.NewInstance(null);
|
167
|
|
168
|
collectionSpecimen.setDerivedFrom(lastDerivationEvent);
|
169
|
|
170
|
lastDerivationEvent.addOriginal(middleSpecimen);
|
171
|
middleSpecimen.setDerivedFrom(firstDerivationEvent);
|
172
|
firstDerivationEvent.addOriginal(firstFieldObject);
|
173
|
existingGatheringEvent = GatheringEvent.NewInstance();
|
174
|
firstFieldObject.setGatheringEvent(existingGatheringEvent);
|
175
|
|
176
|
}
|
177
|
/**
|
178
|
* Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
|
179
|
*/
|
180
|
@Test
|
181
|
public void testGetTitleCache() {
|
182
|
String correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), sand dunes, 3.5.2005, Kilian 5678, A. Muller & Kohlbecker; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
|
183
|
specimenFacade.setEcology(ecology);
|
184
|
specimenFacade.setPlantDescription(plantDescription);
|
185
|
collection.setCode("B");
|
186
|
Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
|
191
|
*/
|
192
|
@Test
|
193
|
public void testGetTitleCacheWithEtAl() {
|
194
|
String correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), sand dunes, 3.5.2005, Kilian 5678, A. Muller, Kohlbecker & al.; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
|
195
|
collector.setHasMoreMembers(true);
|
196
|
specimenFacade.setEcology(ecology);
|
197
|
specimenFacade.setPlantDescription(plantDescription);
|
198
|
collection.setCode("B");
|
199
|
Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
public void createTestDataSet() throws FileNotFoundException {}
|
204
|
}
|