Project

General

Profile

Download (5.56 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
import org.junit.Ignore;
30

    
31

    
32
import org.junit.Test;
33

    
34

    
35

    
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 CorrectEpithetsForRankTest  {
53
	private static final Logger logger = Logger.getLogger(CorrectEpithetsForRankTest.class);
54
	
55
	
56
	private Validator validator;
57
	
58
	private BotanicalName name;
59
	
60
	@Before
61
	public void setUp() {
62
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
63
		vocabularyStore.initialize();
64
		ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
65
		validator = validatorFactory.getValidator();
66
		name = BotanicalName.NewInstance(Rank.SPECIES());
67
		name.setNameCache("Aus aus");
68
		name.setAuthorshipCache("L.");
69
		name.setFullTitleCache("Aus aus L.");
70
		name.setTitleCache("Aus aus L.", true);
71
	}
72
	
73
	
74
/****************** TESTS *****************************/
75
	
76
	@Test
77
	public void testValidSpecificName() {
78
		name.setGenusOrUninomial("Aus");
79
		name.setSpecificEpithet("aus");
80
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class, Default.class);
81
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
82
	}
83
	
84
	@Test
85
	public void testInValidSpecificName() {
86
		name.setGenusOrUninomial("Aus");
87
		name.setSpecificEpithet(null); // at the default level, this property can be null
88
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
89
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
90
	}
91
	
92
	@Test
93
	public void testValidFamilyGroupName() {
94
		name.setGenusOrUninomial("Aus");
95
		name.setRank(Rank.FAMILY());
96
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
97
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
98
	}
99
	
100
	@Test
101
	public void testInValidFamilyGroupName() {
102
		name.setGenusOrUninomial("Aus");
103
		name.setRank(Rank.FAMILY()); // at the default level, this property can be null
104
		name.setSpecificEpithet("aus");
105
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
106
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
107
	}
108
	
109
	@Test
110
	public void testValidGenusGroupName() {
111
		name.setGenusOrUninomial("Aus");
112
		name.setInfraGenericEpithet("bus");
113
		name.setRank(Rank.SUBGENUS());
114
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
115
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
116
	}
117
	
118
	@Test
119
	public void testInValidGenusGroupName() {
120
		name.setGenusOrUninomial("Aus");
121
		name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
122
		name.setSpecificEpithet("aus");
123
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
124
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
125
	}
126
	
127
	@Test
128
	public void testValidInfraSpecificName() {
129
		name.setGenusOrUninomial("Aus");
130
		name.setSpecificEpithet("aus");
131
		name.setInfraSpecificEpithet("ceus");
132
		name.setRank(Rank.SUBSPECIES());
133
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
134
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
135
	}
136
	
137
	@Test
138
	public void testInValidInfraSpecificName() {
139
		name.setGenusOrUninomial("Aus");
140
		name.setRank(Rank.SUBGENUS()); // at the default level, this property can be null
141
		name.setSpecificEpithet("aus");
142
        Set<ConstraintViolation<BotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
143
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
144
	}
145
}
(1-1/5)