Project

General

Profile

Download (4.26 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.assertEquals;
13
import static org.junit.Assert.assertFalse;
14
import static org.junit.Assert.assertNotNull;
15
import static org.junit.Assert.assertTrue;
16

    
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import javax.validation.ConstraintViolation;
21
import javax.validation.Validator;
22

    
23
import org.apache.log4j.Logger;
24
import org.junit.Before;
25
import org.junit.Ignore;
26

    
27
import org.junit.Test;
28

    
29
import org.unitils.spring.annotation.SpringBeanByType;
30

    
31
import eu.etaxonomy.cdm.model.name.BotanicalName;
32
import eu.etaxonomy.cdm.model.name.Rank;
33
import eu.etaxonomy.cdm.model.reference.Generic;
34
import eu.etaxonomy.cdm.model.taxon.Synonym;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
37

    
38
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
39

    
40
/**
41
 * NOTE: In this test, the words "valid" and "invalid", loaded though 
42
 * these terms are when applied to taxonomic names, only mean "passes the
43
 * rules of this validator" or not and should not be confused with the strict
44
 * nomenclatural and taxonomic sense of these words.
45
 * 
46
 * @author ben.clark
47
 *
48
 */
49
@Ignore //FIXME ignoring only for merging 8.6.2010 a.kohlbecker
50
public class TaxonNameCannotBeAcceptedAndSynonymTest extends CdmIntegrationTest {
51
	private static final Logger logger = Logger.getLogger(TaxonNameCannotBeAcceptedAndSynonymTest.class);
52
	
53
	@SpringBeanByType
54
	private Validator validator;
55
	
56
	private BotanicalName name1;
57
	private BotanicalName name2;
58
	private BotanicalName name3;
59
    private Taxon taxon1;
60
    private Taxon taxon2;
61
    private Synonym synonym;
62
    private Generic sec1;
63
    private Generic sec2;
64
	
65
	@Before
66
	public void setUp() {
67
		name1 = BotanicalName.NewInstance(Rank.SPECIES());
68
		name2 = BotanicalName.NewInstance(Rank.SPECIES());
69
		name3 = BotanicalName.NewInstance(Rank.SPECIES());
70
		
71
		sec1 = Generic.NewInstance();
72
		sec2 = Generic.NewInstance();
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/6)