Project

General

Profile

Download (8.91 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
package eu.etaxonomy.cdm.validation;
10

    
11
import java.util.Set;
12

    
13
import javax.validation.ConstraintViolation;
14

    
15
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
16
import org.junit.Assert;
17
import org.junit.Before;
18
import org.junit.Test;
19

    
20
import eu.etaxonomy.cdm.model.agent.Person;
21
import eu.etaxonomy.cdm.model.name.IBotanicalName;
22
import eu.etaxonomy.cdm.model.name.IZoologicalName;
23
import eu.etaxonomy.cdm.model.name.NameRelationship;
24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.validation.constraint.BasionymsMustShareEpithetsAndAuthorsValidator;
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
public class BasionymsMustShareEpithetsAndAuthorsTest extends ValidationTestBase {
40

    
41
    @SuppressWarnings("unused")
42
    private static final Logger logger = LogManager.getLogger(BasionymsMustShareEpithetsAndAuthorsTest.class);
43

    
44
	private IBotanicalName name;
45
	private TaxonName basionymName;
46
	private Person author1;
47
	private Person author2;
48

    
49
	@Before
50
	public void setUp() {
51

    
52
		name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
53
		name.setGenusOrUninomial("Aus");
54
		name.setSpecificEpithet("aus");
55
		author1 = Person.NewTitledInstance("Person");
56
		name.setBasionymAuthorship(author1);
57

    
58
		author2 = Person.NewTitledInstance("Person2");
59
		basionymName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
60
		basionymName.setGenusOrUninomial("Aus");
61
		basionymName.setSpecificEpithet("aus");
62
        basionymName.setCombinationAuthorship(author1);
63

    
64
        name.addBasionym(basionymName);
65
	}
66

    
67
/****************** TESTS *****************************/
68

    
69
	@Test
70
	public void testBasionymHasSameAuthorship() {
71
        Assert.assertEquals(1, name.getNameRelations().size());
72
        NameRelationship basRel = name.getNameRelations().iterator().next();
73
	    Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
74
        assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
75

    
76
        basionymName.setCombinationAuthorship(author2);
77
        Assert.assertEquals(1, name.getNameRelations().size());
78
        basRel = name.getNameRelations().iterator().next();
79
        constraintViolations  = validator.validate(basRel, Level3.class);
80
        assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
81
	}
82

    
83
	@Test
84
    public void testSameSpecificLastEpithet() {
85
	    Assert.assertEquals(1, name.getNameRelations().size());
86
       NameRelationship basRel = name.getNameRelations().iterator().next();
87
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
88
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
89

    
90
       basionymName.setSpecificEpithet("bus");
91
       Assert.assertEquals(1, name.getNameRelations().size());
92
       basRel = name.getNameRelations().iterator().next();
93
       constraintViolations  = validator.validate(basRel, Level3.class);
94
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
95
    }
96

    
97
    @Test
98
    public void testSameInfraSpecificEpithet() {
99
       name.setInfraSpecificEpithet("bus");
100
       basionymName.setInfraSpecificEpithet("bus");
101
       Assert.assertEquals(1, name.getNameRelations().size());
102
       NameRelationship basRel = name.getNameRelations().iterator().next();
103
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
104
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
105

    
106
       basionymName.setInfraSpecificEpithet("heptodi");
107
       Assert.assertEquals(1, name.getNameRelations().size());
108
       basRel = name.getNameRelations().iterator().next();
109
       constraintViolations  = validator.validate(basRel, Level3.class);
110
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
111
    }
112

    
113
    @Test
114
    public void testSameLastEpithetSpecificInfraSpecific() {
115
       name.setInfraSpecificEpithet("bus");
116
       basionymName.setSpecificEpithet("bus");
117
       Assert.assertEquals(1, name.getNameRelations().size());
118
       NameRelationship basRel = name.getNameRelations().iterator().next();
119
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
120
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
121

    
122
       basionymName.setSpecificEpithet("heptodi");
123
       Assert.assertEquals(1, name.getNameRelations().size());
124
       basRel = name.getNameRelations().iterator().next();
125
       constraintViolations  = validator.validate(basRel, Level3.class);
126
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
127
    }
128

    
129
    @Test
130
    public void testSameLastEpithetInfraSpecificSpecific() {
131
       name.setSpecificEpithet("bus");
132
       basionymName.setInfraSpecificEpithet("bus");
133
       Assert.assertEquals(1, name.getNameRelations().size());
134
       NameRelationship basRel = name.getNameRelations().iterator().next();
135
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
136
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
137

    
138
       basionymName.setInfraSpecificEpithet("heptodi");
139
       Assert.assertEquals(1, name.getNameRelations().size());
140
       basRel = name.getNameRelations().iterator().next();
141
       constraintViolations  = validator.validate(basRel, Level3.class);
142
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
143
    }
144

    
145
    @Test
146
    public void testZoologicalReference() {
147
       Reference nomRef = ReferenceFactory.newBook();
148
       Reference nomRef2 = ReferenceFactory.newBook();
149

    
150
       IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
151
       zooName.setGenusOrUninomial("Aus");
152
       zooName.setSpecificEpithet("aus");
153
       zooName.setBasionymAuthorship(author1);
154
       zooName.setNomenclaturalReference(nomRef);
155
       IZoologicalName originalCombination = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
156
       originalCombination.setGenusOrUninomial("Aus");
157
       originalCombination.setSpecificEpithet("aus");
158
       originalCombination.setCombinationAuthorship(author1);
159
       originalCombination.setNomenclaturalReference(nomRef);
160
       zooName.addBasionym(TaxonName.castAndDeproxy(originalCombination));
161

    
162

    
163
       Assert.assertEquals(1, zooName.getNameRelations().size());
164
       NameRelationship basRel = zooName.getNameRelations().iterator().next();
165
       Set<ConstraintViolation<NameRelationship>> constraintViolations  = validator.validate(basRel, Level3.class);
166
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
167

    
168
       originalCombination.setNomenclaturalReference(nomRef2);
169
       Assert.assertEquals(1, zooName.getNameRelations().size());
170
       basRel = zooName.getNameRelations().iterator().next();
171
       constraintViolations  = validator.validate(basRel, Level3.class);
172
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
173

    
174
       //reset
175
       originalCombination.setNomenclaturalReference(nomRef);
176
       Assert.assertEquals(1, zooName.getNameRelations().size());
177
       basRel = zooName.getNameRelations().iterator().next();
178
       constraintViolations  = validator.validate(basRel, Level3.class);
179
       assertNoConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
180

    
181
       zooName.setNomenclaturalMicroReference("A");
182
       originalCombination.setNomenclaturalMicroReference("B");
183
       Assert.assertEquals(1, zooName.getNameRelations().size());
184
       basRel = zooName.getNameRelations().iterator().next();
185
       constraintViolations  = validator.validate(basRel, Level3.class);
186
       assertHasConstraintOnValidator((Set)constraintViolations, BasionymsMustShareEpithetsAndAuthorsValidator.class);
187

    
188
    }
189

    
190

    
191

    
192
}
(2-2/15)