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.
9 package eu
.etaxonomy
.cdm
.validation
;
11 import static org
.junit
.Assert
.assertFalse
;
12 import static org
.junit
.Assert
.assertTrue
;
16 import javax
.validation
.ConstraintViolation
;
17 import javax
.validation
.groups
.Default
;
19 import org
.apache
.logging
.log4j
.LogManager
;
20 import org
.apache
.logging
.log4j
.Logger
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
24 import eu
.etaxonomy
.cdm
.model
.name
.IBotanicalName
;
25 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
27 import eu
.etaxonomy
.cdm
.validation
.constraint
.CorrectEpithetsForRankValidator
;
30 * NOTE: In this test, the words "valid" and "invalid", loaded though
31 * these terms are when applied to taxonomic names, only mean "passes the
32 * rules of this validator" or not and should not be confused with the strict
33 * nomenclatural and taxonomic sense of these words.
37 public class CorrectEpithetsForRankTest
extends ValidationTestBase
{
39 @SuppressWarnings("unused")
40 private static final Logger logger
= LogManager
.getLogger();
42 private IBotanicalName name
;
46 name
= TaxonNameFactory
.NewBotanicalInstance(Rank
.SPECIES());
47 name
.setNameCache("Aus aus");
48 name
.setAuthorshipCache("L.");
49 name
.setFullTitleCache("Aus aus L.");
50 name
.setTitleCache("Aus aus L.", true);
53 /****************** TESTS *****************************/
56 public void testValidSpecificName() {
57 name
.setGenusOrUninomial("Aus");
58 name
.setSpecificEpithet("aus");
59 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class, Default
.class);
60 assertTrue("There should be no constraint violations as this name has the correct epithets for its rank", constraintViolations
.isEmpty());
64 public void testInValidSpecificName() {
65 name
.setGenusOrUninomial("Aus");
66 name
.setSpecificEpithet(null); // at the default level, this property can be null
67 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
68 assertFalse("There should be a constraint violation as this name does not have a specific epithet", constraintViolations
.isEmpty());
69 assertHasConstraintOnValidator((Set
)constraintViolations
, CorrectEpithetsForRankValidator
.class);
73 public void testValidFamilyGroupName() {
74 name
.setGenusOrUninomial("Aus");
75 name
.setRank(Rank
.FAMILY());
76 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
77 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank", constraintViolations
.isEmpty());
81 public void testInValidFamilyGroupName() {
82 name
.setGenusOrUninomial("Aus");
83 name
.setRank(Rank
.FAMILY()); // at the default level, this property can be null
84 name
.setSpecificEpithet("aus");
85 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
86 assertFalse("There should be a constraint violation as this name does not have a specific epithet", constraintViolations
.isEmpty());
90 public void testValidGenusGroupName() {
91 name
.setGenusOrUninomial("Aus");
92 name
.setInfraGenericEpithet("bus");
93 name
.setRank(Rank
.SUBGENUS());
94 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
95 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations
.isEmpty());
99 public void testInValidGenusGroupName() {
100 name
.setGenusOrUninomial("Aus");
101 name
.setRank(Rank
.SUBGENUS()); // at the default level, this property can be null
102 name
.setSpecificEpithet("aus");
103 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
104 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());
108 public void testValidInfraSpecificName() {
109 name
.setGenusOrUninomial("Aus");
110 name
.setSpecificEpithet("aus");
111 name
.setInfraSpecificEpithet("ceus");
112 name
.setRank(Rank
.SUBSPECIES());
113 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
114 assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations
.isEmpty());
118 public void testInValidInfraSpecificName() {
119 name
.setGenusOrUninomial("Aus");
120 name
.setRank(Rank
.SUBGENUS()); // at the default level, this property can be null
121 name
.setSpecificEpithet("aus");
122 Set
<ConstraintViolation
<IBotanicalName
>> constraintViolations
= validator
.validate(name
, Level2
.class);
123 assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations
.isEmpty());