Project

General

Profile

Download (3.22 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.assertFalse;
13
import static org.junit.Assert.assertTrue;
14

    
15
import java.util.Set;
16

    
17
import javax.validation.ConstraintViolation;
18

    
19
import org.apache.log4j.Logger;
20
import org.junit.Before;
21
import org.junit.Test;
22

    
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.name.IBotanicalName;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
27
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer;
28

    
29

    
30

    
31
/**
32
 * NOTE: In this test, the words "valid" and "invalid", loaded though
33
 * these terms are when applied to taxonomic names, only mean "passes the
34
 * rules of this validator" or not and should not be confused with the strict
35
 * nomenclatural and taxonomic sense of these words.
36
 *
37
 * @author ben.clark
38
 *
39
 */
40
public class MustHaveAuthorityTest extends ValidationTestBase {
41
	@SuppressWarnings("unused")
42
    private static final Logger logger = Logger.getLogger(MustHaveAuthorityTest.class);
43

    
44
	private IBotanicalName name;
45

    
46
	@Before
47
	public void setUp() {
48
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
49
		vocabularyStore.initialize();
50
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
51
		name.setNameCache("Aus aus");
52
		name.setGenusOrUninomial("Aus");
53
		name.setSpecificEpithet("aus");
54
		name.setAuthorshipCache("L.");
55
		name.setFullTitleCache("Aus aus L.");
56
		name.setTitleCache("Aus aus L.", true);
57
	}
58

    
59

    
60
/****************** TESTS *****************************/
61

    
62
	@Test
63
	public void testValidSpecificName() {
64
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
65
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
66
	}
67

    
68
	@Test
69
	public void testValidSpecificNameWithBasionymAuthorship() {
70
		name.setAuthorshipCache(null);
71
		name.setBasionymAuthorship(Person.NewInstance());
72
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
73
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
74
	}
75

    
76
	@Test
77
	public void testInValidSpecificName() {
78
		name.setAuthorshipCache(null);
79
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
80
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
81
	}
82

    
83
	@Test
84
	public void testValidAutonym() {
85
		name.setInfraSpecificEpithet("aus");
86
		name.setAuthorshipCache(null);
87
		name.setBasionymAuthorship(null);
88
		name.setRank(Rank.SUBSPECIES());
89
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
90
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank", constraintViolations.isEmpty());
91
	}
92
}
(3-3/12)