Project

General

Profile

Download (7.11 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.strategy.cache.occurrence;
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.description.Feature;
22
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
23
import eu.etaxonomy.cdm.model.description.TextData;
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.occurrence.DerivationEvent;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
31
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
32
import eu.etaxonomy.cdm.model.term.DefinedTerm;
33
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
34
import eu.etaxonomy.cdm.test.TermTestBase;
35

    
36
/**
37
 * Note: this class is mostly a copy from the orignal class DerivedUnitFacadeFieldUnitCacheStrategyTest
38
 *       in cdmlib-service. (#9678)
39
 *
40
 * @author a.mueller
41
 * @since 21.06.2021
42
 */
43
public class FieldUnitDefaultCacheStrategyTest extends TermTestBase {
44

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

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

    
63
	private String fieldNumber = "5678";
64
	private String fieldNotes = "such a beautiful specimen";
65
	private Person primaryCollector;
66

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

    
73
	private DerivedUnit collectionSpecimen;
74
	private GatheringEvent existingGatheringEvent;
75
	private DerivationEvent firstDerivationEvent;
76
	private FieldUnit firstFieldObject;
77

    
78
//****************************** SET UP *****************************************/
79

    
80
	@Before
81
	public void setUp() throws Exception {
82
		fieldUnit = FieldUnit.NewInstance();
83

    
84
		fieldUnit = FieldUnit.NewInstance();
85
		gatheringEvent = GatheringEvent.NewInstance();
86
		fieldUnit.setGatheringEvent(gatheringEvent);
87
		gatheringEvent.setAbsoluteElevation(absoluteElevation);
88
//		gatheringEvent.setAbsoluteElevationError(absoluteElevationError);
89
		gatheringEvent.setActor(collector);
90
		gatheringEvent.setCollectingMethod(collectingMethod);
91
		gatheringEvent.setDistanceToGround(distanceToGround);
92
		gatheringEvent.setDistanceToWaterSurface(distanceToSurface);
93
		gatheringEvent.setExactLocation(exactLocation);
94
		gatheringEvent.setDescription(gatheringEventDescription);
95

    
96
		gatheringEvent.setTimeperiod(gatheringPeriod);
97
		gatheringEvent.setLocality(locality);
98
		gatheringEvent.setCountry(country);
99

    
100
		fieldUnit.setFieldNumber(fieldNumber);
101
		fieldUnit.setFieldNotes(fieldNotes);
102
		fieldUnit.setIndividualCount(individualCount);
103
		fieldUnit.setSex(sex);
104
		fieldUnit.setLifeStage(lifeStage);
105
		primaryCollector = Person.NewTitledInstance("Kilian");
106
		collector.addTeamMember(primaryCollector);
107
		Person secondCollector = Person.NewInstance();
108
		secondCollector.setGivenName("Andreas");
109
		secondCollector.setFamilyName("Muller");
110
		collector.addTeamMember(secondCollector);
111
		Person thirdCollector = Person.NewTitledInstance("Kohlbecker");
112
		collector.addTeamMember(thirdCollector);
113
		fieldUnit.setPrimaryCollector(primaryCollector);
114

    
115
		//existing specimen with 2 derivation events in line
116
		collectionSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
117
		DerivedUnit middleSpecimen = DerivedUnit.NewPreservedSpecimenInstance();
118
		firstFieldObject = FieldUnit.NewInstance();
119

    
120
		//TODO maybe we should define concrete event types here
121
		DerivationEvent lastDerivationEvent = DerivationEvent.NewInstance(null);
122
		DerivationEvent middleDerivationEvent = DerivationEvent.NewInstance(null);
123
		firstDerivationEvent = DerivationEvent.NewInstance(null);
124

    
125
		collectionSpecimen.setDerivedFrom(lastDerivationEvent);
126

    
127
		lastDerivationEvent.addOriginal(middleSpecimen);
128
		middleSpecimen.setDerivedFrom(firstDerivationEvent);
129
		firstDerivationEvent.addOriginal(firstFieldObject);
130
		existingGatheringEvent = GatheringEvent.NewInstance();
131
		firstFieldObject.setGatheringEvent(existingGatheringEvent);
132
	}
133

    
134

    
135
    @Test
136
    public void testGetTitleCache() {
137
        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.";
138
        addEcology(fieldUnit, ecology);
139
        addPlantDescription(fieldUnit, plantDescription);
140
        Assert.assertEquals(correctCache, fieldUnit.getTitleCache());
141

    
142
        //freetext without unit
143
        String altitudeText = "approx. 40";
144
        fieldUnit.getGatheringEvent().setAbsoluteElevationText(altitudeText);
145
        String expected = correctCache.replace("alt. 40 m", "alt. "+ altitudeText);
146
        Assert.assertEquals(expected, fieldUnit.getTitleCache());
147

    
148
        //freetext with unit
149
        String altitudeTextM = "approx. 40 m";
150
        fieldUnit.getGatheringEvent().setAbsoluteElevationText(altitudeTextM);
151
        expected = correctCache.replace("alt. 40 m", "alt. "+ altitudeTextM);
152
        Assert.assertEquals(expected, fieldUnit.getTitleCache());
153
    }
154

    
155
    private void addEcology(FieldUnit fieldUnit, String ecology) {
156
        SpecimenDescription description = SpecimenDescription.NewInstance(fieldUnit);
157
        TextData textData = TextData.NewInstance(Feature.ECOLOGY(), ecology, Language.DEFAULT(), null);
158
        description.addElement(textData);
159
    }
160

    
161
    private void addPlantDescription(FieldUnit fieldUnit, String plantDescription) {
162
        SpecimenDescription description = SpecimenDescription.NewInstance(fieldUnit);
163
        TextData textData = TextData.NewInstance(Feature.DESCRIPTION(), plantDescription, Language.DEFAULT(), null);
164
        description.addElement(textData);
165
    }
166
}
(3-3/4)