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.model.common;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertFalse;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import static org.junit.Assert.assertTrue;
|
15
|
|
16
|
import org.junit.Before;
|
17
|
import org.junit.Test;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
21
|
import eu.etaxonomy.cdm.model.name.Rank;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
23
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.test.unit.EntityTestBase;
|
28
|
|
29
|
/**
|
30
|
* @author a.babadshanjan
|
31
|
* @since 02.02.2009
|
32
|
*/
|
33
|
public class IdentifiableEntityTest extends EntityTestBase {
|
34
|
|
35
|
private TaxonName abies;
|
36
|
private TaxonName abiesMill;
|
37
|
private TaxonName abiesAlba;
|
38
|
private TaxonName abiesAlbaMichx;
|
39
|
private TaxonName abiesAlbaMill;
|
40
|
private TaxonName abiesAlbaxPinusBeta;
|
41
|
private TaxonName pinusBeta;
|
42
|
|
43
|
private Taxon abiesTaxon;
|
44
|
private Taxon abiesMillTaxon;
|
45
|
|
46
|
private TaxonName abiesAutonym;
|
47
|
private Taxon abiesAutonymTaxon;
|
48
|
|
49
|
private TaxonName abiesBalsamea;
|
50
|
private Taxon abiesBalsameaTaxon;
|
51
|
// private Taxon abiesAlbaxPinusBetaTaxon;
|
52
|
|
53
|
@Before
|
54
|
public void setUp() throws Exception {
|
55
|
|
56
|
abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
57
|
abies.setNameCache("Abies");
|
58
|
abies.setTitleCache("Abies", true);
|
59
|
Reference sec = ReferenceFactory.newArticle();
|
60
|
sec.setTitle("Abies alba Ref");
|
61
|
|
62
|
abiesTaxon = Taxon.NewInstance(abies, sec);
|
63
|
|
64
|
abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
|
65
|
abiesMill.setNameCache("Abies");
|
66
|
abiesMill.setTitleCache("Abies Mill.", true);
|
67
|
abiesMillTaxon = Taxon.NewInstance(abiesMill, sec);
|
68
|
|
69
|
abiesAlba = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
|
70
|
abiesAlba.setNameCache("Abies alba");
|
71
|
abiesAlba.setTitleCache("Abies alba", true);
|
72
|
|
73
|
abiesAlbaMichx = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
|
74
|
abiesAlbaMichx.setNameCache("Abies alba");
|
75
|
abiesAlbaMichx.setTitleCache("Abies alba Michx.", true);
|
76
|
|
77
|
abiesAlbaMill = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
|
78
|
abiesAlbaMill.setNameCache("Abies alba");
|
79
|
abiesAlbaMill.setTitleCache("Abies alba Mill.", true);
|
80
|
|
81
|
abiesAutonym = TaxonNameFactory.NewNonViralInstance(Rank.SECTION_BOTANY());
|
82
|
abiesAutonym.setGenusOrUninomial("Abies");
|
83
|
abiesAutonym.setInfraGenericEpithet("Abies");
|
84
|
|
85
|
abiesAutonym.setTitleCache("Abies Mill. sect. Abies", true);
|
86
|
abiesAutonym.getNameCache();
|
87
|
abiesAutonymTaxon = Taxon.NewInstance(abiesAutonym, sec);
|
88
|
|
89
|
abiesBalsamea = TaxonNameFactory.NewNonViralInstance(Rank.SECTION_BOTANY());
|
90
|
abiesBalsamea.setGenusOrUninomial("Abies");
|
91
|
abiesBalsamea.setInfraGenericEpithet("Balsamea");
|
92
|
abiesBalsamea.getNameCache();
|
93
|
abiesBalsamea.setTitleCache("Abies sect. Balsamea L.", true);
|
94
|
abiesBalsameaTaxon = Taxon.NewInstance(abiesBalsamea, sec);
|
95
|
|
96
|
abiesAlbaxPinusBeta = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
|
97
|
pinusBeta = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
|
98
|
pinusBeta.setGenusOrUninomial("Pinus");
|
99
|
pinusBeta.setSpecificEpithet("beta");
|
100
|
abiesAlbaxPinusBeta.setHybridFormula(true);
|
101
|
abiesAlbaxPinusBeta.addHybridParent(abiesAlba, HybridRelationshipType.FIRST_PARENT(), null);
|
102
|
abiesAlbaxPinusBeta.addHybridParent(pinusBeta, HybridRelationshipType.SECOND_PARENT(), null);
|
103
|
}
|
104
|
|
105
|
@Test
|
106
|
public void testAddCredit() {
|
107
|
assertNotNull("A list should always be returned",abies.getCredits());
|
108
|
assertTrue("No credits should exist",abies.getCredits().isEmpty());
|
109
|
String text1 = "Credit1";
|
110
|
String text2 = "Credit2";
|
111
|
String text3 = "Credit0"; //for sorting order
|
112
|
Person person = Person.NewTitledInstance("Me");
|
113
|
abies.addCredit(Credit.NewInstance(person, text1));
|
114
|
assertEquals("Number of credits should be 1",1,abies.getCredits().size());
|
115
|
abies.addCredit(Credit.NewInstance(person, text2));
|
116
|
assertEquals("Number of credits should be 2",2,abies.getCredits().size());
|
117
|
abies.addCredit(Credit.NewInstance(person, text3));
|
118
|
assertEquals("Number of credits should be 3",3,abies.getCredits().size());
|
119
|
assertEquals("Credit0 should be last in list", text3, abies.getCredits(2).getText());
|
120
|
}
|
121
|
|
122
|
@Test
|
123
|
public void testRemoveCredit() {
|
124
|
assertNotNull("A list should always be returned",abies.getCredits());
|
125
|
String text1 = "Credit1";
|
126
|
String text2 = "Credit2";
|
127
|
Person person = Person.NewTitledInstance("Me");
|
128
|
Credit credit1 = Credit.NewInstance(person, text1);
|
129
|
Credit credit2 = Credit.NewInstance(person, text2);
|
130
|
abies.addCredit(credit1);
|
131
|
abies.addCredit(credit2);
|
132
|
assertEquals("Number of credits should be 2",2,abies.getCredits().size());
|
133
|
abies.removeCredit(credit1);
|
134
|
assertNotNull("A list should always be returned",abies.getCredits());
|
135
|
assertFalse("The list should not be empty",abies.getCredits().isEmpty());
|
136
|
assertEquals("Number of credits should be 1",1,abies.getCredits().size());
|
137
|
assertEquals("Remaining credit should be credit2",credit2,abies.getCredits().get(0));
|
138
|
abies.removeCredit(credit2);
|
139
|
assertNotNull("A list should always be returned",abies.getCredits());
|
140
|
assertTrue("No credits should exist",abies.getCredits().isEmpty());
|
141
|
}
|
142
|
|
143
|
@Test
|
144
|
public void testClone(){
|
145
|
IdentifiableEntity<?> clone = abies.clone();
|
146
|
assertNotNull(clone);
|
147
|
assertEquals(clone.annotations, abies.annotations);
|
148
|
assertEquals(clone.markers, abies.markers);
|
149
|
assertFalse(clone.uuid.equals(abies.uuid));
|
150
|
}
|
151
|
}
|