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