Revision 9dc896c9
Added by Andreas Müller almost 7 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/validation/NameMustFollowCodeTest.java | ||
---|---|---|
24 | 24 |
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
25 | 25 |
import eu.etaxonomy.cdm.model.name.HybridRelationshipType; |
26 | 26 |
import eu.etaxonomy.cdm.model.name.Rank; |
27 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
|
27 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
28 | 28 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
29 | 29 |
import eu.etaxonomy.cdm.validation.constraint.NameMustFollowCodeValidator; |
30 | 30 |
|
... | ... | |
40 | 40 |
@SuppressWarnings("unused") |
41 | 41 |
private static final Logger logger = Logger.getLogger(NameMustFollowCodeTest.class); |
42 | 42 |
|
43 |
private TaxonNameBase<?,?> nonViralName;
|
|
44 |
private TaxonNameBase<?,?> viralName;
|
|
45 |
private TaxonNameBase<?,?> bacterialName;
|
|
46 |
private TaxonNameBase<?,?> zoologicalName;
|
|
47 |
private TaxonNameBase<?,?> cultivarName;
|
|
43 |
private TaxonName nonViralName; |
|
44 |
private TaxonName viralName; |
|
45 |
private TaxonName bacterialName; |
|
46 |
private TaxonName zoologicalName; |
|
47 |
private TaxonName cultivarName; |
|
48 | 48 |
|
49 | 49 |
@Before |
50 | 50 |
public void setUp() { |
... | ... | |
62 | 62 |
|
63 | 63 |
@Test |
64 | 64 |
public void testValidEmptyNames() { |
65 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations
|
|
65 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations |
|
66 | 66 |
= validator.validate(cultivarName); |
67 | 67 |
assertTrue("There should be no constraint violations as this name has data set and therefore no unvalid attributes set", constraintViolations.isEmpty()); |
68 | 68 |
|
... | ... | |
82 | 82 |
@Test |
83 | 83 |
public void testMessage() { |
84 | 84 |
nonViralName.setAcronym("acronym"); |
85 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations = validator.validate(nonViralName);
|
|
85 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations = validator.validate(nonViralName); |
|
86 | 86 |
assertFalse("There should be a constraint violation as a nonViralName must not have an acronym", constraintViolations.isEmpty()); |
87 | 87 |
String message = constraintViolations.iterator().next().getMessage(); |
88 | 88 |
String expected = "Taxon name must only have attributes set that are available according to their code. E.g. 'acronym name' should only be available for viral names."; |
... | ... | |
92 | 92 |
@Test |
93 | 93 |
public void testValidNonViralName() { |
94 | 94 |
nonViralName.setAcronym("acronym"); |
95 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations = validator.validate(nonViralName);
|
|
95 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations = validator.validate(nonViralName); |
|
96 | 96 |
assertFalse("There should be a constraint violation as a nonViralName must not have an acronym", constraintViolations.isEmpty()); |
97 | 97 |
|
98 | 98 |
nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES()); |
... | ... | |
137 | 137 |
assertTrue("There should be no constraint violation as NonViralNames may have the name cache set", constraintViolations.isEmpty()); |
138 | 138 |
|
139 | 139 |
nonViralName = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES()); |
140 |
TaxonNameBase<?,?> childName = TaxonNameFactory.NewViralInstance(Rank.SPECIES());
|
|
140 |
TaxonName childName = TaxonNameFactory.NewViralInstance(Rank.SPECIES()); |
|
141 | 141 |
nonViralName.addHybridChild(childName, HybridRelationshipType.FIRST_PARENT(), null); |
142 | 142 |
constraintViolations = validator.validate(nonViralName); |
143 | 143 |
assertTrue("There should be no constraint violation as NonViralNames may have a hybrid child", constraintViolations.isEmpty()); |
... | ... | |
148 | 148 |
@Test |
149 | 149 |
public void testValidViralName() { |
150 | 150 |
viralName.setAcronym("acronym"); |
151 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations = validator.validate(viralName);
|
|
151 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations = validator.validate(viralName); |
|
152 | 152 |
assertTrue("There should be no constraint violation as a viral name may have acronym set", constraintViolations.isEmpty()); |
153 | 153 |
|
154 | 154 |
//Invalid |
... | ... | |
168 | 168 |
assertFalse("There should be a constraint violation as a ViralName must not have the nameCache set", constraintViolations.isEmpty()); |
169 | 169 |
|
170 | 170 |
viralName = TaxonNameFactory.NewViralInstance(Rank.SPECIES()); |
171 |
TaxonNameBase<?,?> childName = TaxonNameFactory.NewViralInstance(Rank.SPECIES());
|
|
171 |
TaxonName childName = TaxonNameFactory.NewViralInstance(Rank.SPECIES()); |
|
172 | 172 |
viralName.addHybridChild(childName, HybridRelationshipType.FIRST_PARENT(), null); |
173 | 173 |
constraintViolations = validator.validate(viralName); |
174 | 174 |
assertFalse("There should be a constraint violation as a ViralName must not have hybrid child", constraintViolations.isEmpty()); |
... | ... | |
183 | 183 |
zoologicalName.setOriginalPublicationYear(1987); |
184 | 184 |
zoologicalName.setPublicationYear(2001); |
185 | 185 |
|
186 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations = validator.validate(zoologicalName);
|
|
186 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations = validator.validate(zoologicalName); |
|
187 | 187 |
assertTrue("There should be no constraint violation as a zoological name may have breed and years set", constraintViolations.isEmpty()); |
188 | 188 |
} |
189 | 189 |
|
... | ... | |
192 | 192 |
bacterialName.setSubGenusAuthorship("Subgenus author"); |
193 | 193 |
bacterialName.setNameApprobation("Name approbation"); |
194 | 194 |
|
195 |
Set<ConstraintViolation<TaxonNameBase<?,?>>> constraintViolations = validator.validate(bacterialName);
|
|
195 |
Set<ConstraintViolation<TaxonName<?,?>>> constraintViolations = validator.validate(bacterialName); |
|
196 | 196 |
assertTrue("There should be no constraint violation as a bacterial name may have subgenus authorship or name approbation set", constraintViolations.isEmpty()); |
197 | 197 |
} |
198 | 198 |
|
Also available in: Unified diff
fix #6368 rename table and class TaxonNameBase