Project

General

Profile

Download (3.16 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.common.DefaultTermInitializer;
25
import eu.etaxonomy.cdm.model.name.BotanicalName;
26
import eu.etaxonomy.cdm.model.name.Rank;
27

    
28

    
29

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

    
43
	private BotanicalName name;
44

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

    
58

    
59
/****************** TESTS *****************************/
60

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

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

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

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