1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.validation;
|
5
|
|
6
|
import static org.junit.Assert.assertEquals;
|
7
|
import static org.junit.Assert.assertFalse;
|
8
|
import static org.junit.Assert.assertNotNull;
|
9
|
import static org.junit.Assert.assertTrue;
|
10
|
|
11
|
import java.util.Set;
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import javax.validation.ConstraintViolation;
|
15
|
import javax.validation.Validator;
|
16
|
import javax.validation.groups.Default;
|
17
|
|
18
|
import junit.framework.Assert;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Ignore;
|
23
|
import org.junit.Test;
|
24
|
import org.unitils.dbunit.annotation.DataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
28
|
import eu.etaxonomy.cdm.model.agent.Person;
|
29
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.common.Group;
|
32
|
import eu.etaxonomy.cdm.model.common.Language;
|
33
|
import eu.etaxonomy.cdm.model.common.User;
|
34
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
35
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.Specimen;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
39
|
import eu.etaxonomy.cdm.model.reference.Article;
|
40
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
41
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
42
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
43
|
|
44
|
/**
|
45
|
* NOTE: In this test, the words "valid" and "invalid", loaded though
|
46
|
* these terms are when applied to taxonomic names, only mean "passes the
|
47
|
* rules of this validator" or not and should not be confused with the strict
|
48
|
* nomenclatural and taxonomic sense of these words.
|
49
|
*
|
50
|
* @author ben.clark
|
51
|
*
|
52
|
*/
|
53
|
public class CorrectEpithetsForRankTest extends CdmIntegrationTest {
|
54
|
private static final Logger logger = Logger.getLogger(CorrectEpithetsForRankTest.class);
|
55
|
|
56
|
@SpringBeanByType
|
57
|
private Validator validator;
|
58
|
|
59
|
private BotanicalName name;
|
60
|
|
61
|
@Before
|
62
|
public void setUp() {
|
63
|
name = BotanicalName.NewInstance(Rank.SPECIES());
|
64
|
name.setNameCache("Aus aus");
|
65
|
name.setAuthorshipCache("L.");
|
66
|
name.setFullTitleCache("Aus aus L.");
|
67
|
name.setTitleCache("Aus aus L.");
|
68
|
}
|
69
|
|
70
|
|
71
|
/****************** TESTS *****************************/
|
72
|
|
73
|
|
74
|
|
75
|
/**
|
76
|
* Test validation at the "default" level with a valid name
|
77
|
*/
|
78
|
@Test
|
79
|
public void testValidationWithValidSpecificName() {
|
80
|
name.setGenusOrUninomial("Aus");
|
81
|
name.setSpecificEpithet("aus");
|
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 testValidationWithInValidSpecificName() {
|
88
|
name.setGenusOrUninomial("Aus");
|
89
|
name.setSpecificEpithet(null); // at the default level, this property can be nulll
|
90
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
91
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
92
|
}
|
93
|
|
94
|
|
95
|
}
|