1
|
/**
|
2
|
* Copyright (C) 2007 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.name;
|
11
|
|
12
|
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.After;
|
17
|
import org.junit.AfterClass;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.BeforeClass;
|
21
|
import org.junit.Test;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
24
|
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @created 18.06.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class HomotypicalGroupTest {
|
32
|
private static final Logger logger = Logger.getLogger(HomotypicalGroupTest.class);
|
33
|
|
34
|
private static HomotypicalGroup group1;
|
35
|
private static HomotypicalGroup group2;
|
36
|
private static TaxonNameBase name1;
|
37
|
private static TaxonNameBase name2;
|
38
|
private static TaxonNameBase name3;
|
39
|
private static TaxonNameBase name4;
|
40
|
|
41
|
|
42
|
/**
|
43
|
* @throws java.lang.Exception
|
44
|
*/
|
45
|
@BeforeClass
|
46
|
public static void setUpBeforeClass() throws Exception {
|
47
|
new DefaultTermInitializer().initialize();
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* @throws java.lang.Exception
|
52
|
*/
|
53
|
@AfterClass
|
54
|
public static void tearDownAfterClass() throws Exception {
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* @throws java.lang.Exception
|
59
|
*/
|
60
|
@Before
|
61
|
public void setUp() throws Exception {
|
62
|
name1 = TaxonNameBase.NewBotanicalInstance(Rank.SPECIES());
|
63
|
name2 = TaxonNameBase.NewBotanicalInstance(Rank.GENUS());
|
64
|
name3 = TaxonNameBase.NewBotanicalInstance(Rank.SUBSPECIES());
|
65
|
name4 = TaxonNameBase.NewBotanicalInstance(Rank.VARIETY());
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* @throws java.lang.Exception
|
70
|
*/
|
71
|
@After
|
72
|
public void tearDown() throws Exception {
|
73
|
}
|
74
|
|
75
|
//*********************** TESTS ***********************************************/
|
76
|
|
77
|
@Test
|
78
|
public void testGetBasionyms() {
|
79
|
name1.addBasionym(name2);
|
80
|
Set<TaxonNameBase> basionyms = name1.getHomotypicalGroup().getBasionyms();
|
81
|
Assert.assertNotNull("Basionym set should not be null", basionyms);
|
82
|
Assert.assertEquals("Number of basionyms should be 1", 1, basionyms.size());
|
83
|
name3.addBasionym(name2);
|
84
|
basionyms = name2.getHomotypicalGroup().getBasionyms();
|
85
|
Assert.assertEquals("Number of basionyms should be 1", 1, basionyms.size());
|
86
|
Assert.assertEquals("", name2, basionyms.iterator().next());
|
87
|
name3.addBasionym(name4);
|
88
|
basionyms = name2.getHomotypicalGroup().getBasionyms();
|
89
|
Assert.assertEquals("Number of basionyms should be 2", 2, basionyms.size());
|
90
|
// Assert.assertEquals("", name2, basionyms.iterator().next());
|
91
|
|
92
|
}
|
93
|
|
94
|
@Test
|
95
|
public void testGetReplacedSynonym() {
|
96
|
name3.addReplacedSynonym(name4, null, null, null);
|
97
|
Set<TaxonNameBase> replacedSyn = name3.getHomotypicalGroup().getReplacedSynonym();
|
98
|
Assert.assertNotNull("Replaced synonym set should not be null", replacedSyn);
|
99
|
Assert.assertEquals("Number of replaced synonym should be 1", 1, replacedSyn.size());
|
100
|
}
|
101
|
|
102
|
@Test
|
103
|
public void testGetBasionymAndReplacedSynonymRelations(){
|
104
|
name1.addBasionym(name2);
|
105
|
name3.addBasionym(name2);
|
106
|
name4.addReplacedSynonym(name2, null, null, null);
|
107
|
Set<NameRelationship> rels = name2.getHomotypicalGroup().getBasionymAndReplacedSynonymRelations();
|
108
|
Assert.assertEquals("Number of relations should be 3", 3, rels.size());
|
109
|
|
110
|
}
|
111
|
|
112
|
@Test
|
113
|
public void testGetUnrelatedNames(){
|
114
|
name1.addBasionym(name2);
|
115
|
name4.addReplacedSynonym(name2, null, null, null);
|
116
|
Set<TaxonNameBase> unrelatedNames = name2.getHomotypicalGroup().getUnrelatedNames();
|
117
|
Assert.assertEquals("Number of unrelatedNames should be 0", 0, unrelatedNames.size());
|
118
|
name1.getHomotypicalGroup().merge(name3.getHomotypicalGroup());
|
119
|
unrelatedNames = name2.getHomotypicalGroup().getUnrelatedNames();
|
120
|
Assert.assertEquals("Number of unrelatedNames should be 1", 1, unrelatedNames.size());
|
121
|
}
|
122
|
|
123
|
@Test
|
124
|
public void testSetGroupBasionym(){
|
125
|
|
126
|
name1.mergeHomotypicGroups(name2);
|
127
|
name1.mergeHomotypicGroups(name3);
|
128
|
name2.mergeHomotypicGroups(name4);
|
129
|
|
130
|
name3.getHomotypicalGroup().setGroupBasionym(name1);
|
131
|
|
132
|
Assert.assertEquals(1, name2.getBasionyms().size());
|
133
|
Assert.assertEquals(1, name3.getBasionyms().size());
|
134
|
Assert.assertEquals(1, name4.getBasionyms().size());
|
135
|
Assert.assertEquals(name1, name4.getBasionym());
|
136
|
}
|
137
|
|
138
|
@Test
|
139
|
public void testRemoveGroupBasionym(){
|
140
|
|
141
|
name1.mergeHomotypicGroups(name2);
|
142
|
name1.mergeHomotypicGroups(name3);
|
143
|
name2.mergeHomotypicGroups(name4);
|
144
|
|
145
|
HomotypicalGroup hg = name3.getHomotypicalGroup();
|
146
|
hg.setGroupBasionym(name1);
|
147
|
|
148
|
Assert.assertEquals(1, name2.getBasionyms().size());
|
149
|
Assert.assertEquals(1, name3.getBasionyms().size());
|
150
|
Assert.assertEquals(1, name4.getBasionyms().size());
|
151
|
Assert.assertEquals(name1, name4.getBasionym());
|
152
|
Assert.assertEquals(1, hg.getBasionyms().size());
|
153
|
|
154
|
hg.removeGroupBasionym(name1);
|
155
|
Assert.assertEquals(0, hg.getBasionyms().size());
|
156
|
|
157
|
Assert.assertEquals(0, name2.getBasionyms().size());
|
158
|
Assert.assertEquals(0, name3.getBasionyms().size());
|
159
|
Assert.assertEquals(0, name4.getBasionyms().size());
|
160
|
Assert.assertEquals(null, name4.getBasionym());
|
161
|
|
162
|
}
|
163
|
/*
|
164
|
@Test
|
165
|
public void testClone(){
|
166
|
group1 = HomotypicalGroup.NewInstance();
|
167
|
|
168
|
group1.addTypifiedName(name1);
|
169
|
group1.addTypifiedName(name2);
|
170
|
group1.setGroupBasionym(name1);
|
171
|
HomotypicalGroup clone =(HomotypicalGroup)group1.clone();
|
172
|
|
173
|
Assert.assertEquals(clone.getTypifiedNames().size(), group1.getTypifiedNames().size());
|
174
|
TaxonNameBase cloneBasionym = clone.getBasionyms().iterator().next();
|
175
|
TaxonNameBase group1Basionym = group1.getBasionyms().iterator().next();
|
176
|
Assert.assertNotSame(cloneBasionym, group1Basionym);
|
177
|
}
|
178
|
*/
|
179
|
|
180
|
|
181
|
|
182
|
}
|