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 org.apache.log4j.Logger;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Test;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
17
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
18
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
19
|
import eu.etaxonomy.cdm.model.name.Rank;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
21
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
22
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
23
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
24
|
import eu.etaxonomy.cdm.validation.constraint.ValidTaxonomicYearValidator;
|
25
|
|
26
|
|
27
|
|
28
|
/**
|
29
|
* NOTE: In this test, the words "valid" and "invalid", loaded though
|
30
|
* these terms are when applied to taxonomic names, only mean "passes the
|
31
|
* rules of this validator" or not and should not be confused with the strict
|
32
|
* nomenclatural and taxonomic sense of these words.
|
33
|
*
|
34
|
* @author ben.clark
|
35
|
*
|
36
|
*
|
37
|
*/
|
38
|
public class ValidTaxonomicYearTest extends ValidationTestBase {
|
39
|
@SuppressWarnings("unused")
|
40
|
private static final Logger logger = Logger.getLogger(ValidTaxonomicYearTest.class);
|
41
|
|
42
|
static Class validatorClass = ValidTaxonomicYearValidator.class;
|
43
|
static Class group = Level3.class;
|
44
|
|
45
|
|
46
|
private BotanicalName name;
|
47
|
|
48
|
private Reference beforeLineeRef;
|
49
|
private Reference afterLineeRef;
|
50
|
|
51
|
|
52
|
@Before
|
53
|
public void setUp() {
|
54
|
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
|
55
|
vocabularyStore.initialize();
|
56
|
|
57
|
name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
58
|
name.setNameCache("Aus aus");
|
59
|
name.setAuthorshipCache("L.");
|
60
|
name.setFullTitleCache("Aus aus L.");
|
61
|
name.setTitleCache("Aus aus L.", true);
|
62
|
|
63
|
beforeLineeRef = ReferenceFactory.newBook();
|
64
|
beforeLineeRef.setDatePublished(TimePeriodParser.parseString("1752"));
|
65
|
|
66
|
afterLineeRef = ReferenceFactory.newBook();
|
67
|
afterLineeRef.setDatePublished(TimePeriodParser.parseString("1754"));
|
68
|
|
69
|
}
|
70
|
|
71
|
|
72
|
/****************** TESTS *****************************/
|
73
|
|
74
|
@Test
|
75
|
public void testNotBeforeLinee() {
|
76
|
name.setNomenclaturalReference(beforeLineeRef);
|
77
|
validateHasConstraint(name, validatorClass, group);
|
78
|
}
|
79
|
|
80
|
@Test
|
81
|
public void testAfterLinee() {
|
82
|
name.setNomenclaturalReference(afterLineeRef);
|
83
|
validateHasNoConstraint(name, validatorClass, group);
|
84
|
}
|
85
|
|
86
|
@Test
|
87
|
public void testNoNomRef() {
|
88
|
name.setNomenclaturalReference(null);
|
89
|
validateHasNoConstraint(name, validatorClass, group);
|
90
|
}
|
91
|
|
92
|
@Test
|
93
|
public void testZooName() {
|
94
|
|
95
|
IZoologicalName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
|
96
|
|
97
|
zooName.setNomenclaturalReference(null);
|
98
|
zooName.setPublicationYear(1788);
|
99
|
validateHasNoConstraint(zooName, validatorClass, group);
|
100
|
|
101
|
zooName.setPublicationYear(1730);
|
102
|
//currently we do not use the publication year for zooName.getYear, but this may change in future.
|
103
|
//we may adapt this test then
|
104
|
validateHasNoConstraint(zooName, validatorClass, group);
|
105
|
|
106
|
zooName.setNomenclaturalReference(beforeLineeRef);
|
107
|
validateHasConstraint(zooName, validatorClass, group);
|
108
|
}
|
109
|
}
|