AT: committing merge changes
[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 junit.framework.Assert;
13
14 import org.apache.log4j.Logger;
15 import org.junit.Before;
16 import org.junit.BeforeClass;
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.DefaultTermInitializer;
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.description.Sex;
26 import eu.etaxonomy.cdm.model.description.Stage;
27 import eu.etaxonomy.cdm.model.location.NamedArea;
28 import eu.etaxonomy.cdm.model.location.Point;
29 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
30 import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
31 import eu.etaxonomy.cdm.model.media.Media;
32 import eu.etaxonomy.cdm.model.name.BotanicalName;
33 import eu.etaxonomy.cdm.model.name.Rank;
34 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35 import eu.etaxonomy.cdm.model.occurrence.Collection;
36 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
37 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
38 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
39 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
40 import eu.etaxonomy.cdm.model.occurrence.Specimen;
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 Specimen specimen;
53 DerivationEvent derivationEvent;
54 FieldObservation fieldObservation;
55 GatheringEvent gatheringEvent;
56 Integer absoluteElevation = 40;
57 Integer absoluteElevationError = 2;
58 Team collector = Team.NewInstance();
59 String collectingMethod = "Collection Method";
60 Integer distanceToGround = 22;
61 Integer distanceToSurface = 50;
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 = TimePeriod.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 Stage lifeStage = Stage.NewInstance("A wonderful stage", "stage", "st");
75 Sex sex = Sex.NewInstance("FemaleMale", "FM", "FM");
76 LanguageString locality = LanguageString.NewInstance("Berlin-Dahlem, E side of Englerallee", Language.DEFAULT());
77 NamedArea country = WaterbodyOrCountry.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("my prservation", null, null);
87
88 DerivedUnitFacade specimenFacade;
89
90 Specimen collectionSpecimen;
91 GatheringEvent existingGatheringEvent;
92 DerivationEvent firstDerivationEvent;
93 FieldObservation 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 = Specimen.NewInstance();
115
116 derivationEvent = DerivationEvent.NewInstance();
117 specimen.setDerivedFrom(derivationEvent);
118 fieldObservation = FieldObservation.NewInstance();
119 fieldObservation.addDerivationEvent(derivationEvent);
120 gatheringEvent = GatheringEvent.NewInstance();
121 fieldObservation.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 fieldObservation.setFieldNumber(fieldNumber);
136 fieldObservation.setFieldNotes(fieldNotes);
137 fieldObservation.setIndividualCount(individualCount);
138 fieldObservation.setSex(sex);
139 fieldObservation.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 fieldObservation.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 = Specimen.NewInstance();
161 Specimen middleSpecimen = Specimen.NewInstance();
162 firstFieldObject = FieldObservation.NewInstance();
163
164 DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();
165 DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance();
166 firstDerivationEvent = DerivationEvent.NewInstance();
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 }