Project

General

Profile

Download (9.46 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 java.io.FileNotFoundException;
12

    
13
import org.apache.log4j.Logger;
14
import org.junit.Assert;
15
import org.junit.Before;
16
import org.junit.Test;
17

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

    
42
/**
43
 * @author a.mueller
44
 * @date 03.06.2010
45
 *
46
 */
47
public class DerivedUnitFacadeCacheStrategyTest extends CdmIntegrationTest {
48
	@SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.class);
50

    
51
	DerivedUnit specimen;
52
	DerivationEvent derivationEvent;
53
	FieldUnit fieldUnit;
54
	GatheringEvent gatheringEvent;
55
	Integer absoluteElevation = 40;
56
	Integer absoluteElevationError = 2;
57
	Team collector = Team.NewInstance();
58
	String collectingMethod = "Collection Method";
59
	Double distanceToGround = 22.0;
60
	Double distanceToSurface = 50.0;
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 = TimePeriodParser.parseString("03.05.2005");
65
	String ecology = "sand dunes";
66
	String plantDescription = "flowers blue";
67

    
68
	String fieldNumber = "5678";
69
	String fieldNotes = "such a beautiful specimen";
70
	Person primaryCollector;
71

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

    
78
	String exsiccatum = "Greuter, Pl. Dahlem. 456";
79
	String accessionNumber = "8909756";
80
	String catalogNumber = "UU879873590";
81
	String barcode = "B12345678";
82
	TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(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(null, "my prservation");
87

    
88
	DerivedUnitFacade specimenFacade;
89

    
90
	DerivedUnit collectionSpecimen;
91
	GatheringEvent existingGatheringEvent;
92
	DerivationEvent firstDerivationEvent;
93
	FieldUnit 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
	@Before
110
	public void setUp() throws Exception {
111
		specimen = DerivedUnit.NewPreservedSpecimenInstance();
112

    
113
		derivationEvent = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
114
		specimen.setDerivedFrom(derivationEvent);
115
		fieldUnit = FieldUnit.NewInstance();
116
		fieldUnit.addDerivationEvent(derivationEvent);
117
		gatheringEvent = GatheringEvent.NewInstance();
118
		fieldUnit.setGatheringEvent(gatheringEvent);
119
		gatheringEvent.setAbsoluteElevation(absoluteElevation);
120
//		gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
121
		gatheringEvent.setActor(collector);
122
		gatheringEvent.setCollectingMethod(collectingMethod);
123
		gatheringEvent.setDistanceToGround(distanceToGround);
124
		gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
125
		gatheringEvent.setExactLocation(exactLocation);
126
		gatheringEvent.setDescription(gatheringEventDescription);
127

    
128
		gatheringEvent.setTimeperiod(gatheringPeriod);
129
		gatheringEvent.setLocality(locality);
130
		gatheringEvent.setCountry(country);
131

    
132
		fieldUnit.setFieldNumber(fieldNumber);
133
		fieldUnit.setFieldNotes(fieldNotes);
134
		fieldUnit.setIndividualCount(individualCount);
135
		fieldUnit.setSex(sex);
136
		fieldUnit.setLifeStage(lifeStage);
137
		primaryCollector = Person.NewTitledInstance("Kilian");
138
		collector.addTeamMember(primaryCollector);
139
		Person secondCollector = Person.NewInstance();
140
		secondCollector.setFirstname("Andreas");
141
		secondCollector.setLastname("Muller");
142
		collector.addTeamMember(secondCollector);
143
		Person thirdCollector = Person.NewTitledInstance("Kohlbecker");
144
		collector.addTeamMember(thirdCollector);
145
		fieldUnit.setPrimaryCollector(primaryCollector);
146

    
147
		specimen.setAccessionNumber(accessionNumber);
148
		specimen.setCatalogNumber(catalogNumber);
149
		specimen.setBarcode(barcode);
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
	/**
189
     * Test method for {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.occurrence.Specimen)}.
190
     */
191
    @Test
192
    public void testGetTitleCacheWithEtAl() {
193
        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.";
194
        collector.setHasMoreMembers(true);
195
        specimenFacade.setEcology(ecology);
196
        specimenFacade.setPlantDescription(plantDescription);
197
        collection.setCode("B");
198
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
199
    }
200

    
201
    //#6381
202
    @Test
203
    public void testGetTitleCacheAccessionBarcodeCatalogNumber() {
204
        //Note: Collection Code B might be deduplicated in future
205
        specimenFacade.setPlantDescription(plantDescription);
206
        collection.setCode("B");
207
        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.";
208
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
209
        specimenFacade.setAccessionNumber(null);
210
        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.";
211
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
212
        specimenFacade.setBarcode(null);
213
        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.";
214
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
215
    }
216

    
217
    @Override
218
    public void createTestDataSet() throws FileNotFoundException {}
219
}
(2-2/4)