Project

General

Profile

Download (7.6 KB) Statistics
| Branch: | Tag: | Revision:
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.FieldUnit;
36
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
37
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
38
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
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
	DerivedUnit specimen;
51
	DerivationEvent derivationEvent;
52
	FieldUnit fieldUnit;
53
	GatheringEvent gatheringEvent;
54
	Integer absoluteElevation = 40;
55
	Integer absoluteElevationError = 2;
56
	Team collector = Team.NewInstance();
57
	String collectingMethod = "Collection Method";
58
	Double distanceToGround = 22.0;
59
	Double distanceToSurface = 50.0;
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 = TimePeriodParser.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
	DefinedTerm lifeStage = DefinedTerm.NewStageInstance("A wonderful stage", "stage", "st");
73
	DefinedTerm sex = DefinedTerm.NewSexInstance("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
	DerivedUnit collectionSpecimen;
89
	GatheringEvent existingGatheringEvent;
90
	DerivationEvent firstDerivationEvent;
91
	FieldUnit 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 = DerivedUnit.NewPreservedSpecimenInstance();
113

    
114
		derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
115
		specimen.setDerivedFrom(derivationEvent);
116
		fieldUnit = FieldUnit.NewInstance();
117
		fieldUnit.addDerivationEvent(derivationEvent);
118
		gatheringEvent = GatheringEvent.NewInstance();
119
		fieldUnit.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
		fieldUnit.setFieldNumber(fieldNumber);
134
		fieldUnit.setFieldNotes(fieldNotes);
135
		fieldUnit.setIndividualCount(individualCount);
136
		fieldUnit.setSex(sex);
137
		fieldUnit.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
		fieldUnit.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 = DerivedUnit.NewPreservedSpecimenInstance();
159
		DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
160
		firstFieldObject = FieldUnit.NewInstance();
161

    
162
		//TODO maybe we should define concrete event types here
163
		DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance(null);
164
		DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance(null);
165
		firstDerivationEvent = DerivationEvent.NewInstance(null);
166

    
167
		collectionSpecimen.setDerivedFrom(lastDerivationEvent);
168

    
169
		lastDerivationEvent.addOriginal(middleSpecimen);
170
		middleSpecimen.setDerivedFrom(firstDerivationEvent);
171
		firstDerivationEvent.addOriginal(firstFieldObject);
172
		existingGatheringEvent = GatheringEvent.NewInstance();
173
		firstFieldObject.setGatheringEvent(existingGatheringEvent);
174

    
175
	}
176
	/**
177
	 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
178
	 */
179
	@Test
180
	public void testGetTitleCache() {
181
		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.";
182
		specimenFacade.setEcology(ecology);
183
		specimenFacade.setPlantDescription(plantDescription);
184
		collection.setCode("B");
185
		Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
186
	}
187

    
188
}
(1-1/3)