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
|
package eu.etaxonomy.cdm.validation;
|
10
|
|
11
|
import static org.junit.Assert.assertFalse;
|
12
|
import static org.junit.Assert.assertTrue;
|
13
|
|
14
|
import java.util.Set;
|
15
|
|
16
|
import javax.validation.ConstraintViolation;
|
17
|
import javax.validation.groups.Default;
|
18
|
|
19
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.Test;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
import eu.etaxonomy.cdm.validation.constraint.CorrectRanksForCodeValidator;
|
28
|
|
29
|
/**
|
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.
|
34
|
*
|
35
|
* @author a.mueller
|
36
|
* @since 2021-10-15
|
37
|
*/
|
38
|
public class CorrectRanksForCodeTest extends ValidationTestBase {
|
39
|
|
40
|
@SuppressWarnings("unused")
|
41
|
private static final Logger logger = LogManager.getLogger(CorrectRanksForCodeTest.class);
|
42
|
|
43
|
private IBotanicalName name;
|
44
|
|
45
|
@Before
|
46
|
public void setUp() {
|
47
|
name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
48
|
name.setNameCache("Aus aus");
|
49
|
name.setAuthorshipCache("L.");
|
50
|
name.setFullTitleCache("Aus aus L.");
|
51
|
name.setTitleCache("Aus aus L.", true);
|
52
|
|
53
|
}
|
54
|
|
55
|
/****************** TESTS *****************************/
|
56
|
|
57
|
@Test
|
58
|
public void testCultivars() {
|
59
|
name.setNameType(NomenclaturalCode.ICNCP);
|
60
|
name.setRank(Rank.CULTIVAR());
|
61
|
name.setGenusOrUninomial("Aus");
|
62
|
name.setSpecificEpithet("aus");
|
63
|
Set<ConstraintViolation<IBotanicalName>> constraintViolations = validator.validate(name, Level2.class, Default.class);
|
64
|
assertTrue("There should be no constraint violations as this name has a rank according to the code", constraintViolations.isEmpty());
|
65
|
name.setNameType(NomenclaturalCode.ICNAFP);
|
66
|
constraintViolations = validator.validate(name, Level2.class, Default.class);
|
67
|
assertFalse("There should be a constraint violation as this name of rank cultivar has code ICNafp", constraintViolations.isEmpty());
|
68
|
assertHasConstraintOnValidator((Set)constraintViolations, CorrectRanksForCodeValidator.class);
|
69
|
|
70
|
name.setNameType(NomenclaturalCode.ICNCP);
|
71
|
name.setRank(Rank.SPECIES());
|
72
|
assertFalse("There should be a constraint violation as this name of rank cultivar has code ICNafp", constraintViolations.isEmpty());
|
73
|
assertHasConstraintOnValidator((Set)constraintViolations, CorrectRanksForCodeValidator.class);
|
74
|
}
|
75
|
|
76
|
@Test
|
77
|
public void testZoological() {
|
78
|
name.setNameType(NomenclaturalCode.ICZN);
|
79
|
name.setRank(Rank.SECTION_ZOOLOGY());
|
80
|
name.setGenusOrUninomial("Aus");
|
81
|
Set<ConstraintViolation<IBotanicalName>> constraintViolations = validator.validate(name, Level2.class, Default.class);
|
82
|
assertTrue("There should be no constraint violations as this name has a rank according to the code", constraintViolations.isEmpty());
|
83
|
name.setNameType(NomenclaturalCode.ICNAFP);
|
84
|
constraintViolations = validator.validate(name, Level2.class, Default.class);
|
85
|
assertFalse("There should be a constraint violation as this name has a zoological rank but code ICNafp", constraintViolations.isEmpty());
|
86
|
assertHasConstraintOnValidator((Set)constraintViolations, CorrectRanksForCodeValidator.class);
|
87
|
}
|
88
|
|
89
|
@Test
|
90
|
public void testBotanical() {
|
91
|
name.setNameType(NomenclaturalCode.ICNAFP);
|
92
|
name.setRank(Rank.SECTION_BOTANY());
|
93
|
name.setGenusOrUninomial("Aus");
|
94
|
name.setInfraGenericEpithet("bus");
|
95
|
Set<ConstraintViolation<IBotanicalName>> constraintViolations = validator.validate(name, Level2.class, Default.class);
|
96
|
assertTrue("There should be no constraint violations as this name has a rank according to the code", constraintViolations.isEmpty());
|
97
|
name.setNameType(NomenclaturalCode.ICZN);
|
98
|
constraintViolations = validator.validate(name, Level2.class, Default.class);
|
99
|
assertFalse("There should be a constraint violation as this name has a botanical rank but code ICZN", constraintViolations.isEmpty());
|
100
|
assertHasConstraintOnValidator((Set)constraintViolations, CorrectRanksForCodeValidator.class);
|
101
|
}
|
102
|
}
|