Remove generics from Reference in cdmlib-model #5830
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / validation / CorrectEpithetsForRankTest.java
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.validation.constraint.CorrectEpithetsForRankValidator;
28
29
30
31 /**
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.
36 *
37 * @author ben.clark
38 *
39 *
40 */
41 public class CorrectEpithetsForRankTest extends ValidationTestBase {
42 @SuppressWarnings("unused")
43 private static final Logger logger = Logger.getLogger(CorrectEpithetsForRankTest.class);
44
45 private BotanicalName name;
46
47 @Before
48 public void setUp() {
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);
56 }
57
58
59 /****************** TESTS *****************************/
60
61 @Test
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());
67 }
68
69 @Test
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);
76 }
77
78 @Test
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());
84 }
85
86 @Test
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());
93 }
94
95 @Test
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());
102 }
103
104 @Test
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());
111 }
112
113 @Test
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());
121 }
122
123 @Test
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());
130 }
131 }