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
|
|
10
|
package eu.etaxonomy.cdm.validation;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.validation.ConstraintViolation;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.agent.Person;
|
22
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
23
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
27
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
import eu.etaxonomy.cdm.validation.constraint.BasionymsMustShareEpithetsAndAuthorsValidator;
|
31
|
|
32
|
|
33
|
|
34
|
/**
|
35
|
* NOTE: In this test, the words "valid" and "invalid", loaded though
|
36
|
* these terms are when applied to taxonomic names, only mean "passes the
|
37
|
* rules of this validator" or not and should not be confused with the strict
|
38
|
* nomenclatural and taxonomic sense of these words.
|
39
|
*
|
40
|
* @author ben.clark
|
41
|
*
|
42
|
*
|
43
|
*/
|
44
|
public class BasionymsMustShareEpithetsAndAuthorsTest extends ValidationTestBase {
|
45
|
@SuppressWarnings("unused")
|
46
|
private static final Logger logger = Logger.getLogger(BasionymsMustShareEpithetsAndAuthorsTest.class);
|
47
|
|
48
|
private BotanicalName name;
|
49
|
private BotanicalName basionymName;
|
50
|
private Person author1;
|
51
|
private Person author2;
|
52
|
|
53
|
|
54
|
|
55
|
@Before
|
56
|
public void setUp() {
|
57
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
58
|
vocabularyStore.initialize();
|
59
|
name = TaxonNameBase.NewBotanicalInstance(Rank.SPECIES());
|
60
|
name.setGenusOrUninomial("Aus");
|
61
|
name.setSpecificEpithet("aus");
|
62
|
author1 = Person.NewTitledInstance("Person");
|
63
|
name.setBasionymAuthorship(author1);
|
64
|
|
65
|
author2 = Person.NewTitledInstance("Person2");
|
66
|
basionymName = TaxonNameBase.NewBotanicalInstance(Rank.SPECIES());
|
67
|
basionymName.setGenusOrUninomial("Aus");
|
68
|
basionymName.setSpecificEpithet("aus");
|
69
|
basionymName.setCombinationAuthorship(author1);
|
70
|
|
71
|
|
72
|
name.addBasionym(basionymName);
|
73
|
|
74
|
}
|
75
|
|
76
|
|
77
|
/****************** TESTS *****************************/
|
78
|
|
79
|
@Test
|
80
|
public void testBasionymHasSameAuthorship() {
|
81
|
Assert.assertEquals(1, name.getNameRelations().size());
|
82
|
NameRelationship basRel = name.getNameRelations().iterator().next();
|
83
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
84
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
85
|
|
86
|
basionymName.setCombinationAuthorship(author2);
|
87
|
Assert.assertEquals(1, name.getNameRelations().size());
|
88
|
basRel = name.getNameRelations().iterator().next();
|
89
|
constraintViolations = validator.validate(basRel, Level3.class);
|
90
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public void testSameSpecificLastEpithet() {
|
95
|
Assert.assertEquals(1, name.getNameRelations().size());
|
96
|
NameRelationship basRel = name.getNameRelations().iterator().next();
|
97
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
98
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
99
|
|
100
|
basionymName.setSpecificEpithet("bus");
|
101
|
Assert.assertEquals(1, name.getNameRelations().size());
|
102
|
basRel = name.getNameRelations().iterator().next();
|
103
|
constraintViolations = validator.validate(basRel, Level3.class);
|
104
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
105
|
}
|
106
|
|
107
|
@Test
|
108
|
public void testSameInfraSpecificEpithet() {
|
109
|
name.setInfraSpecificEpithet("bus");
|
110
|
basionymName.setInfraSpecificEpithet("bus");
|
111
|
Assert.assertEquals(1, name.getNameRelations().size());
|
112
|
NameRelationship basRel = name.getNameRelations().iterator().next();
|
113
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
114
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
115
|
|
116
|
basionymName.setInfraSpecificEpithet("heptodi");
|
117
|
Assert.assertEquals(1, name.getNameRelations().size());
|
118
|
basRel = name.getNameRelations().iterator().next();
|
119
|
constraintViolations = validator.validate(basRel, Level3.class);
|
120
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
121
|
}
|
122
|
|
123
|
@Test
|
124
|
public void testSameLastEpithetSpecificInfraSpecific() {
|
125
|
name.setInfraSpecificEpithet("bus");
|
126
|
basionymName.setSpecificEpithet("bus");
|
127
|
Assert.assertEquals(1, name.getNameRelations().size());
|
128
|
NameRelationship basRel = name.getNameRelations().iterator().next();
|
129
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
130
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
131
|
|
132
|
basionymName.setSpecificEpithet("heptodi");
|
133
|
Assert.assertEquals(1, name.getNameRelations().size());
|
134
|
basRel = name.getNameRelations().iterator().next();
|
135
|
constraintViolations = validator.validate(basRel, Level3.class);
|
136
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
137
|
}
|
138
|
|
139
|
@Test
|
140
|
public void testSameLastEpithetInfraSpecificSpecific() {
|
141
|
name.setSpecificEpithet("bus");
|
142
|
basionymName.setInfraSpecificEpithet("bus");
|
143
|
Assert.assertEquals(1, name.getNameRelations().size());
|
144
|
NameRelationship basRel = name.getNameRelations().iterator().next();
|
145
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
146
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
147
|
|
148
|
basionymName.setInfraSpecificEpithet("heptodi");
|
149
|
Assert.assertEquals(1, name.getNameRelations().size());
|
150
|
basRel = name.getNameRelations().iterator().next();
|
151
|
constraintViolations = validator.validate(basRel, Level3.class);
|
152
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
153
|
}
|
154
|
|
155
|
@Test
|
156
|
public void testZoologicalReference() {
|
157
|
Reference nomRef = ReferenceFactory.newBook();
|
158
|
Reference nomRef2 = ReferenceFactory.newBook();
|
159
|
|
160
|
ZoologicalName zooName = TaxonNameBase.NewZoologicalInstance(Rank.SPECIES());
|
161
|
zooName.setGenusOrUninomial("Aus");
|
162
|
zooName.setSpecificEpithet("aus");
|
163
|
zooName.setBasionymAuthorship(author1);
|
164
|
zooName.setNomenclaturalReference(nomRef);
|
165
|
ZoologicalName originalCombination = TaxonNameBase.NewZoologicalInstance(Rank.SPECIES());
|
166
|
originalCombination.setGenusOrUninomial("Aus");
|
167
|
originalCombination.setSpecificEpithet("aus");
|
168
|
originalCombination.setCombinationAuthorship(author1);
|
169
|
originalCombination.setNomenclaturalReference(nomRef);
|
170
|
zooName.addBasionym(originalCombination);
|
171
|
|
172
|
|
173
|
Assert.assertEquals(1, zooName.getNameRelations().size());
|
174
|
NameRelationship basRel = zooName.getNameRelations().iterator().next();
|
175
|
Set<ConstraintViolation<NameRelationship>> constraintViolations = validator.validate(basRel, Level3.class);
|
176
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
177
|
|
178
|
originalCombination.setNomenclaturalReference(nomRef2);
|
179
|
Assert.assertEquals(1, zooName.getNameRelations().size());
|
180
|
basRel = zooName.getNameRelations().iterator().next();
|
181
|
constraintViolations = validator.validate(basRel, Level3.class);
|
182
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
183
|
|
184
|
//reset
|
185
|
originalCombination.setNomenclaturalReference(nomRef);
|
186
|
Assert.assertEquals(1, zooName.getNameRelations().size());
|
187
|
basRel = zooName.getNameRelations().iterator().next();
|
188
|
constraintViolations = validator.validate(basRel, Level3.class);
|
189
|
assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
190
|
|
191
|
zooName.setNomenclaturalMicroReference("A");
|
192
|
originalCombination.setNomenclaturalMicroReference("B");
|
193
|
Assert.assertEquals(1, zooName.getNameRelations().size());
|
194
|
basRel = zooName.getNameRelations().iterator().next();
|
195
|
constraintViolations = validator.validate(basRel, Level3.class);
|
196
|
assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
|
197
|
|
198
|
}
|
199
|
|
200
|
|
201
|
|
202
|
}
|