Project

General

Profile

Download (8.99 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.DefinedTerm;
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.common.LanguageString;
21
import eu.etaxonomy.cdm.model.common.TimePeriod;
22
import eu.etaxonomy.cdm.model.location.Country;
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.media.Media;
27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.model.name.TaxonName;
29
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
30
import eu.etaxonomy.cdm.model.occurrence.Collection;
31
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
32
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
33
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
34
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
35
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
36
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
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
 */
45
public class DerivedUnitFacadeCacheStrategyTest extends TermTestBase {
46
	@SuppressWarnings("unused")
47
	private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.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
	Integer 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
	String barcode = "B12345678";
80
	TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(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(null, "my prservation");
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
	@Before
99
	public void setUp() throws Exception {
100
		specimen = DerivedUnit.NewPreservedSpecimenInstance();
101

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

    
117
		gatheringEvent.setTimeperiod(gatheringPeriod);
118
		gatheringEvent.setLocality(locality);
119
		gatheringEvent.setCountry(country);
120

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

    
136
		specimen.setAccessionNumber(accessionNumber);
137
		specimen.setCatalogNumber(catalogNumber);
138
		specimen.setBarcode(barcode);
139
		specimen.setStoredUnder(taxonName);
140
		specimen.setCollection(collection);
141
		specimen.setPreservation(preservationMethod);
142
		specimen.setExsiccatum(exsiccatum);
143

    
144
		specimenFacade = DerivedUnitFacade.NewInstance(specimen);
145

    
146
		//existing specimen with 2 derivation events in line
147
		collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
148
		DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
149
		firstFieldObject = FieldUnit.NewInstance();
150

    
151
		//TODO maybe we should define concrete event types here
152
		DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance(null);
153
		DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance(null);
154
		firstDerivationEvent = DerivationEvent.NewInstance(null);
155

    
156
		collectionSpecimen.setDerivedFrom(lastDerivationEvent);
157

    
158
		lastDerivationEvent.addOriginal(middleSpecimen);
159
		middleSpecimen.setDerivedFrom(firstDerivationEvent);
160
		firstDerivationEvent.addOriginal(firstFieldObject);
161
		existingGatheringEvent = GatheringEvent.NewInstance();
162
		firstFieldObject.setGatheringEvent(existingGatheringEvent);
163

    
164
	}
165
	/**
166
	 * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
167
	 */
168
	@Test
169
	public void testGetTitleCache() {
170
		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.";
171
		specimenFacade.setEcology(ecology);
172
		specimenFacade.setPlantDescription(plantDescription);
173
		collection.setCode("B");
174
		Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
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 testGetTitleCacheWithEtAl() {
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 & al.; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
183
        collector.setHasMoreMembers(true);
184
        specimenFacade.setEcology(ecology);
185
        specimenFacade.setPlantDescription(plantDescription);
186
        collection.setCode("B");
187
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
188
    }
189

    
190
    //#6381
191
    @Test
192
    public void testGetTitleCacheAccessionBarcodeCatalogNumber() {
193
        //Note: Collection Code B might be deduplicated in future
194
        specimenFacade.setPlantDescription(plantDescription);
195
        collection.setCode("B");
196
        String correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), 3.5.2005, Kilian 5678, A. Muller & Kohlbecker; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
197
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
198
        specimenFacade.setAccessionNumber(null);
199
        correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), 3.5.2005, Kilian 5678, A. Muller & Kohlbecker; Greuter, Pl. Dahlem. 456 (B B12345678); flowers blue.";
200
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
201
        specimenFacade.setBarcode(null);
202
        correctCache = "Germany, Berlin-Dahlem, E side of Englerallee, alt. 40 m, 10\u00B034'1.2\"N, 12\u00B018'E (WGS84), 3.5.2005, Kilian 5678, A. Muller & Kohlbecker; Greuter, Pl. Dahlem. 456 (B UU879873590); flowers blue.";
203
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
204
    }
205

    
206
}
(2-2/4)