Project

General

Profile

Download (9.02 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 java.util.Set;
13

    
14
import javax.validation.ConstraintViolation;
15

    
16
import org.apache.log4j.Logger;
17
import org.junit.Assert;
18
import org.junit.Before;
19
import org.junit.Test;
20

    
21
import eu.etaxonomy.cdm.model.agent.Person;
22
import eu.etaxonomy.cdm.model.name.IBotanicalName;
23
import eu.etaxonomy.cdm.model.name.IZoologicalName;
24
import eu.etaxonomy.cdm.model.name.NameRelationship;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.TaxonName;
27
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.model.term.DefaultTermInitializer;
31
import eu.etaxonomy.cdm.validation.constraint.BasionymsMustShareEpithetsAndAuthorsValidator;
32

    
33

    
34

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

    
49
	private IBotanicalName name;
50
	private TaxonName basionymName;
51
	private Person author1;
52
	private Person author2;
53

    
54

    
55

    
56
	@Before
57
	public void setUp() {
58
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
59
		vocabularyStore.initialize();
60
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
61
		name.setGenusOrUninomial("Aus");
62
		name.setSpecificEpithet("aus");
63
		author1 = Person.NewTitledInstance("Person");
64
		name.setBasionymAuthorship(author1);
65

    
66
		author2 = Person.NewTitledInstance("Person2");
67
		basionymName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
68
		basionymName.setGenusOrUninomial("Aus");
69
		basionymName.setSpecificEpithet("aus");
70
        basionymName.setCombinationAuthorship(author1);
71

    
72
        name.addBasionym(basionymName);
73
	}
74

    
75
/****************** TESTS *****************************/
76

    
77
	@Test
78
	public void testBasionymHasSameAuthorship() {
79
        Assert.assertEquals(1, name.getNameRelations().size());
80
        NameRelationship basRel = name.getNameRelations().iterator().next();
81
	    Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
82
        assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
83

    
84
        basionymName.setCombinationAuthorship(author2);
85
        Assert.assertEquals(1, name.getNameRelations().size());
86
        basRel = name.getNameRelations().iterator().next();
87
        constraintViolations  = validator.validate(basRel, Level3.class);
88
        assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
89
	}
90

    
91
	@Test
92
    public void testSameSpecificLastEpithet() {
93
	    Assert.assertEquals(1, name.getNameRelations().size());
94
       NameRelationship basRel = name.getNameRelations().iterator().next();
95
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
96
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
97

    
98
       basionymName.setSpecificEpithet("bus");
99
       Assert.assertEquals(1, name.getNameRelations().size());
100
       basRel = name.getNameRelations().iterator().next();
101
       constraintViolations  = validator.validate(basRel, Level3.class);
102
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
103
    }
104

    
105
    @Test
106
    public void testSameInfraSpecificEpithet() {
107
       name.setInfraSpecificEpithet("bus");
108
       basionymName.setInfraSpecificEpithet("bus");
109
       Assert.assertEquals(1, name.getNameRelations().size());
110
       NameRelationship basRel = name.getNameRelations().iterator().next();
111
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
112
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
113

    
114
       basionymName.setInfraSpecificEpithet("heptodi");
115
       Assert.assertEquals(1, name.getNameRelations().size());
116
       basRel = name.getNameRelations().iterator().next();
117
       constraintViolations  = validator.validate(basRel, Level3.class);
118
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
119
    }
120

    
121
    @Test
122
    public void testSameLastEpithetSpecificInfraSpecific() {
123
       name.setInfraSpecificEpithet("bus");
124
       basionymName.setSpecificEpithet("bus");
125
       Assert.assertEquals(1, name.getNameRelations().size());
126
       NameRelationship basRel = name.getNameRelations().iterator().next();
127
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
128
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
129

    
130
       basionymName.setSpecificEpithet("heptodi");
131
       Assert.assertEquals(1, name.getNameRelations().size());
132
       basRel = name.getNameRelations().iterator().next();
133
       constraintViolations  = validator.validate(basRel, Level3.class);
134
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
135
    }
136

    
137
    @Test
138
    public void testSameLastEpithetInfraSpecificSpecific() {
139
       name.setSpecificEpithet("bus");
140
       basionymName.setInfraSpecificEpithet("bus");
141
       Assert.assertEquals(1, name.getNameRelations().size());
142
       NameRelationship basRel = name.getNameRelations().iterator().next();
143
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
144
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
145

    
146
       basionymName.setInfraSpecificEpithet("heptodi");
147
       Assert.assertEquals(1, name.getNameRelations().size());
148
       basRel = name.getNameRelations().iterator().next();
149
       constraintViolations  = validator.validate(basRel, Level3.class);
150
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
151
    }
152

    
153
    @Test
154
    public void testZoologicalReference() {
155
       Reference nomRef = ReferenceFactory.newBook();
156
       Reference nomRef2 = ReferenceFactory.newBook();
157

    
158
       IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
159
       zooName.setGenusOrUninomial("Aus");
160
       zooName.setSpecificEpithet("aus");
161
       zooName.setBasionymAuthorship(author1);
162
       zooName.setNomenclaturalReference(nomRef);
163
       IZoologicalName originalCombination = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
164
       originalCombination.setGenusOrUninomial("Aus");
165
       originalCombination.setSpecificEpithet("aus");
166
       originalCombination.setCombinationAuthorship(author1);
167
       originalCombination.setNomenclaturalReference(nomRef);
168
       zooName.addBasionym(TaxonName.castAndDeproxy(originalCombination));
169

    
170

    
171
       Assert.assertEquals(1, zooName.getNameRelations().size());
172
       NameRelationship basRel = zooName.getNameRelations().iterator().next();
173
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
174
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
175

    
176
       originalCombination.setNomenclaturalReference(nomRef2);
177
       Assert.assertEquals(1, zooName.getNameRelations().size());
178
       basRel = zooName.getNameRelations().iterator().next();
179
       constraintViolations  = validator.validate(basRel, Level3.class);
180
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
181

    
182
       //reset
183
       originalCombination.setNomenclaturalReference(nomRef);
184
       Assert.assertEquals(1, zooName.getNameRelations().size());
185
       basRel = zooName.getNameRelations().iterator().next();
186
       constraintViolations  = validator.validate(basRel, Level3.class);
187
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
188

    
189
       zooName.setNomenclaturalMicroReference("A");
190
       originalCombination.setNomenclaturalMicroReference("B");
191
       Assert.assertEquals(1, zooName.getNameRelations().size());
192
       basRel = zooName.getNameRelations().iterator().next();
193
       constraintViolations  = validator.validate(basRel, Level3.class);
194
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
195

    
196
    }
197

    
198

    
199

    
200
}
(1-1/12)