Project

General

Profile

Download (4.03 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.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.common.DefaultTermInitializer;
23
import eu.etaxonomy.cdm.model.name.BotanicalName;
24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27
import eu.etaxonomy.cdm.model.taxon.Synonym;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
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 TaxonNameCannotBeAcceptedAndSynonymTest extends ValidationTestBase{
41
	@SuppressWarnings("unused")
42
	private static final Logger logger = Logger.getLogger(TaxonNameCannotBeAcceptedAndSynonymTest.class);
43

    
44
	private BotanicalName name1;
45
	private BotanicalName name2;
46
	private BotanicalName name3;
47
    private Taxon taxon1;
48
    private Taxon taxon2;
49
    private Synonym synonym;
50
    private Reference<?> sec1;
51
    private Reference<?> sec2;
52

    
53
	@Before
54
	public void setUp() {
55
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
56
		vocabularyStore.initialize();
57
		name1 = BotanicalName.NewInstance(Rank.SPECIES());
58
		name2 = BotanicalName.NewInstance(Rank.SPECIES());
59
		name3 = BotanicalName.NewInstance(Rank.SPECIES());
60

    
61
		sec1 = ReferenceFactory.newGeneric();
62
		sec2 = ReferenceFactory.newGeneric();
63

    
64
		taxon1 = Taxon.NewInstance(name1, sec1);
65
		taxon1.setTitleCache("Aus aus", true);
66
		taxon2 = Taxon.NewInstance(name2, sec1);
67
		taxon2.setTitleCache("Aus bus", true);
68
		synonym = Synonym.NewInstance(name3, sec1);
69
		synonym.setTitleCache("Aus ceus", true);
70
	}
71

    
72

    
73
/****************** TESTS *****************************/
74

    
75
	@Test
76
	public void testValidTaxon() {
77
		assert taxon1.getName().getTaxonBases().size() == 1;
78
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
79
        assertTrue("There should be no constraint violations as this taxon does not have the same name as any other taxa",constraintViolations.isEmpty());
80
	}
81

    
82
	@Test
83
	public void testTwoAcceptedTaxaWithSameNameSameSec() {
84
		taxon2.setName(name1);
85
		assert taxon1.getName().getTaxonBases().size() == 2;
86
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
87
        assertTrue("There should be a single constraint violation as this taxon shares the same name as taxon2 and is according to the same authority, sec1",!constraintViolations.isEmpty());
88
	}
89

    
90
	@Test
91
	public void testTwoAcceptedTaxaWithSameNameDifferentSec() {
92
		taxon2.setName(name1);
93
		taxon2.setSec(sec2);
94
		assert taxon1.getName().getTaxonBases().size() == 2;
95
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
96
        assertTrue("There should not be any constraint violations despite both accepted taxa sharing the same name as the sec reference is different",constraintViolations.isEmpty());
97
	}
98

    
99
	@Test
100
	public void testTaxonAndSynonymWithSameNameSameSec() {
101
		synonym.setName(name1);
102
		assert taxon1.getName().getTaxonBases().size() == 2;
103
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
104
        assertTrue("There should be a single constraint violation as this taxon shares the same name as synonym and is according to the same authority, sec1",!constraintViolations.isEmpty());
105
	}
106
}
(6-6/10)