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 static org.junit.Assert.assertFalse;
|
13
|
import static org.junit.Assert.assertTrue;
|
14
|
|
15
|
import java.util.Set;
|
16
|
|
17
|
import javax.validation.ConstraintViolation;
|
18
|
import javax.validation.groups.Default;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
25
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
26
|
import eu.etaxonomy.cdm.model.name.Rank;
|
27
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
28
|
import eu.etaxonomy.cdm.validation.constraint.CorrectEpithetsForRankValidator;
|
29
|
|
30
|
|
31
|
|
32
|
/**
|
33
|
* NOTE: In this test, the words "valid" and "invalid", loaded though
|
34
|
* these terms are when applied to taxonomic names, only mean "passes the
|
35
|
* rules of this validator" or not and should not be confused with the strict
|
36
|
* nomenclatural and taxonomic sense of these words.
|
37
|
*
|
38
|
* @author ben.clark
|
39
|
*
|
40
|
*
|
41
|
*/
|
42
|
public class CorrectEpithetsForRankTest extends ValidationTestBase {
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(CorrectEpithetsForRankTest.class);
|
45
|
|
46
|
private BotanicalName name;
|
47
|
|
48
|
@Before
|
49
|
public void setUp() {
|
50
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
51
|
vocabularyStore.initialize();
|
52
|
name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
53
|
name.setNameCache("Aus aus");
|
54
|
name.setAuthorshipCache("L.");
|
55
|
name.setFullTitleCache("Aus aus L.");
|
56
|
name.setTitleCache("Aus aus L.", true);
|
57
|
}
|
58
|
|
59
|
|
60
|
/****************** TESTS *****************************/
|
61
|
|
62
|
@Test
|
63
|
public void testValidSpecificName() {
|
64
|
name.setGenusOrUninomial("Aus");
|
65
|
name.setSpecificEpithet("aus");
|
66
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class, Default.class);
|
67
|
assertTrue("There should be no constraint violations as this name has the correct epithets for its rank",constraintViolations.isEmpty());
|
68
|
}
|
69
|
|
70
|
@Test
|
71
|
public void testInValidSpecificName() {
|
72
|
name.setGenusOrUninomial("Aus");
|
73
|
name.setSpecificEpithet(null); // at the default level, this property can be null
|
74
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
75
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
76
|
assertHasConstraintOnValidator((Set)constraintViolations, CorrectEpithetsForRankValidator.class);
|
77
|
}
|
78
|
|
79
|
@Test
|
80
|
public void testValidFamilyGroupName() {
|
81
|
name.setGenusOrUninomial("Aus");
|
82
|
name.setRank(Rank.FAMILY());
|
83
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
84
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
85
|
}
|
86
|
|
87
|
@Test
|
88
|
public void testInValidFamilyGroupName() {
|
89
|
name.setGenusOrUninomial("Aus");
|
90
|
name.setRank(Rank.FAMILY()); // at the default level, this property can be null
|
91
|
name.setSpecificEpithet("aus");
|
92
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
93
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
94
|
}
|
95
|
|
96
|
@Test
|
97
|
public void testValidGenusGroupName() {
|
98
|
name.setGenusOrUninomial("Aus");
|
99
|
name.setInfraGenericEpithet("bus");
|
100
|
name.setRank(Rank.SUBGENUS());
|
101
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
102
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
103
|
}
|
104
|
|
105
|
@Test
|
106
|
public void testInValidGenusGroupName() {
|
107
|
name.setGenusOrUninomial("Aus");
|
108
|
name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
|
109
|
name.setSpecificEpithet("aus");
|
110
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
111
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
112
|
}
|
113
|
|
114
|
@Test
|
115
|
public void testValidInfraSpecificName() {
|
116
|
name.setGenusOrUninomial("Aus");
|
117
|
name.setSpecificEpithet("aus");
|
118
|
name.setInfraSpecificEpithet("ceus");
|
119
|
name.setRank(Rank.SUBSPECIES());
|
120
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
121
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
122
|
}
|
123
|
|
124
|
@Test
|
125
|
public void testInValidInfraSpecificName() {
|
126
|
name.setGenusOrUninomial("Aus");
|
127
|
name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
|
128
|
name.setSpecificEpithet("aus");
|
129
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
130
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
131
|
}
|
132
|
}
|