Project

General

Profile

Download (8.86 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.common.DefaultTermInitializer;
23
import eu.etaxonomy.cdm.model.name.BotanicalName;
24
import eu.etaxonomy.cdm.model.name.NameRelationship;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.ZoologicalName;
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

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

    
47
	private BotanicalName name;
48
	private BotanicalName basionymName;
49
	private Person author1;
50
	private Person author2;
51

    
52

    
53

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

    
64
		author2 = Person.NewTitledInstance("Person2");
65
		basionymName = BotanicalName.NewInstance(Rank.SPECIES());
66
		basionymName.setGenusOrUninomial("Aus");
67
		basionymName.setSpecificEpithet("aus");
68
        basionymName.setCombinationAuthorship(author1);
69

    
70

    
71
        name.addBasionym(basionymName);
72

    
73
	}
74

    
75

    
76
/****************** TESTS *****************************/
77

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

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

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

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

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

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

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

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

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

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

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

    
159
       ZoologicalName zooName = ZoologicalName.NewInstance(Rank.SPECIES());
160
       zooName.setGenusOrUninomial("Aus");
161
       zooName.setSpecificEpithet("aus");
162
       zooName.setBasionymAuthorship(author1);
163
       zooName.setNomenclaturalReference(nomRef);
164
       ZoologicalName originalCombination = ZoologicalName.NewInstance(Rank.SPECIES());
165
       originalCombination.setGenusOrUninomial("Aus");
166
       originalCombination.setSpecificEpithet("aus");
167
       originalCombination.setCombinationAuthorship(author1);
168
       originalCombination.setNomenclaturalReference(nomRef);
169
       zooName.addBasionym(originalCombination);
170

    
171

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

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

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

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

    
197
    }
198

    
199

    
200

    
201
}
(1-1/10)