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.assertEquals;
|
13
|
import static org.junit.Assert.assertFalse;
|
14
|
import static org.junit.Assert.assertNotNull;
|
15
|
import static org.junit.Assert.assertTrue;
|
16
|
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import javax.validation.ConstraintViolation;
|
21
|
import javax.validation.Validation;
|
22
|
import javax.validation.Validator;
|
23
|
import javax.validation.ValidatorFactory;
|
24
|
import javax.validation.groups.Default;
|
25
|
|
26
|
import junit.framework.Assert;
|
27
|
|
28
|
import org.apache.log4j.Logger;
|
29
|
import org.junit.Before;
|
30
|
import org.junit.Ignore;
|
31
|
import org.junit.Test;
|
32
|
|
33
|
import org.unitils.spring.annotation.SpringBeanByType;
|
34
|
|
35
|
import eu.etaxonomy.cdm.model.agent.Person;
|
36
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
37
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
38
|
import eu.etaxonomy.cdm.model.name.Rank;
|
39
|
|
40
|
|
41
|
|
42
|
/**
|
43
|
* NOTE: In this test, the words "valid" and "invalid", loaded though
|
44
|
* these terms are when applied to taxonomic names, only mean "passes the
|
45
|
* rules of this validator" or not and should not be confused with the strict
|
46
|
* nomenclatural and taxonomic sense of these words.
|
47
|
*
|
48
|
* @author ben.clark
|
49
|
*
|
50
|
*/
|
51
|
//@Ignore //FIXME ignoring only for merging 8.6.2010 a.kohlbecker
|
52
|
public class MustHaveAuthorityTest {
|
53
|
private static final Logger logger = Logger.getLogger(MustHaveAuthorityTest.class);
|
54
|
|
55
|
private Validator validator;
|
56
|
|
57
|
private BotanicalName name;
|
58
|
|
59
|
@Before
|
60
|
public void setUp() {
|
61
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
62
|
vocabularyStore.initialize();
|
63
|
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
|
64
|
validator = validatorFactory.getValidator();
|
65
|
name = BotanicalName.NewInstance(Rank.SPECIES());
|
66
|
name.setNameCache("Aus aus");
|
67
|
name.setGenusOrUninomial("Aus");
|
68
|
name.setSpecificEpithet("aus");
|
69
|
name.setAuthorshipCache("L.");
|
70
|
name.setFullTitleCache("Aus aus L.");
|
71
|
name.setTitleCache("Aus aus L.", true);
|
72
|
}
|
73
|
|
74
|
|
75
|
/****************** TESTS *****************************/
|
76
|
|
77
|
@Test
|
78
|
public void testValidSpecificName() {
|
79
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
80
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
81
|
}
|
82
|
|
83
|
@Test
|
84
|
public void testValidSpecificNameWithBasionymAuthorTeam() {
|
85
|
name.setAuthorshipCache(null);
|
86
|
name.setBasionymAuthorTeam(Person.NewInstance());
|
87
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
88
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
89
|
}
|
90
|
|
91
|
@Test
|
92
|
public void testInValidSpecificName() {
|
93
|
name.setAuthorshipCache(null);
|
94
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
95
|
assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
|
96
|
}
|
97
|
|
98
|
@Test
|
99
|
public void testValidAutonym() {
|
100
|
name.setInfraSpecificEpithet("aus");
|
101
|
name.setAuthorshipCache(null);
|
102
|
name.setBasionymAuthorTeam(null);
|
103
|
name.setRank(Rank.SUBSPECIES());
|
104
|
Set<ConstraintViolation<BotanicalName>> constraintViolations = validator.validate(name, Level2.class);
|
105
|
assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
|
106
|
}
|
107
|
}
|