Project

General

Profile

Download (9.36 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
 * @deprecated with #9678 a similar cache strategy (DerivedUnitCacheStrategy)
45
 *      was implemented in cdmlib-model. This class may be removed in future.
46
 */
47
@Deprecated
48
public class DerivedUnitFacadeCacheStrategyTest extends TermTestBase {
49

    
50
    @SuppressWarnings("unused")
51
	private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategyTest.class);
52

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

    
70
	private String fieldNumber = "5678";
71
	private String fieldNotes = "such a beautiful specimen";
72
	private Person primaryCollector;
73

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

    
80
	private String exsiccatum = "Greuter, Pl. Dahlem. 456";
81
	private String accessionNumber = "8909756";
82
	private String catalogNumber = "UU879873590";
83
	private String barcode = "B12345678";
84
	private TaxonName taxonName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS(), "Abies", null, null, null, null, null, null, null);
85
	private String collectorsNumber = "234589913A34";
86
	private Collection collection = Collection.NewInstance();
87

    
88
	private PreservationMethod preservationMethod = PreservationMethod.NewInstance(null, "my prservation");
89

    
90
	private DerivedUnitFacade specimenFacade;
91

    
92
	private DerivedUnit collectionSpecimen;
93
	private GatheringEvent existingGatheringEvent;
94
	private DerivationEvent firstDerivationEvent;
95
	private FieldUnit firstFieldObject;
96
	private Media media1 = Media.NewInstance();
97

    
98
//****************************** SET UP *****************************************/
99

    
100
	@Before
101
	public void setUp() throws Exception {
102
		specimen = DerivedUnit.NewPreservedSpecimenInstance();
103

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

    
119
		gatheringEvent.setTimeperiod(gatheringPeriod);
120
		gatheringEvent.setLocality(locality);
121
		gatheringEvent.setCountry(country);
122

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

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

    
146
		specimenFacade = DerivedUnitFacade.NewInstance(specimen);
147

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

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

    
158
		collectionSpecimen.setDerivedFrom(lastDerivationEvent);
159

    
160
		lastDerivationEvent.addOriginal(middleSpecimen);
161
		middleSpecimen.setDerivedFrom(firstDerivationEvent);
162
		firstDerivationEvent.addOriginal(firstFieldObject);
163
		existingGatheringEvent = GatheringEvent.NewInstance();
164
		firstFieldObject.setGatheringEvent(existingGatheringEvent);
165
	}
166

    
167
	@Test
168
	public void testGetTitleCache() {
169
		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; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
170
		specimenFacade.setEcology(ecology);
171
		specimenFacade.setPlantDescription(plantDescription);
172
		collection.setCode("B");
173
		Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
174
        collection.setCode(null);
175
        collection.setName("Herbarium Berolinense");
176
        Assert.assertEquals(correctCache.replace("B 8909756", "Herbarium Berolinense 8909756"), specimenFacade.getTitleCache());
177
	}
178

    
179
    @Test
180
    public void testGetTitleCacheWithEtAl() {
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 May 2005, Kilian 5678, A. Muller, Kohlbecker & al.; Greuter, Pl. Dahlem. 456 (B 8909756); flowers blue.";
182
        collector.setHasMoreMembers(true);
183
        specimenFacade.setEcology(ecology);
184
        specimenFacade.setPlantDescription(plantDescription);
185
        collection.setCode("B");
186
        Assert.assertEquals(correctCache, specimenFacade.getTitleCache());
187
    }
188

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