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