Project

General

Profile

Download (3.06 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
package eu.etaxonomy.cdm.validation;
10

    
11
import static org.junit.Assert.assertFalse;
12
import static org.junit.Assert.assertTrue;
13

    
14
import java.util.Set;
15

    
16
import javax.validation.ConstraintViolation;
17

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

    
22
import eu.etaxonomy.cdm.model.agent.Person;
23
import eu.etaxonomy.cdm.model.name.IBotanicalName;
24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
26

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

    
39
	private IBotanicalName name;
40

    
41
	@Before
42
	public void setUp() {
43
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
44
		name.setNameCache("Aus aus");
45
		name.setGenusOrUninomial("Aus");
46
		name.setSpecificEpithet("aus");
47
		name.setAuthorshipCache("L.");
48
		name.setFullTitleCache("Aus aus L.");
49
		name.setTitleCache("Aus aus L.", true);
50
	}
51

    
52
/****************** TESTS *****************************/
53

    
54
	@Test
55
	public void testValidSpecificName() {
56
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
57
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank",constraintViolations.isEmpty());
58
	}
59

    
60
	@Test
61
	public void testValidSpecificNameWithBasionymAuthorship() {
62
		name.setAuthorshipCache(null);
63
		name.setBasionymAuthorship(Person.NewInstance());
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 testInValidSpecificName() {
70
		name.setAuthorshipCache(null);
71
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
72
        assertFalse("There should be a constraint violation as this name does not have a specific epithet",constraintViolations.isEmpty());
73
	}
74

    
75
	@Test
76
	public void testValidAutonym() {
77
		name.setInfraSpecificEpithet("aus");
78
		name.setAuthorshipCache(null);
79
		name.setBasionymAuthorship(null);
80
		name.setRank(Rank.SUBSPECIES());
81
        Set<ConstraintViolation<IBotanicalName>> constraintViolations  = validator.validate(name, Level2.class);
82
        assertTrue("There should be no constraint violations as this name has the correct epithets for it rank", constraintViolations.isEmpty());
83
	}
84
}
(4-4/13)