1
|
/**
|
2
|
* Copyright (C) 2017 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.vaadin.util.converter;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.io.FileNotFoundException;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.Collection;
|
17
|
import java.util.Iterator;
|
18
|
import java.util.LinkedHashMap;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.junit.Before;
|
24
|
import org.junit.Test;
|
25
|
|
26
|
import eu.etaxonomy.cdm.CdmVaadinIntegrationTest;
|
27
|
import eu.etaxonomy.cdm.api.service.exception.RegistrationValidationException;
|
28
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager;
|
29
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager.TypeDesignationWorkingSet;
|
30
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
31
|
import eu.etaxonomy.cdm.model.name.Rank;
|
32
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
33
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
34
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
36
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
37
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
40
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
41
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
42
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
43
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
44
|
import eu.etaxonomy.cdm.ref.EntityReference;
|
45
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
46
|
|
47
|
/**
|
48
|
* @author a.kohlbecker
|
49
|
* @since Mar 10, 2017
|
50
|
*
|
51
|
*/
|
52
|
public class TypeDesignationSetManagerIT extends CdmVaadinIntegrationTest {
|
53
|
|
54
|
|
55
|
private NameTypeDesignation ntd;
|
56
|
private SpecimenTypeDesignation std_IT;
|
57
|
private SpecimenTypeDesignation std_HT;
|
58
|
private SpecimenTypeDesignation std_IT_2;
|
59
|
private SpecimenTypeDesignation std_IT_3;
|
60
|
|
61
|
@Before
|
62
|
public void init(){
|
63
|
|
64
|
ntd = NameTypeDesignation.NewInstance();
|
65
|
ntd.setId(1);
|
66
|
TaxonName typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
67
|
typeName.setTitleCache("Prionus L.", true);
|
68
|
ntd.setTypeName(typeName);
|
69
|
Reference citation = ReferenceFactory.newGeneric();
|
70
|
citation.setTitleCache("Species Plantarum", true);
|
71
|
ntd.setCitation(citation);
|
72
|
|
73
|
FieldUnit fu_1 = FieldUnit.NewInstance();
|
74
|
fu_1.setId(1);
|
75
|
fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
|
76
|
|
77
|
FieldUnit fu_2 = FieldUnit.NewInstance();
|
78
|
fu_2.setId(2);
|
79
|
fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
|
80
|
|
81
|
std_HT = SpecimenTypeDesignation.NewInstance();
|
82
|
std_HT.setId(1);
|
83
|
DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
84
|
specimen_HT.setTitleCache("OHA", true);
|
85
|
DerivationEvent derivationEvent_1 = DerivationEvent.NewInstance();
|
86
|
derivationEvent_1.addOriginal(fu_1);
|
87
|
derivationEvent_1.addDerivative(specimen_HT);
|
88
|
specimen_HT.getOriginals().add(fu_1);
|
89
|
std_HT.setTypeSpecimen(specimen_HT);
|
90
|
std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
|
91
|
|
92
|
std_IT = SpecimenTypeDesignation.NewInstance();
|
93
|
std_IT.setId(2);
|
94
|
DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
95
|
specimen_IT.setTitleCache("BER", true);
|
96
|
DerivationEvent derivationEvent_2 = DerivationEvent.NewInstance();
|
97
|
derivationEvent_2.addOriginal(fu_1);
|
98
|
derivationEvent_2.addDerivative(specimen_IT);
|
99
|
std_IT.setTypeSpecimen(specimen_IT);
|
100
|
std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
101
|
|
102
|
std_IT_2 = SpecimenTypeDesignation.NewInstance();
|
103
|
std_IT_2.setId(3);
|
104
|
DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
105
|
specimen_IT_2.setTitleCache("KEW", true);
|
106
|
DerivationEvent derivationEvent_3 = DerivationEvent.NewInstance();
|
107
|
derivationEvent_3.addOriginal(fu_1);
|
108
|
derivationEvent_3.addDerivative(specimen_IT_2);
|
109
|
std_IT_2.setTypeSpecimen(specimen_IT_2);
|
110
|
std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
111
|
|
112
|
std_IT_3 = SpecimenTypeDesignation.NewInstance();
|
113
|
std_IT_3.setId(4);
|
114
|
DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
115
|
specimen_IT_3.setTitleCache("M", true);
|
116
|
std_IT_3.setTypeSpecimen(specimen_IT_3);
|
117
|
std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
|
118
|
}
|
119
|
|
120
|
@Test
|
121
|
public void test1() throws RegistrationValidationException{
|
122
|
|
123
|
List<TypeDesignationBase> tds = new ArrayList<>();
|
124
|
tds.add(ntd);
|
125
|
tds.add(std_IT);
|
126
|
tds.add(std_HT);
|
127
|
tds.add(std_IT_2);
|
128
|
tds.add(std_IT_3);
|
129
|
|
130
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
131
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
132
|
|
133
|
typifiedName.addTypeDesignation(ntd, false);
|
134
|
typifiedName.addTypeDesignation(std_HT, false);
|
135
|
typifiedName.addTypeDesignation(std_IT, false);
|
136
|
typifiedName.addTypeDesignation(std_IT_2, false);
|
137
|
typifiedName.addTypeDesignation(std_IT_3, false);
|
138
|
|
139
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(tds);
|
140
|
String result = typeDesignationManager.print();
|
141
|
|
142
|
Logger.getLogger(this.getClass()).debug(result);
|
143
|
assertNotNull(result);
|
144
|
assertEquals(
|
145
|
"Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; Isotypes: BER, KEW; Type: Isotype, M; NameType: Prionus L. Species Plantarum"
|
146
|
, result
|
147
|
);
|
148
|
|
149
|
LinkedHashMap<TypedEntityReference, TypeDesignationWorkingSet> orderedTypeDesignations =
|
150
|
typeDesignationManager.getOrderdTypeDesignationWorkingSets();
|
151
|
Map<TypeDesignationStatusBase<?>, Collection<EntityReference>> byStatusMap = orderedTypeDesignations.values().iterator().next();
|
152
|
Iterator<TypeDesignationStatusBase<?>> keyIt = byStatusMap.keySet().iterator();
|
153
|
assertEquals("Holotype", keyIt.next().getLabel());
|
154
|
assertEquals("Isotype", keyIt.next().getLabel());
|
155
|
}
|
156
|
|
157
|
@Test
|
158
|
public void test2() throws RegistrationValidationException{
|
159
|
|
160
|
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
|
161
|
typifiedName.setTitleCache("Prionus coriatius L.", true);
|
162
|
|
163
|
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
|
164
|
String result = typeDesignationManager.print();
|
165
|
Logger.getLogger(this.getClass()).debug(result);
|
166
|
assertNotNull(result);
|
167
|
assertEquals(
|
168
|
"Prionus coriatius L."
|
169
|
, result
|
170
|
);
|
171
|
|
172
|
typifiedName.addTypeDesignation(ntd, false);
|
173
|
typeDesignationManager.addTypeDesigations(null, ntd);
|
174
|
|
175
|
assertEquals(
|
176
|
"Prionus coriatius L. NameType: Prionus L. Species Plantarum"
|
177
|
, typeDesignationManager.print()
|
178
|
);
|
179
|
|
180
|
typifiedName.addTypeDesignation(std_HT, false);
|
181
|
typeDesignationManager.addTypeDesigations(null, std_HT);
|
182
|
|
183
|
assertEquals(
|
184
|
"Prionus coriatius L. Type: Testland, near Bughausen, A.Kohlbecker 81989, 2017 Holotype, OHA; NameType: Prionus L. Species Plantarum"
|
185
|
, typeDesignationManager.print()
|
186
|
);
|
187
|
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* {@inheritDoc}
|
192
|
*/
|
193
|
@Override
|
194
|
public void createTestDataSet() throws FileNotFoundException {
|
195
|
// TODO Auto-generated method stub
|
196
|
|
197
|
}
|
198
|
}
|
199
|
|