Project

General

Profile

Download (4.11 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.name.TaxonNameFactory;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
import eu.etaxonomy.cdm.model.taxon.Synonym;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30

    
31

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

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

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

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

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

    
73

    
74
/****************** TESTS *****************************/
75

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

    
83
	@Test
84
	public void testTwoAcceptedTaxaWithSameNameSameSec() {
85
		taxon2.setName(name1);
86
		assert taxon1.getName().getTaxonBases().size() == 2;
87
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
88
        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());
89
	}
90

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

    
100
	@Test
101
	public void testTaxonAndSynonymWithSameNameSameSec() {
102
		synonym.setName(name1);
103
		assert taxon1.getName().getTaxonBases().size() == 2;
104
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
105
        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());
106
	}
107
}
(6-6/10)