Project

General

Profile

Download (7.55 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.facade;
10

    
11
import org.apache.log4j.Logger;
12
import org.junit.Assert;
13
import org.junit.Before;
14
import org.junit.Test;
15

    
16
import eu.etaxonomy.cdm.model.agent.Person;
17
import eu.etaxonomy.cdm.model.agent.Team;
18
import eu.etaxonomy.cdm.model.common.Language;
19
import eu.etaxonomy.cdm.model.common.LanguageString;
20
import eu.etaxonomy.cdm.model.common.TimePeriod;
21
import eu.etaxonomy.cdm.model.location.Country;
22
import eu.etaxonomy.cdm.model.location.NamedArea;
23
import eu.etaxonomy.cdm.model.location.Point;
24
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
25
import eu.etaxonomy.cdm.model.media.Media;
26
import eu.etaxonomy.cdm.model.name.Rank;
27
import eu.etaxonomy.cdm.model.name.TaxonName;
28
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
29
import eu.etaxonomy.cdm.model.occurrence.Collection;
30
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
31
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
32
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
33
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
34
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
35
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
36
import eu.etaxonomy.cdm.model.term.DefinedTerm;
37
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
38
import eu.etaxonomy.cdm.test.TermTestBase;
39

    
40
/**
41
 * @author a.mueller
42
 * @since 03.06.2010
43
 */
44
public class DerivedUnitFacadeFieldUnitCacheStrategyTest extends TermTestBase {
45

    
46
    @SuppressWarnings("unused")
47
	private static final Logger logger = Logger.getLogger(DerivedUnitFacadeFieldUnitCacheStrategyTest.class);
48

    
49
	DerivedUnit specimen;
50
	DerivationEvent derivationEvent;
51
	FieldUnit fieldUnit;
52
	GatheringEvent gatheringEvent;
53
	Integer absoluteElevation = 40;
54
	Integer absoluteElevationError = 2;
55
	Team collector = Team.NewInstance();
56
	String collectingMethod = "Collection Method";
57
	Double distanceToGround = 22.0;
58
	Double distanceToSurface = 50.0;
59
	ReferenceSystem referenceSystem = ReferenceSystem.WGS84();
60
	Point exactLocation = Point.NewInstance(12.3, 10.567, referenceSystem, 22);
61
	String gatheringEventDescription = "A nice gathering description";
62
	TimePeriod gatheringPeriod = TimePeriodParser.parseString("03.05.2005");
63
	String ecology = "sand dunes";
64
	String plantDescription = "flowers blue";
65

    
66
	String fieldNumber = "5678";
67
	String fieldNotes = "such a beautiful specimen";
68
	Person primaryCollector;
69

    
70
	String individualCount = "1";
71
	DefinedTerm lifeStage = DefinedTerm.NewStageInstance("A wonderful stage", "stage", "st");
72
	DefinedTerm sex = DefinedTerm.NewSexInstance("FemaleMale", "FM", "FM");
73
	LanguageString locality = LanguageString.NewInstance("Berlin-Dahlem, E side of Englerallee", Language.DEFAULT());
74
	NamedArea country = Country.GERMANY();
75

    
76
	String exsiccatum = "Greuter, Pl. Dahlem. 456";
77
	String accessionNumber = "8909756";
78
	String catalogNumber = "UU879873590";
79
	TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(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(null, "my prservation");
84

    
85
	DerivedUnitFacade specimenFacade;
86

    
87
	DerivedUnit collectionSpecimen;
88
	GatheringEvent existingGatheringEvent;
89
	DerivationEvent firstDerivationEvent;
90
	FieldUnit firstFieldObject;
91
	Media media1 = Media.NewInstance();
92

    
93
//****************************** SET UP *****************************************/
94

    
95
	@Before
96
	public void setUp() throws Exception {
97
		specimen = DerivedUnit.NewPreservedSpecimenInstance();
98

    
99
		derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
100
		specimen.setDerivedFrom(derivationEvent);
101
		fieldUnit = FieldUnit.NewInstance();
102
		fieldUnit.addDerivationEvent(derivationEvent);
103
		gatheringEvent = GatheringEvent.NewInstance();
104
		fieldUnit.setGatheringEvent(gatheringEvent);
105
		gatheringEvent.setAbsoluteElevation(absoluteElevation);
106
//		gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
107
		gatheringEvent.setActor(collector);
108
		gatheringEvent.setCollectingMethod(collectingMethod);
109
		gatheringEvent.setDistanceToGround(distanceToGround);
110
		gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
111
		gatheringEvent.setExactLocation(exactLocation);
112
		gatheringEvent.setDescription(gatheringEventDescription);
113

    
114
		gatheringEvent.setTimeperiod(gatheringPeriod);
115
		gatheringEvent.setLocality(locality);
116
		gatheringEvent.setCountry(country);
117

    
118
		fieldUnit.setFieldNumber(fieldNumber);
119
		fieldUnit.setFieldNotes(fieldNotes);
120
		fieldUnit.setIndividualCount(individualCount);
121
		fieldUnit.setSex(sex);
122
		fieldUnit.setLifeStage(lifeStage);
123
		primaryCollector = Person.NewTitledInstance("Kilian");
124
		collector.addTeamMember(primaryCollector);
125
		Person secondCollector = Person.NewInstance();
126
		secondCollector.setGivenName("Andreas");
127
		secondCollector.setFamilyName("Muller");
128
		collector.addTeamMember(secondCollector);
129
		Person thirdCollector = Person.NewTitledInstance("Kohlbecker");
130
		collector.addTeamMember(thirdCollector);
131
		fieldUnit.setPrimaryCollector(primaryCollector);
132

    
133
		specimen.setAccessionNumber(accessionNumber);
134
		specimen.setCatalogNumber(catalogNumber);
135
		specimen.setStoredUnder(taxonName);
136
		specimen.setCollection(collection);
137
		specimen.setPreservation(preservationMethod);
138
		specimen.setExsiccatum(exsiccatum);
139

    
140
		specimenFacade = DerivedUnitFacade.NewInstance(specimen);
141

    
142
		//existing specimen with 2 derivation events in line
143
		collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
144
		DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
145
		firstFieldObject = FieldUnit.NewInstance();
146

    
147
		//TODO maybe we should define concrete event types here
148
		DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance(null);
149
		DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance(null);
150
		firstDerivationEvent = DerivationEvent.NewInstance(null);
151

    
152
		collectionSpecimen.setDerivedFrom(lastDerivationEvent);
153

    
154
		lastDerivationEvent.addOriginal(middleSpecimen);
155
		middleSpecimen.setDerivedFrom(firstDerivationEvent);
156
		firstDerivationEvent.addOriginal(firstFieldObject);
157
		existingGatheringEvent = GatheringEvent.NewInstance();
158
		firstFieldObject.setGatheringEvent(existingGatheringEvent);
159
	}
160

    
161
	@Test
162
	public void testGetTitleCache() {
163
		String correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), sand dunes, 3 May 2005, Kilian 5678, A. Muller & Kohlbecker; flowers blue.";
164
		specimenFacade.setEcology(ecology);
165
		specimenFacade.setPlantDescription(plantDescription);
166
		collection.setCode("B");
167
		Assert.assertEquals(correctCache, specimenFacade.innerFieldUnit().getTitleCache());
168

    
169
		//freetext without unit
170
		String altitudeText = "approx. 40";
171
		specimenFacade.setAbsoluteElevationText(altitudeText);
172
		String expected = correctCache.replace("alt. 40 m", "alt. "+ altitudeText);
173
		Assert.assertEquals(expected, specimenFacade.innerFieldUnit().getTitleCache());
174

    
175
		//freetext with unit
176
		String altitudeTextM = "approx. 40 m";
177
		specimenFacade.setAbsoluteElevationText(altitudeTextM);
178
		expected = correctCache.replace("alt. 40 m", "alt. "+ altitudeTextM);
179
		Assert.assertEquals(expected, specimenFacade.innerFieldUnit().getTitleCache());
180
	}
181
}
(3-3/4)