Project

General

Profile

Download (6.63 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.model.common;
11

    
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;
16

    
17
import org.junit.After;
18
import org.junit.AfterClass;
19
import org.junit.Before;
20
import org.junit.BeforeClass;
21
import org.junit.Test;
22

    
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
25
import eu.etaxonomy.cdm.model.name.Rank;
26
import eu.etaxonomy.cdm.model.name.TaxonName;
27
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31

    
32
/**
33
 * @author a.babadshanjan
34
 * @since 02.02.2009
35
 */
36
public class IdentifiableEntityTest {
37

    
38
	private TaxonName abies;
39
	private TaxonName abiesMill;
40
	private TaxonName abiesAlba;
41
	private TaxonName abiesAlbaMichx;
42
	private TaxonName abiesAlbaMill;
43
	private TaxonName abiesAlbaxPinusBeta;
44
	private TaxonName pinusBeta;
45

    
46
	private Taxon abiesTaxon;
47
	private Taxon abiesMillTaxon;
48

    
49
	private TaxonName abiesAutonym;
50
	private Taxon abiesAutonymTaxon;
51

    
52
	private TaxonName abiesBalsamea;
53
	private Taxon abiesBalsameaTaxon;
54
//	private Taxon abiesAlbaxPinusBetaTaxon;
55
	/**
56
	 * @throws java.lang.Exception
57
	 */
58

    
59
	@BeforeClass
60
	public static void setUpBeforeClass() {
61
		DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
62
		vocabularyStore.initialize();
63

    
64
	}
65
	/**
66
	 * @throws java.lang.Exception
67
	 */
68
	@AfterClass
69
	public static void tearDownAfterClass() throws Exception {
70
	}
71

    
72
	/**
73
	 * @throws java.lang.Exception
74
	 */
75
	@Before
76
	public void setUp() throws Exception {
77

    
78
		abies = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
79
		abies.setNameCache("Abies");
80
		abies.setTitleCache("Abies", true);
81
		Reference sec = ReferenceFactory.newArticle();
82
		sec.setTitle("Abies alba Ref");
83

    
84
		abiesTaxon = Taxon.NewInstance(abies, sec);
85

    
86
		abiesMill = TaxonNameFactory.NewNonViralInstance(Rank.GENUS(), null);
87
		abiesMill.setNameCache("Abies");
88
		abiesMill.setTitleCache("Abies Mill.", true);
89
		abiesMillTaxon = Taxon.NewInstance(abiesMill, sec);
90

    
91
		abiesAlba = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
92
		abiesAlba.setNameCache("Abies alba");
93
		abiesAlba.setTitleCache("Abies alba", true);
94

    
95
		abiesAlbaMichx = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
96
		abiesAlbaMichx.setNameCache("Abies alba");
97
		abiesAlbaMichx.setTitleCache("Abies alba Michx.", true);
98

    
99
		abiesAlbaMill = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES(), null);
100
		abiesAlbaMill.setNameCache("Abies alba");
101
		abiesAlbaMill.setTitleCache("Abies alba Mill.", true);
102

    
103
		abiesAutonym  = TaxonNameFactory.NewNonViralInstance(Rank.SECTION_BOTANY());
104
		abiesAutonym.setGenusOrUninomial("Abies");
105
		abiesAutonym.setInfraGenericEpithet("Abies");
106

    
107
		abiesAutonym.setTitleCache("Abies Mill. sect. Abies", true);
108
		abiesAutonym.getNameCache();
109
		abiesAutonymTaxon = Taxon.NewInstance(abiesAutonym, sec);
110

    
111
		abiesBalsamea  = TaxonNameFactory.NewNonViralInstance(Rank.SECTION_BOTANY());
112
		abiesBalsamea.setGenusOrUninomial("Abies");
113
		abiesBalsamea.setInfraGenericEpithet("Balsamea");
114
		abiesBalsamea.getNameCache();
115
		abiesBalsamea.setTitleCache("Abies sect. Balsamea L.", true);
116
		abiesBalsameaTaxon = Taxon.NewInstance(abiesBalsamea, sec);
117

    
118
		abiesAlbaxPinusBeta = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
119
		pinusBeta = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
120
		pinusBeta.setGenusOrUninomial("Pinus");
121
		pinusBeta.setSpecificEpithet("beta");
122
		abiesAlbaxPinusBeta.setHybridFormula(true);
123
		abiesAlbaxPinusBeta.addHybridParent(abiesAlba, HybridRelationshipType.FIRST_PARENT(), null);
124
		abiesAlbaxPinusBeta.addHybridParent(pinusBeta, HybridRelationshipType.SECOND_PARENT(), null);
125

    
126
	}
127

    
128
	/**
129
	 * @throws java.lang.Exception
130
	 */
131
	@After
132
	public void tearDown() throws Exception {
133
	}
134

    
135

    
136
	/**
137
	 * Test method for {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.IdentifiableEntity)}.
138
	 */
139
	@Test
140
	public void testAddCredit() {
141
		assertNotNull("A list should always be returned",abies.getCredits());
142
		assertTrue("No credits should exist",abies.getCredits().isEmpty());
143
		String text1 = "Credit1";
144
		String text2 = "Credit2";
145
		String text3 = "Credit0"; //for sorting order
146
		Person person = Person.NewTitledInstance("Me");
147
		abies.addCredit(Credit.NewInstance(person, text1));
148
		assertEquals("Number of credits should be 1",1,abies.getCredits().size());
149
		abies.addCredit(Credit.NewInstance(person, text2));
150
		assertEquals("Number of credits should be 2",2,abies.getCredits().size());
151
		abies.addCredit(Credit.NewInstance(person, text3));
152
		assertEquals("Number of credits should be 3",3,abies.getCredits().size());
153
		assertEquals("Credit0 should be last in list", text3, abies.getCredits(2).getText());
154
	}
155

    
156
	/**
157
	 * Test method for {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.IdentifiableEntity)}.
158
	 */
159
	@Test
160
	public void testRemoveCredit() {
161
		assertNotNull("A list should always be returned",abies.getCredits());
162
		String text1 = "Credit1";
163
		String text2 = "Credit2";
164
		Person person = Person.NewTitledInstance("Me");
165
		Credit credit1 = Credit.NewInstance(person, text1);
166
		Credit credit2 = Credit.NewInstance(person, text2);
167
		abies.addCredit(credit1);
168
		abies.addCredit(credit2);
169
		assertEquals("Number of credits should be 2",2,abies.getCredits().size());
170
		abies.removeCredit(credit1);
171
		assertNotNull("A list should always be returned",abies.getCredits());
172
		assertFalse("The list should not be empty",abies.getCredits().isEmpty());
173
		assertEquals("Number of credits should be 1",1,abies.getCredits().size());
174
		assertEquals("Remaining credit should be credit2",credit2,abies.getCredits().get(0));
175
		abies.removeCredit(credit2);
176
		assertNotNull("A list should always be returned",abies.getCredits());
177
		assertTrue("No credits should exist",abies.getCredits().isEmpty());
178
	}
179

    
180
	@Test
181
	public void testClone(){
182
		IdentifiableEntity<?> clone = (IdentifiableEntity<?>)abies.clone();
183
		assertNotNull(clone);
184
		assertEquals(clone.annotations, abies.annotations);
185
		assertEquals(clone.markers, abies.markers);
186
		assertFalse(clone.uuid.equals(abies.uuid));
187
	}
188
}
(8-8/17)