2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.validation
;
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
;
18 import java
.util
.UUID
;
20 import javax
.validation
.ConstraintViolation
;
21 import javax
.validation
.Validator
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.junit
.Before
;
25 import org
.junit
.Ignore
;
27 import org
.junit
.Test
;
29 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
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
;
38 import eu
.etaxonomy
.cdm
.test
.integration
.CdmIntegrationTest
;
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.
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);
54 private Validator validator
;
56 private BotanicalName name1
;
57 private BotanicalName name2
;
58 private BotanicalName name3
;
61 private Synonym synonym
;
67 name1
= BotanicalName
.NewInstance(Rank
.SPECIES());
68 name2
= BotanicalName
.NewInstance(Rank
.SPECIES());
69 name3
= BotanicalName
.NewInstance(Rank
.SPECIES());
71 sec1
= Generic
.NewInstance();
72 sec2
= Generic
.NewInstance();
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);
83 /****************** TESTS *****************************/
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());
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());
101 public void testTwoAcceptedTaxaWithSameNameDifferentSec() {
102 taxon2
.setName(name1
);
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());
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());