1199f336846082718c5b0ef96d34f749baf2f6af
[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.AgentBase;
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
42 /**
43 * @author a.mueller
44 * @date 03.06.2010
45 *
46 */
47 public class DerivedUnitFacadeCacheStrategyTest {
48 @SuppressWarnings("unused")
49 private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.class);
50
51 Specimen specimen;
52 DerivationEvent derivationEvent;
53 FieldObservation fieldObservation;
54 GatheringEvent gatheringEvent;
55 Integer absoluteElevation = 40;
56 Integer absoluteElevationError = 2;
57 AgentBase collector = Team.NewInstance();
58 String collectingMethod = "Collection Method";
59 Integer distanceToGround = 22;
60 Integer distanceToSurface = 50;
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 = TimePeriod.parseString("05.05.2005");
65 String ecology = "sand dunes";
66 String plantDescription = "flowers blue";
67
68 String fieldNumber = "15p23B";
69 String fieldNotes = "such a beautiful specimen";
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 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 Specimen collectionSpecimen;
88 GatheringEvent existingGatheringEvent;
89 DerivationEvent firstDerivationEvent;
90 FieldObservation firstFieldObject;
91 Media media1 = Media.NewInstance();
92
93 //****************************** SET UP *****************************************/
94
95 /**
96 * @throws java.lang.Exception
97 */
98 @BeforeClass
99 public static void setUpBeforeClass() throws Exception {
100 // FIXME maybe this will cause problems in other tests
101 new DefaultTermInitializer().initialize();
102 }
103
104 /**
105 * @throws java.lang.Exception
106 */
107 @Before
108 public void setUp() throws Exception {
109 specimen = Specimen.NewInstance();
110
111 derivationEvent = DerivationEvent.NewInstance();
112 specimen.setDerivedFrom(derivationEvent);
113 fieldObservation = FieldObservation.NewInstance();
114 fieldObservation.addDerivationEvent(derivationEvent);
115 gatheringEvent = GatheringEvent.NewInstance();
116 fieldObservation.setGatheringEvent(gatheringEvent);
117 gatheringEvent.setAbsoluteElevation(absoluteElevation);
118 gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
119 gatheringEvent.setActor(collector);
120 gatheringEvent.setCollectingMethod(collectingMethod);
121 gatheringEvent.setDistanceToGround(distanceToGround);
122 gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
123 gatheringEvent.setExactLocation(exactLocation);
124 gatheringEvent.setDescription(gatheringEventDescription);
125
126 gatheringEvent.setTimeperiod(gatheringPeriod);
127 gatheringEvent.setLocality(locality);
128 gatheringEvent.setCountry(country);
129
130 fieldObservation.setFieldNumber(fieldNumber);
131 fieldObservation.setFieldNotes(fieldNotes);
132 fieldObservation.setIndividualCount(individualCount);
133 fieldObservation.setSex(sex);
134 fieldObservation.setLifeStage(lifeStage);
135
136 specimen.setAccessionNumber(accessionNumber);
137 specimen.setCatalogNumber(catalogNumber);
138 specimen.setStoredUnder(taxonName);
139 specimen.setCollectorsNumber(collectorsNumber);
140 specimen.setCollection(collection);
141 specimen.setPreservation(preservationMethod);
142
143 specimenFacade = DerivedUnitFacade.NewInstance(specimen);
144
145 //existing specimen with 2 derivation events in line
146 collectionSpecimen = Specimen.NewInstance();
147 Specimen middleSpecimen = Specimen.NewInstance();
148 firstFieldObject = FieldObservation.NewInstance();
149
150 DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance();
151 DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance();
152 firstDerivationEvent = DerivationEvent.NewInstance();
153
154 collectionSpecimen.setDerivedFrom(lastDerivationEvent);
155
156 lastDerivationEvent.addOriginal(middleSpecimen);
157 middleSpecimen.setDerivedFrom(firstDerivationEvent);
158 firstDerivationEvent.addOriginal(firstFieldObject);
159 existingGatheringEvent = GatheringEvent.NewInstance();
160 firstFieldObject.setGatheringEvent(existingGatheringEvent);
161
162 }
163 /**
164 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
165 */
166 @Test
167 public void testGetTitleCache() {
168 String correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10°34'1\"N, 12°18'E (WGS84), sand dunes, 05.05.2005 (B 8909756); flowers blue.";
169 specimenFacade.setEcology(ecology);
170 specimenFacade.setPlantDescription(plantDescription);
171 collection.setCode("B");
172 Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
173 }
174
175 }