Project

General

Profile

Download (5.53 KB) Statistics
| Branch: | Tag: | Revision:
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 org.apache.log4j.Logger;
27

    
28
import org.junit.Before;
29

    
30

    
31
import org.junit.Test;
32

    
33

    
34

    
35
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
36
import eu.etaxonomy.cdm.model.name.BotanicalName;
37
import eu.etaxonomy.cdm.model.name.Rank;
38

    
39

    
40

    
41
/**
42
 * NOTE: In this test, the words "valid" and "invalid", loaded though 
43
 * these terms are when applied to taxonomic names, only mean "passes the
44
 * rules of this validator" or not and should not be confused with the strict
45
 * nomenclatural and taxonomic sense of these words.
46
 * 
47
 * @author ben.clark
48
 *
49
 */
50
//@Ignore //FIXME ignoring only for merging 8.6.2010 a.kohlbecker
51
public class CorrectEpithetsForRankTest  {
52
	private static final Logger logger = Logger.getLogger(CorrectEpithetsForRankTest.class);
53
	
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.setAuthorshipCache("L.");
68
		name.setFullTitleCache("Aus aus L.");
69
		name.setTitleCache("Aus aus L.", true);
70
	}
71
	
72
	
73
/****************** TESTS *****************************/
74
	
75
	@Test
76
	public void testValidSpecificName() {
77
		name.setGenusOrUninomial("Aus");
78
		name.setSpecificEpithet("aus");
79
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class, Default.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 testInValidSpecificName() {
85
		name.setGenusOrUninomial("Aus");
86
		name.setSpecificEpithet(null); // at the default level, this property can be null
87
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
88
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
89
	}
90
	
91
	@Test
92
	public void testValidFamilyGroupName() {
93
		name.setGenusOrUninomial("Aus");
94
		name.setRank(Rank.FAMILY());
95
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
96
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
97
	}
98
	
99
	@Test
100
	public void testInValidFamilyGroupName() {
101
		name.setGenusOrUninomial("Aus");
102
		name.setRank(Rank.FAMILY()); // at the default level, this property can be null
103
		name.setSpecificEpithet("aus");
104
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
105
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
106
	}
107
	
108
	@Test
109
	public void testValidGenusGroupName() {
110
		name.setGenusOrUninomial("Aus");
111
		name.setInfraGenericEpithet("bus");
112
		name.setRank(Rank.SUBGENUS());
113
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
114
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
115
	}
116
	
117
	@Test
118
	public void testInValidGenusGroupName() {
119
		name.setGenusOrUninomial("Aus");
120
		name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
121
		name.setSpecificEpithet("aus");
122
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
123
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
124
	}
125
	
126
	@Test
127
	public void testValidInfraSpecificName() {
128
		name.setGenusOrUninomial("Aus");
129
		name.setSpecificEpithet("aus");
130
		name.setInfraSpecificEpithet("ceus");
131
		name.setRank(Rank.SUBSPECIES());
132
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
133
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
134
	}
135
	
136
	@Test
137
	public void testInValidInfraSpecificName() {
138
		name.setGenusOrUninomial("Aus");
139
		name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
140
		name.setSpecificEpithet("aus");
141
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
142
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
143
	}
144
}
(1-1/5)