Project

General

Profile

Download (4.4 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
import javax.validation.Validation;
18
import javax.validation.Validator;
19
import javax.validation.ValidatorFactory;
20

    
21
import org.apache.log4j.Logger;
22
import org.junit.Before;
23
import org.junit.Ignore;
24
import org.junit.Test;
25
import org.unitils.spring.annotation.SpringBeanByType;
26

    
27
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
28
import eu.etaxonomy.cdm.model.name.BotanicalName;
29
import eu.etaxonomy.cdm.model.name.Rank;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
32
import eu.etaxonomy.cdm.model.taxon.Synonym;
33
import eu.etaxonomy.cdm.model.taxon.Taxon;
34

    
35

    
36
/**
37
 * NOTE: In this test, the words "valid" and "invalid", loaded though 
38
 * these terms are when applied to taxonomic names, only mean "passes the
39
 * rules of this validator" or not and should not be confused with the strict
40
 * nomenclatural and taxonomic sense of these words.
41
 * 
42
 * @author ben.clark
43
 *
44
 */
45
//@Ignore //FIXME ignoring only for merging 8.6.2010 a.kohlbecker
46
public class TaxonNameCannotBeAcceptedAndSynonymTest{
47
	private static final Logger logger = Logger.getLogger(TaxonNameCannotBeAcceptedAndSynonymTest.class);
48
	
49
	
50
	private Validator validator;
51
	
52
	private BotanicalName name1;
53
	private BotanicalName name2;
54
	private BotanicalName name3;
55
    private Taxon taxon1;
56
    private Taxon taxon2;
57
    private Synonym synonym;
58
    private Reference sec1;
59
    private Reference sec2;
60
	
61
	@Before
62
	public void setUp() {
63
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
64
		vocabularyStore.initialize();
65
		ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
66
		validator = validatorFactory.getValidator();
67
		name1 = BotanicalName.NewInstance(Rank.SPECIES());
68
		name2 = BotanicalName.NewInstance(Rank.SPECIES());
69
		name3 = BotanicalName.NewInstance(Rank.SPECIES());
70
		
71
		sec1 = ReferenceFactory.newGeneric();
72
		sec2 = ReferenceFactory.newGeneric();
73
		
74
		taxon1 = Taxon.NewInstance(name1, sec1);
75
		taxon1.setTitleCache("Aus aus", true);
76
		taxon2 = Taxon.NewInstance(name2, sec1);
77
		taxon2.setTitleCache("Aus bus", true);
78
		synonym = Synonym.NewInstance(name3, sec1);
79
		synonym.setTitleCache("Aus ceus", true);
80
	}
81
	
82
	
83
/****************** TESTS *****************************/
84
	
85
	@Test
86
	public void testValidTaxon() {
87
		assert taxon1.getName().getTaxonBases().size() == 1;
88
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
89
        assertTrue("There should be no constraint violations as this taxon does not have the same name as any other taxa",constraintViolations.isEmpty());
90
	}
91
	
92
	@Test
93
	public void testTwoAcceptedTaxaWithSameNameSameSec() {
94
		taxon2.setName(name1);
95
		assert taxon1.getName().getTaxonBases().size() == 2;
96
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
97
        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());
98
	}
99
	
100
	@Test
101
	public void testTwoAcceptedTaxaWithSameNameDifferentSec() {
102
		taxon2.setName(name1);
103
		taxon2.setSec(sec2);
104
		assert taxon1.getName().getTaxonBases().size() == 2;
105
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
106
        assertTrue("There should not be any constraint violations despite both accepted taxa sharing the same name as the sec reference is different",constraintViolations.isEmpty());
107
	}
108
	
109
	@Test
110
	public void testTaxonAndSynonymWithSameNameSameSec() {
111
		synonym.setName(name1);
112
		assert taxon1.getName().getTaxonBases().size() == 2;
113
        Set<ConstraintViolation<Taxon>> constraintViolations  = validator.validate(taxon1, Level3.class);
114
        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());
115
	}
116
}
(5-5/5)