2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.validation
;
12 import static org
.junit
.Assert
.assertFalse
;
13 import static org
.junit
.Assert
.assertTrue
;
17 import javax
.validation
.ConstraintViolation
;
18 import javax
.validation
.groups
.Default
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
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
.validation
.constraint
.CorrectEpithetsForRankValidator
;
32 * NOTE: In this test, the words "valid" and "invalid", loaded though
33 * these terms are when applied to taxonomic names, only mean "passes the
34 * rules of this validator" or not and should not be confused with the strict
35 * nomenclatural and taxonomic sense of these words.
41 public class CorrectEpithetsForRankTest
extends ValidationTestBase
{
42 @SuppressWarnings("unused")
43 private static final Logger logger
= Logger
.getLogger(CorrectEpithetsForRankTest
.class);
45 private BotanicalName name
;
49 DefaultTermInitializer vocabularyStore
= new DefaultTermInitializer();
50 vocabularyStore
.initialize();
51 name
= BotanicalName
.NewInstance(Rank
.SPECIES());
52 name
.setNameCache("Aus aus");
53 name
.setAuthorshipCache("L.");
54 name
.setFullTitleCache("Aus aus L.");
55 name
.setTitleCache("Aus aus L.", true);
59 /****************** TESTS *****************************/
62 public void testValidSpecificName() {
63 name
.setGenusOrUninomial("Aus");
64 name
.setSpecificEpithet("aus");
65 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class, Default
.class);
66 assertTrue("There should be no constraint violations as this name has the correct epithets for its rank",constraintViolations
.isEmpty());
70 public void testInValidSpecificName() {
71 name
.setGenusOrUninomial("Aus");
72 name
.setSpecificEpithet(null); // at the default level, this property can be null
73 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
74 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());
75 assertHasConstraintOnValidator((Set
)constraintViolations
, CorrectEpithetsForRankValidator
.class);
79 public void testValidFamilyGroupName() {
80 name
.setGenusOrUninomial("Aus");
81 name
.setRank(Rank
.FAMILY());
82 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
83 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations
.isEmpty());
87 public void testInValidFamilyGroupName() {
88 name
.setGenusOrUninomial("Aus");
89 name
.setRank(Rank
.FAMILY()); // at the default level, this property can be null
90 name
.setSpecificEpithet("aus");
91 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
92 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());
96 public void testValidGenusGroupName() {
97 name
.setGenusOrUninomial("Aus");
98 name
.setInfraGenericEpithet("bus");
99 name
.setRank(Rank
.SUBGENUS());
100 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
101 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations
.isEmpty());
105 public void testInValidGenusGroupName() {
106 name
.setGenusOrUninomial("Aus");
107 name
.setRank(Rank
.SUBGENUS()); // at the default level, this property can be null
108 name
.setSpecificEpithet("aus");
109 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
110 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());
114 public void testValidInfraSpecificName() {
115 name
.setGenusOrUninomial("Aus");
116 name
.setSpecificEpithet("aus");
117 name
.setInfraSpecificEpithet("ceus");
118 name
.setRank(Rank
.SUBSPECIES());
119 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
120 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations
.isEmpty());
124 public void testInValidInfraSpecificName() {
125 name
.setGenusOrUninomial("Aus");
126 name
.setRank(Rank
.SUBGENUS()); // at the default level, this property can be null
127 name
.setSpecificEpithet("aus");
128 Set
<ConstraintViolation
<BotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
129 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());