change version to 3.3.0-SNAPSHOT in cdm-3.3 branch
[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.junit.Assert;
13
14 import org.apache.log4j.Logger;
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.Language;
21 import eu.etaxonomy.cdm.model.common.LanguageString;
22 import eu.etaxonomy.cdm.model.common.TimePeriod;
23 import eu.etaxonomy.cdm.model.description.Sex;
24 import eu.etaxonomy.cdm.model.description.Stage;
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.location.WaterbodyOrCountry;
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.FieldObservation;
36 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
37 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
38 import eu.etaxonomy.cdm.model.occurrence.Specimen;
39 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
40
41 /**
42 * @author a.mueller
43 * @date 03.06.2010
44 *
45 */
46 public class DerivedUnitFacadeCacheStrategyTest extends CdmIntegrationTest {
47 @SuppressWarnings("unused")
48 private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.class);
49
50 Specimen specimen;
51 DerivationEvent derivationEvent;
52 FieldObservation fieldObservation;
53 GatheringEvent gatheringEvent;
54 Integer absoluteElevation = 40;
55 Integer absoluteElevationError = 2;
56 Team collector = Team.NewInstance();
57 String collectingMethod = "Collection Method";
58 Integer distanceToGround = 22;
59 Integer distanceToSurface = 50;
60 ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
61 Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
62 String gatheringEventDescription = "A nice gathering description";
63 TimePeriod gatheringPeriod = TimePeriod.parseString("03.05.2005");
64 String ecology = "sand dunes";
65 String plantDescription = "flowers blue";
66
67 String fieldNumber = "5678";
68 String fieldNotes = "such a beautiful specimen";
69 Person primaryCollector;
70
71 Integer individualCount = 1;
72 Stage lifeStage = Stage.NewInstance("A wonderful stage", "stage", "st");
73 Sex sex = Sex.NewInstance("FemaleMale", "FM", "FM");
74 LanguageString locality = LanguageString.NewInstance("Berlin-Dahlem, E side of Englerallee", Language.DEFAULT());
75 NamedArea country = WaterbodyOrCountry.GERMANY();
76
77 String exsiccatum = "Greuter, Pl. Dahlem. 456";
78 String accessionNumber = "8909756";
79 String catalogNumber = "UU879873590";
80 TaxonNameBase<?,?> taxonName = BotanicalName.NewInstance(Rank.GENUS(), "Abies", null, null, null, null, null, null, null);
81 String collectorsNumber = "234589913A34";
82 Collection collection = Collection.NewInstance();
83
84 PreservationMethod preservationMethod = PreservationMethod.NewInstance("my prservation", null, null);
85
86 DerivedUnitFacade specimenFacade;
87
88 Specimen collectionSpecimen;
89 GatheringEvent existingGatheringEvent;
90 DerivationEvent firstDerivationEvent;
91 FieldObservation firstFieldObject;
92 Media media1 = Media.NewInstance();
93
94
95 //****************************** SET UP *****************************************/
96
97 // /**
98 // * @throws java.lang.Exception
99 // */
100 // @BeforeClass
101 // public static void setUpBeforeClass() throws Exception {
102 // // FIXME maybe this will cause problems in other tests
103 // // INDEED !!!! it causes problems thus this is replaced by making this test a CdmIntegrationTest !!!
104 // new DefaultTermInitializer().initialize();
105 // }
106
107 /**
108 * @throws java.lang.Exception
109 */
110 @Before
111 public void setUp() throws Exception {
112 specimen = Specimen.NewInstance();
113
114 derivationEvent = DerivationEvent.NewInstance();
115 specimen.setDerivedFrom(derivationEvent);
116 fieldObservation = FieldObservation.NewInstance();
117 fieldObservation.addDerivationEvent(derivationEvent);
118 gatheringEvent = GatheringEvent.NewInstance();
119 fieldObservation.setGatheringEvent(gatheringEvent);
120 gatheringEvent.setAbsoluteElevation(absoluteElevation);
121 gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
122 gatheringEvent.setActor(collector);
123 gatheringEvent.setCollectingMethod(collectingMethod);
124 gatheringEvent.setDistanceToGround(distanceToGround);
125 gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
126 gatheringEvent.setExactLocation(exactLocation);
127 gatheringEvent.setDescription(gatheringEventDescription);
128
129 gatheringEvent.setTimeperiod(gatheringPeriod);
130 gatheringEvent.setLocality(locality);
131 gatheringEvent.setCountry(country);
132
133 fieldObservation.setFieldNumber(fieldNumber);
134 fieldObservation.setFieldNotes(fieldNotes);
135 fieldObservation.setIndividualCount(individualCount);
136 fieldObservation.setSex(sex);
137 fieldObservation.setLifeStage(lifeStage);
138 primaryCollector = Person.NewTitledInstance("Kilian");
139 collector.addTeamMember(primaryCollector);
140 Person secondCollector = Person.NewInstance();
141 secondCollector.setFirstname("Andreas");
142 secondCollector.setLastname("Muller");
143 collector.addTeamMember(secondCollector);
144 Person thirdCollector = Person.NewTitledInstance("Kohlbecker");
145 collector.addTeamMember(thirdCollector);
146 fieldObservation.setPrimaryCollector(primaryCollector);
147
148 specimen.setAccessionNumber(accessionNumber);
149 specimen.setCatalogNumber(catalogNumber);
150 specimen.setStoredUnder(taxonName);
151 specimen.setCollection(collection);
152 specimen.setPreservation(preservationMethod);
153 specimen.setExsiccatum(exsiccatum);
154
155 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
156
157 //existing specimen with 2 derivation events in line
158 collectionSpecimen = Specimen.NewInstance();
159 Specimen middleSpecimen = Specimen.NewInstance();
160 firstFieldObject = FieldObservation.NewInstance();
161
162 DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();
163 DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance();
164 firstDerivationEvent = DerivationEvent.NewInstance();
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 }