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.api.service;
|
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.assertNull;
|
16
|
import static org.junit.Assert.assertTrue;
|
17
|
|
18
|
import java.io.FileNotFoundException;
|
19
|
import java.util.ArrayList;
|
20
|
import java.util.Collections;
|
21
|
import java.util.Iterator;
|
22
|
import java.util.List;
|
23
|
import java.util.Set;
|
24
|
import java.util.UUID;
|
25
|
|
26
|
import org.junit.Assert;
|
27
|
import org.junit.Before;
|
28
|
import org.junit.Test;
|
29
|
import org.unitils.dbunit.annotation.DataSet;
|
30
|
import org.unitils.spring.annotation.SpringBeanByType;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
|
33
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
34
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
35
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
36
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
37
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
38
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
39
|
import eu.etaxonomy.cdm.model.name.Rank;
|
40
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
42
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
45
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
46
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
47
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
48
|
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
|
49
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
50
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
51
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
52
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
53
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
54
|
|
55
|
/**
|
56
|
* @author n.hoffmann
|
57
|
* @since Dec 16, 2010
|
58
|
*/
|
59
|
//@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
|
60
|
public class TaxonNodeServiceImplTest extends CdmTransactionalIntegrationTest{
|
61
|
|
62
|
|
63
|
@SpringBeanByType
|
64
|
private ITaxonNodeService taxonNodeService;
|
65
|
|
66
|
@SpringBeanByType
|
67
|
private IClassificationService classificationService;
|
68
|
|
69
|
@SpringBeanByType
|
70
|
private IReferenceService referenceService;
|
71
|
|
72
|
@SpringBeanByType
|
73
|
private ITermService termService;
|
74
|
|
75
|
@SpringBeanByType
|
76
|
private INameService nameService;
|
77
|
|
78
|
@SpringBeanByType
|
79
|
private ITaxonService taxonService;
|
80
|
|
81
|
@SpringBeanByType
|
82
|
private IPolytomousKeyService polKeyService;
|
83
|
|
84
|
@SpringBeanByType
|
85
|
private IPolytomousKeyNodeService polKeyNodeService;
|
86
|
|
87
|
|
88
|
private static final UUID t1Uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
|
89
|
private static final UUID t2Uuid = UUID.fromString("2659a7e0-ff35-4ee4-8493-b453756ab955");
|
90
|
private static final UUID classificationUuid = UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878");
|
91
|
private static final UUID classification2Uuid = UUID.fromString("43d67247-936f-42a3-a739-bbcde372e334");
|
92
|
private static final UUID referenceUuid = UUID.fromString("de7d1205-291f-45d9-9059-ca83fc7ade14");
|
93
|
private static final UUID node1Uuid= UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
94
|
private static final UUID node2Uuid = UUID.fromString("2d41f0c2-b785-4f73-a436-cc2d5e93cc5b");
|
95
|
|
96
|
private static final UUID node4Uuid = UUID.fromString("2fbf7bf5-22dd-4c1a-84e4-c8c93d1f0342");
|
97
|
private static final UUID node5Uuid = UUID.fromString("c4d5170a-7967-4dac-ab76-ae2019eefde5");
|
98
|
private static final UUID node6Uuid = UUID.fromString("b419ba5e-9c8b-449c-ad86-7abfca9a7340");
|
99
|
private static final UUID rootNodeUuid = UUID.fromString("324a1a77-689c-44be-8e65-347d835f4111");
|
100
|
|
101
|
|
102
|
private Taxon t1;
|
103
|
private Taxon t2;
|
104
|
private Taxon t4;
|
105
|
// private Synonym s1;
|
106
|
private SynonymType synonymType;
|
107
|
private Reference reference;
|
108
|
private String referenceDetail;
|
109
|
private Classification classification;
|
110
|
private TaxonNode node1;
|
111
|
private TaxonNode node2;
|
112
|
|
113
|
private TaxonNode node4;
|
114
|
|
115
|
/**
|
116
|
* @throws java.lang.Exception
|
117
|
*/
|
118
|
@Before
|
119
|
public void setUp() throws Exception {
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
124
|
*/
|
125
|
@Test
|
126
|
@DataSet
|
127
|
public final void testMakeTaxonNodeASynonymOfAnotherTaxonNode() {
|
128
|
classification = classificationService.load(classificationUuid);
|
129
|
node1 = taxonNodeService.load(node1Uuid);
|
130
|
node2 = taxonNodeService.load(node2Uuid);
|
131
|
node4 = taxonNodeService.load(node4Uuid);
|
132
|
reference = referenceService.load(referenceUuid);
|
133
|
// synonymType = SynonymType.HOMOTYPIC_SYNONYM_OF();
|
134
|
synonymType = CdmBase.deproxy(termService.load(SynonymType.uuidHomotypicSynonymOf), SynonymType.class) ;
|
135
|
referenceDetail = "test";
|
136
|
|
137
|
//TODO
|
138
|
|
139
|
// descriptions
|
140
|
t1 = node1.getTaxon();
|
141
|
PolytomousKey polKey = PolytomousKey.NewInstance();
|
142
|
PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
|
143
|
keyNode.setKey(polKey);
|
144
|
polKeyNodeService.save(keyNode);
|
145
|
polKeyService.save(polKey);
|
146
|
|
147
|
//nameRelations
|
148
|
|
149
|
TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
150
|
t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null );
|
151
|
|
152
|
//taxonRelations
|
153
|
Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
154
|
t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
|
155
|
Synonym synonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
156
|
taxonService.save(t1);
|
157
|
taxonService.save(relatedTaxon);
|
158
|
nameService.save(relatedName);
|
159
|
|
160
|
t1.addHomotypicSynonym(synonym);
|
161
|
taxonService.saveOrUpdate(t1);
|
162
|
t1 =(Taxon) taxonService.load(t1.getUuid());
|
163
|
t1 = HibernateProxyHelper.deproxy(t1);
|
164
|
TaxonName nameT1 = t1.getName();
|
165
|
t2 = node2.getTaxon();
|
166
|
assertEquals(2, t1.getDescriptions().size());
|
167
|
Assert.assertTrue(t2.getSynonyms().isEmpty());
|
168
|
Assert.assertTrue(t2.getDescriptions().size() == 0);
|
169
|
assertEquals(2,t1.getSynonyms().size());
|
170
|
DeleteResult result;
|
171
|
|
172
|
t4 = node4.getTaxon();
|
173
|
UUID uuidT4 = t4.getUuid();
|
174
|
t4 = (Taxon) taxonService.find(uuidT4);
|
175
|
TaxonName name4 = nameService.find(t4.getName().getUuid());
|
176
|
result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node4, node2, synonymType, reference, referenceDetail);
|
177
|
if (result.isError() || result.isAbort()){
|
178
|
Assert.fail();
|
179
|
}
|
180
|
t4 = (Taxon)taxonService.find(uuidT4);
|
181
|
assertNull(t4);
|
182
|
|
183
|
//Taxon can't be deleted because of the polytomous key node
|
184
|
result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymType, reference, referenceDetail);
|
185
|
if (result.isError() || result.isAbort()){
|
186
|
Assert.fail();
|
187
|
}
|
188
|
commitAndStartNewTransaction(new String[]{/*"TaxonNode"*/});
|
189
|
t1 = (Taxon)taxonService.find(t1Uuid);
|
190
|
assertNotNull(t1);//because of the polytomous key node
|
191
|
node1 = taxonNodeService.load(node1Uuid);
|
192
|
assertNull(node1);
|
193
|
|
194
|
Set<CdmBase> updatedObjects = result.getUpdatedObjects();
|
195
|
Iterator<CdmBase> it = updatedObjects.iterator();
|
196
|
Taxon taxon;
|
197
|
while (it.hasNext()) {
|
198
|
CdmBase updatedObject = it.next();
|
199
|
if(updatedObject.isInstanceOf(Taxon.class)){
|
200
|
taxon = HibernateProxyHelper.deproxy(updatedObject, Taxon.class);
|
201
|
Set<Synonym> syns = taxon.getSynonyms();
|
202
|
assertNotNull(syns);
|
203
|
if (taxon.equals(t2)){
|
204
|
assertEquals(4,syns.size());
|
205
|
Set<TaxonName> typifiedNames =taxon.getHomotypicGroup().getTypifiedNames();
|
206
|
assertEquals(typifiedNames.size(),4);
|
207
|
assertTrue(taxon.getHomotypicGroup().equals( nameT1.getHomotypicalGroup()));
|
208
|
|
209
|
assertEquals(taxon, t2);
|
210
|
}
|
211
|
|
212
|
}
|
213
|
|
214
|
}
|
215
|
}
|
216
|
|
217
|
/**
|
218
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonNodeServiceImpl#makeTaxonNodeASynonymOfAnotherTaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.SynonymType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
219
|
*/
|
220
|
@Test
|
221
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
222
|
public final void testMakeTaxonNodeAHeterotypicSynonymOfAnotherTaxonNode() {
|
223
|
|
224
|
//create data
|
225
|
classification = classificationService.load(classificationUuid);
|
226
|
node1 = taxonNodeService.load(node1Uuid);
|
227
|
node2 = taxonNodeService.load(node2Uuid);
|
228
|
reference = referenceService.load(referenceUuid);
|
229
|
synonymType = CdmBase.deproxy(termService.load(SynonymType.uuidHeterotypicSynonymOf), SynonymType.class) ;
|
230
|
referenceDetail = "test";
|
231
|
|
232
|
// descriptions
|
233
|
t1 = node1.getTaxon();
|
234
|
PolytomousKey polKey = PolytomousKey.NewInstance();
|
235
|
PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
|
236
|
keyNode.setKey(polKey);
|
237
|
polKeyNodeService.save(keyNode);
|
238
|
polKeyService.save(polKey);
|
239
|
|
240
|
//nameRelations
|
241
|
TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
242
|
t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null );
|
243
|
TaxonName name1 = t1.getName();
|
244
|
UUID name1UUID = name1.getUuid();
|
245
|
//taxonRelations
|
246
|
Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
247
|
t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
|
248
|
Synonym t1HomotypSynonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
249
|
|
250
|
t1.addHomotypicSynonym(t1HomotypSynonym);
|
251
|
TaxonName nameT1 = t1.getName();
|
252
|
t2 = node2.getTaxon();
|
253
|
assertEquals("taxon 1 must have 2 descriptions", 2, t1.getDescriptions().size());
|
254
|
assertEquals("taxon 1 must have 2 synonyms", 2, t1.getSynonyms().size());
|
255
|
Assert.assertTrue("taxon 2 must have no synonyms", t2.getSynonyms().isEmpty());
|
256
|
Assert.assertTrue("taxon 2 must have no descriptions", t2.getDescriptions().size() == 0);
|
257
|
|
258
|
//save
|
259
|
taxonService.save(t1HomotypSynonym);
|
260
|
taxonService.save(relatedTaxon);
|
261
|
nameService.save(relatedName);
|
262
|
|
263
|
//do it
|
264
|
DeleteResult result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode
|
265
|
(node1, node2, synonymType, reference, referenceDetail);
|
266
|
|
267
|
//post conditions
|
268
|
if (!result.getUpdatedObjects().iterator().hasNext()){
|
269
|
Assert.fail("Some updates must have taken place");
|
270
|
}
|
271
|
assertEquals(3,result.getUpdatedObjects().size());
|
272
|
assertNotNull("Old taxon should not have been deleted as it is referenced by key node", taxonService.find(t1Uuid));
|
273
|
assertNull("Old taxon node should not exist anymore", taxonNodeService.find(node1Uuid));
|
274
|
|
275
|
t1HomotypSynonym = (Synonym)taxonService.find(t1HomotypSynonym.getUuid());
|
276
|
assertNotNull(t1HomotypSynonym);
|
277
|
|
278
|
keyNode.setTaxon(null);
|
279
|
polKeyNodeService.saveOrUpdate(keyNode);
|
280
|
t2 =HibernateProxyHelper.deproxy(t2);
|
281
|
HibernateProxyHelper.deproxy(t2.getHomotypicGroup());
|
282
|
t2.setName(HibernateProxyHelper.deproxy(t2.getName()));
|
283
|
|
284
|
termService.saveOrUpdate(synonymType);
|
285
|
assertFalse("taxon 2 must have a synonym now", t2.getSynonyms().isEmpty());
|
286
|
assertEquals("taxon 2 must have 3 synonyms now, the old taxon 1 and it's 2 synonyms", 3, t2.getSynonyms().size());
|
287
|
assertEquals("taxon 2 must have 2 descriptions now, taken form taxon 1", 2, t2.getDescriptions().size());
|
288
|
|
289
|
result = taxonService.deleteTaxon(t1.getUuid(), null, null);
|
290
|
if (result.isAbort() || result.isError()){
|
291
|
Assert.fail();
|
292
|
}
|
293
|
assertNull(taxonService.find(t1Uuid));
|
294
|
assertNull(taxonNodeService.find(node1Uuid));
|
295
|
name1 = nameService.find(name1UUID);
|
296
|
assertNotNull("taxon name 1 should still exist", name1);
|
297
|
assertEquals("... but being used for the new synonym only as taxon 1 is deleted", 1, name1.getTaxonBases().size());
|
298
|
t1HomotypSynonym = (Synonym)taxonService.find(t1HomotypSynonym.getUuid());
|
299
|
assertNotNull(t1HomotypSynonym);
|
300
|
|
301
|
Synonym newSynonym =(Synonym) name1.getTaxonBases().iterator().next();
|
302
|
|
303
|
Taxon newAcceptedTaxon = CdmBase.deproxy(taxonService.find(t2.getUuid()), Taxon.class);
|
304
|
assertEquals("The new synonym (old accepted taxon) and it's homotypic synonym should still be homotypic", newSynonym.getHomotypicGroup(), t1HomotypSynonym.getName().getHomotypicalGroup());
|
305
|
assertFalse("The new accepted taxon must not be homotypic to ", newAcceptedTaxon.getHomotypicGroup().equals(newSynonym.getName().getHomotypicalGroup()));
|
306
|
|
307
|
assertEquals("The new accepted taxon is taxon 2", newAcceptedTaxon, t2);
|
308
|
assertEquals("The new synonyms name must be the same as the old accepted taxon's name", newSynonym.getName(), nameT1);
|
309
|
}
|
310
|
|
311
|
|
312
|
@Test
|
313
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
314
|
public final void testIndexCreateNode() {
|
315
|
Taxon taxon = Taxon.NewInstance(null, null);
|
316
|
classification = classificationService.load(classificationUuid);
|
317
|
node2 = taxonNodeService.load(node2Uuid);
|
318
|
String oldTreeIndex = node2.treeIndex();
|
319
|
|
320
|
TaxonNode newNode = node2.addChildTaxon(taxon, null, null);
|
321
|
taxonNodeService.saveOrUpdate(newNode);
|
322
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
323
|
newNode = taxonNodeService.load(newNode.getUuid());
|
324
|
Assert.assertEquals("", oldTreeIndex + newNode.getId() + "#", newNode.treeIndex());
|
325
|
}
|
326
|
|
327
|
|
328
|
@Test
|
329
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
330
|
public final void testIndexMoveNode() {
|
331
|
//in classification
|
332
|
classification = classificationService.load(classificationUuid);
|
333
|
node1 = taxonNodeService.load(node1Uuid);
|
334
|
node2 = taxonNodeService.load(node2Uuid);
|
335
|
node2.addChildNode(node1, null, null);
|
336
|
taxonNodeService.saveOrUpdate(node1);
|
337
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
338
|
TaxonNode node6 = taxonNodeService.load(node6Uuid);
|
339
|
Assert.assertEquals("Node6 treeindex is not correct", node2.treeIndex() + "2#4#6#", node6.treeIndex());
|
340
|
|
341
|
//root of new classification
|
342
|
Classification classification2 = classificationService.load(classification2Uuid);
|
343
|
node1 = taxonNodeService.load(node1Uuid);
|
344
|
classification2.setRootNode(HibernateProxyHelper.deproxy(classification2.getRootNode(),TaxonNode.class));
|
345
|
classification2.addChildNode(node1, null, null);
|
346
|
taxonNodeService.saveOrUpdate(node1);
|
347
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
348
|
node1 = taxonNodeService.load(node1Uuid);
|
349
|
Assert.assertEquals("Node1 treeindex is not correct", "#t2#8#2#", node1.treeIndex());
|
350
|
node6 = taxonNodeService.load(node6Uuid);
|
351
|
Assert.assertEquals("Node6 treeindex is not correct", "#t2#8#2#4#6#", node6.treeIndex());
|
352
|
|
353
|
//into new classification
|
354
|
node2 = taxonNodeService.load(node2Uuid);
|
355
|
TaxonNode node5 = taxonNodeService.load(node5Uuid);
|
356
|
node2 =node5.addChildNode(node2, null, null);
|
357
|
taxonNodeService.saveOrUpdate(node2);
|
358
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
359
|
node2 = taxonNodeService.load(node2Uuid);
|
360
|
Assert.assertEquals("Node3 treeindex is not correct", "#t2#8#2#5#3#", node2.treeIndex());
|
361
|
|
362
|
}
|
363
|
|
364
|
@Test
|
365
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
|
366
|
public final void testIndexDeleteNode() {
|
367
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
368
|
node1 = taxonNodeService.load(node1Uuid);
|
369
|
TaxonNode node4 = taxonNodeService.load(node4Uuid);
|
370
|
String treeIndex = node1.treeIndex();
|
371
|
TaxonNode node6 = taxonNodeService.load(node6Uuid);
|
372
|
treeIndex= node6.treeIndex();
|
373
|
|
374
|
HibernateProxyHelper.deproxy(node1, TaxonNode.class);
|
375
|
node1.deleteChildNode(node4, false);
|
376
|
TaxonNode node5 = taxonNodeService.load(node5Uuid);
|
377
|
treeIndex = node5.treeIndex();
|
378
|
|
379
|
node6 = taxonNodeService.load(node6Uuid);
|
380
|
|
381
|
treeIndex = node6.treeIndex();
|
382
|
Taxon newTaxon= Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
383
|
UUID taxonNewUuid = taxonService.save(newTaxon).getUuid();
|
384
|
|
385
|
node5.addChildTaxon(newTaxon, null, null);
|
386
|
String node5TreeIndex =node5.treeIndex();
|
387
|
taxonNodeService.saveOrUpdate(node5);
|
388
|
|
389
|
commitAndStartNewTransaction(new String[]{"TaxonNode"});
|
390
|
node5 = taxonNodeService.load(node5Uuid);
|
391
|
List<TaxonNode> children = node5.getChildNodes();
|
392
|
TaxonNode node = children.get(0);
|
393
|
int id = node.getId();
|
394
|
Assert.assertEquals("Node6 treeindex is not correct", "#t1#1#2#6#", treeIndex);
|
395
|
Assert.assertEquals("new node treeindex is not correct", node5TreeIndex + id +"#", node.treeIndex());
|
396
|
}
|
397
|
|
398
|
|
399
|
@Test
|
400
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
401
|
public final void testDeleteNode(){
|
402
|
classification = classificationService.load(classificationUuid);
|
403
|
node1 = taxonNodeService.load(node1Uuid);
|
404
|
node2 = taxonNodeService.load(rootNodeUuid);
|
405
|
node1 = HibernateProxyHelper.deproxy(node1);
|
406
|
|
407
|
TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), null, null);
|
408
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
409
|
newNode = taxonNodeService.load(uuidNewNode);
|
410
|
UUID taxUUID = newNode.getTaxon().getUuid();
|
411
|
UUID nameUUID = newNode.getTaxon().getName().getUuid();
|
412
|
|
413
|
DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
|
414
|
if (!result.isOk()){
|
415
|
Assert.fail();
|
416
|
}
|
417
|
newNode = taxonNodeService.load(uuidNewNode);
|
418
|
node1 = taxonNodeService.load(node1Uuid);
|
419
|
assertNull(newNode);
|
420
|
assertNull(node1);
|
421
|
|
422
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
423
|
assertNull(t1);
|
424
|
Taxon newTaxon = (Taxon)taxonService.load(taxUUID);
|
425
|
assertNull(newTaxon);
|
426
|
IBotanicalName name = nameService.load(nameUUID);
|
427
|
assertNull(name);
|
428
|
|
429
|
|
430
|
}
|
431
|
|
432
|
@Test
|
433
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
|
434
|
|
435
|
public final void testDeleteNodeWithReusedTaxon(){
|
436
|
classification = classificationService.load(classificationUuid);
|
437
|
node1 = taxonNodeService.load(node1Uuid);
|
438
|
node2 = taxonNodeService.load(rootNodeUuid);
|
439
|
node1 = HibernateProxyHelper.deproxy(node1);
|
440
|
|
441
|
|
442
|
Classification classification2 = Classification.NewInstance("Classification2");
|
443
|
TaxonNode nodeClassification2 =classification2.addChildTaxon(node1.getTaxon(), null, null);
|
444
|
assertEquals(node1.getTaxon().getUuid(), t1Uuid);
|
445
|
classificationService.save(classification2);
|
446
|
List<TaxonNode> nodesOfClassification2 = taxonNodeService.listAllNodesForClassification(classification2, null, null);
|
447
|
UUID nodeUUID = nodesOfClassification2.get(0).getUuid();
|
448
|
assertEquals(nodeUUID, nodeClassification2.getUuid());
|
449
|
Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
450
|
taxonService.save(newTaxon);
|
451
|
TaxonNode newNode = node1.addChildTaxon(newTaxon,null, null);
|
452
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
453
|
newNode = taxonNodeService.load(uuidNewNode);
|
454
|
UUID taxUUID = newNode.getTaxon().getUuid();
|
455
|
UUID nameUUID = newNode.getTaxon().getName().getUuid();
|
456
|
|
457
|
DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
|
458
|
if (!result.isOk()){
|
459
|
Assert.fail();
|
460
|
}
|
461
|
//taxonService.getSession().flush();
|
462
|
newNode = taxonNodeService.load(uuidNewNode);
|
463
|
node1 = taxonNodeService.load(node1Uuid);
|
464
|
assertNull(newNode);
|
465
|
assertNull(node1);
|
466
|
assertNotNull(taxonNodeService.load(nodeUUID));
|
467
|
|
468
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
469
|
assertNotNull(t1);
|
470
|
newTaxon = (Taxon)taxonService.load(taxUUID);
|
471
|
assertNull(newTaxon);
|
472
|
IBotanicalName name = nameService.load(nameUUID);
|
473
|
assertNull(name);
|
474
|
|
475
|
|
476
|
}
|
477
|
|
478
|
|
479
|
|
480
|
@Test
|
481
|
@DataSet
|
482
|
public final void testDeleteNodes(){
|
483
|
classification = classificationService.load(classificationUuid);
|
484
|
node1 = taxonNodeService.load(node1Uuid);
|
485
|
node2 = taxonNodeService.load(rootNodeUuid);
|
486
|
node1 = HibernateProxyHelper.deproxy(node1);
|
487
|
node2 = HibernateProxyHelper.deproxy(node2);
|
488
|
TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), null, null);
|
489
|
UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
|
490
|
List<TaxonNode> treeNodes = new ArrayList<TaxonNode>();
|
491
|
treeNodes.add(node1);
|
492
|
treeNodes.add(node2);
|
493
|
|
494
|
taxonNodeService.deleteTaxonNodes(treeNodes, null);
|
495
|
|
496
|
newNode = taxonNodeService.load(uuidNewNode);
|
497
|
node1 = taxonNodeService.load(node1Uuid);
|
498
|
assertNull(newNode);
|
499
|
assertNull(node1);
|
500
|
//taxonService.getSession().flush();
|
501
|
t1 = (Taxon) taxonService.load(t1Uuid);
|
502
|
assertNull(t1);
|
503
|
t2 = (Taxon) taxonService.load(t2Uuid);
|
504
|
assertNull(t2);
|
505
|
|
506
|
|
507
|
}
|
508
|
@Test
|
509
|
@DataSet
|
510
|
public void testMoveTaxonNode(){
|
511
|
classification = classificationService.load(classificationUuid);
|
512
|
// Set<TaxonNode> nodes = classification.getAllNodes();
|
513
|
List<TaxonNode> nodes = classification.getChildNodes();
|
514
|
System.out.println(nodes.size());
|
515
|
classification.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), nodes.size(), null, null);
|
516
|
nodes = classification.getChildNodes();
|
517
|
System.out.println(nodes.size());
|
518
|
|
519
|
}
|
520
|
|
521
|
@Test
|
522
|
public void testCompareNaturalOrder() {
|
523
|
/*
|
524
|
* Classification
|
525
|
* * Abies
|
526
|
* `- Abies alba
|
527
|
* - Abies balsamea
|
528
|
* * Pinus
|
529
|
* `- Pinus pampa
|
530
|
*/
|
531
|
Classification classification = Classification.NewInstance("Classification");
|
532
|
IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
533
|
abiesName.setGenusOrUninomial("Abies");
|
534
|
Taxon abies = Taxon.NewInstance(abiesName, null);
|
535
|
IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
536
|
abiesAlbaName.setGenusOrUninomial("Abies");
|
537
|
abiesAlbaName.setSpecificEpithet("alba");
|
538
|
Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
539
|
IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
540
|
pinusName.setGenusOrUninomial("Pinus");
|
541
|
Taxon pinus = Taxon.NewInstance(pinusName, null);
|
542
|
IBotanicalName pinusPampaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
543
|
pinusPampaName.setGenusOrUninomial("Pinus");
|
544
|
pinusPampaName.setSpecificEpithet("pampa");
|
545
|
Taxon pinusPampa = Taxon.NewInstance(pinusPampaName, null);
|
546
|
|
547
|
IBotanicalName abiesBalsameaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
548
|
abiesBalsameaName.setGenusOrUninomial("Abies");
|
549
|
abiesBalsameaName.setSpecificEpithet("balsamea");
|
550
|
Taxon abiesBalsamea = Taxon.NewInstance(abiesBalsameaName, null);
|
551
|
|
552
|
List<TaxonNode> nodes = new ArrayList<TaxonNode>();
|
553
|
nodes.add(classification.addChildTaxon(abies, null, null));
|
554
|
TaxonNode abiesAlbaNode = classification.addParentChild(abies, abiesAlba, null, null);
|
555
|
TaxonNode balsameaNode = classification.addParentChild(abies, abiesBalsamea, null, null);
|
556
|
nodes.add(balsameaNode);
|
557
|
nodes.add(abiesAlbaNode);
|
558
|
nodes.add(classification.addChildTaxon(pinus, null, null));
|
559
|
nodes.add(classification.addParentChild(pinus, pinusPampa, null, null));
|
560
|
classificationService.saveClassification(classification);
|
561
|
//this.taxonNodeService.save(nodes);
|
562
|
TaxonNaturalComparator comparator = new TaxonNaturalComparator();
|
563
|
List<TaxonNode> allNodes = new ArrayList<>(classification.getAllNodes());
|
564
|
Collections.sort(allNodes, comparator);
|
565
|
|
566
|
Assert.assertEquals(allNodes.get(0).getTaxon(), abies );
|
567
|
Assert.assertEquals(allNodes.get(2).getTaxon(), abiesBalsamea );
|
568
|
Assert.assertEquals(allNodes.get(1).getTaxon(), abiesAlba );
|
569
|
|
570
|
taxonNodeService.moveTaxonNode(balsameaNode, abiesAlbaNode,1);
|
571
|
classification = classificationService.load(classification.getUuid());
|
572
|
|
573
|
allNodes = new ArrayList<>(classification.getAllNodes());
|
574
|
Collections.sort(allNodes, comparator);
|
575
|
|
576
|
Assert.assertEquals(allNodes.get(0).getTaxon(), abies );
|
577
|
Assert.assertEquals(allNodes.get(1).getTaxon(), abiesBalsamea );
|
578
|
Assert.assertEquals(allNodes.get(2).getTaxon(), abiesAlba );
|
579
|
|
580
|
}
|
581
|
|
582
|
@Test
|
583
|
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "TaxonNodeServiceImplTest.testGetUuidAndTitleCacheHierarchy.xml")
|
584
|
public void testGetUuidAndTitleCacheHierarchy(){
|
585
|
UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
|
586
|
UUID abiesUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
|
587
|
UUID abiesAlbaUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
|
588
|
UUID abiesAlbaSubBrotaUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
|
589
|
UUID abiesPalmaUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
|
590
|
UUID pinusUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
|
591
|
// /*
|
592
|
// * Checklist
|
593
|
// * - Abies
|
594
|
// * - Abies alba
|
595
|
// * - Abieas alba subs. brota
|
596
|
// * - Abies palma
|
597
|
// * -Pinus
|
598
|
// */
|
599
|
// Classification checklist = Classification.NewInstance("Checklist");
|
600
|
// checklist.setUuid(classificationUuid);
|
601
|
//
|
602
|
// BotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
603
|
// abiesName.setGenusOrUninomial("Abies");
|
604
|
// Taxon abies = Taxon.NewInstance(abiesName, null);
|
605
|
//
|
606
|
// BotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
607
|
// abiesAlbaName.setGenusOrUninomial("Abies");
|
608
|
// abiesAlbaName.setSpecificEpithet("alba");
|
609
|
// Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
610
|
//
|
611
|
// BotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
|
612
|
// abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
|
613
|
// abiesAlbaSubBrotaName.setSpecificEpithet("alba");
|
614
|
// abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
|
615
|
// Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
|
616
|
//
|
617
|
// BotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
618
|
// abiesPalmaName.setGenusOrUninomial("Abies");
|
619
|
// abiesPalmaName.setSpecificEpithet("palma");
|
620
|
// Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
|
621
|
//
|
622
|
// BotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
623
|
// pinusName.setGenusOrUninomial("Pinus");
|
624
|
// Taxon pinus = Taxon.NewInstance(pinusName, null);
|
625
|
//
|
626
|
// checklist.addParentChild(null, abies, null, null);
|
627
|
// checklist.addParentChild(abies, abiesAlba, null, null);
|
628
|
// checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
|
629
|
// checklist.addParentChild(abies, abiesPalma, null, null);
|
630
|
// checklist.addParentChild(null, pinus, null, null);
|
631
|
//
|
632
|
//
|
633
|
// setComplete();
|
634
|
// endTransaction();
|
635
|
//
|
636
|
// String fileNameAppendix = "testGetUuidAndTitleCacheHierarchy";
|
637
|
//
|
638
|
// writeDbUnitDataSetFile(new String[] {
|
639
|
// "TAXONBASE", "TAXONNAME",
|
640
|
// "TAXONRELATIONSHIP",
|
641
|
// "HOMOTYPICALGROUP",
|
642
|
// "CLASSIFICATION", "TAXONNODE",
|
643
|
// "HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
644
|
// },
|
645
|
// fileNameAppendix );
|
646
|
Classification classification = classificationService.load(classificationUuid);
|
647
|
|
648
|
List<TaxonNode> expectedChildTaxonNodes = classification.getChildNodes();
|
649
|
List<UuidAndTitleCache<TaxonNode>> childNodesUuidAndTitleCache = taxonNodeService.listChildNodesAsUuidAndTitleCache(classification.getRootNode());
|
650
|
assertNotNull("child UuidAndTitleCache list is null", childNodesUuidAndTitleCache);
|
651
|
|
652
|
compareChildren(expectedChildTaxonNodes, childNodesUuidAndTitleCache);
|
653
|
|
654
|
//test taxon parent of sub species
|
655
|
Taxon abiesAlbaSubBrota = HibernateProxyHelper.deproxy(taxonService.load(abiesAlbaSubBrotaUuid), Taxon.class);
|
656
|
TaxonNode abiesAlbaSubBrotaNode = abiesAlbaSubBrota.getTaxonNodes().iterator().next();
|
657
|
TaxonNode expectedTaxonParent = HibernateProxyHelper.deproxy(abiesAlbaSubBrotaNode.getParent(), TaxonNode.class);
|
658
|
UuidAndTitleCache<TaxonNode> taxonParent = taxonNodeService.getParentUuidAndTitleCache(abiesAlbaSubBrotaNode);
|
659
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getUuid(), taxonParent.getUuid());
|
660
|
assertEquals("Taxon Nodes do not match. ", (Integer)expectedTaxonParent.getId(), taxonParent.getId());
|
661
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent.getTaxon().getTitleCache(), taxonParent.getTitleCache());
|
662
|
assertEquals("Taxon Nodes do not match. ", expectedTaxonParent, taxonNodeService.load(taxonParent.getUuid()));
|
663
|
|
664
|
//test classification parent
|
665
|
Taxon abies = HibernateProxyHelper.deproxy(taxonService.load(abiesUuid), Taxon.class);
|
666
|
TaxonNode abiesNode = abies.getTaxonNodes().iterator().next();
|
667
|
TaxonNode expectedClassificationParent = HibernateProxyHelper.deproxy(abiesNode.getParent(), TaxonNode.class);
|
668
|
UuidAndTitleCache<TaxonNode> classificationParent= taxonNodeService.getParentUuidAndTitleCache(abiesNode);
|
669
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getUuid(), classificationParent.getUuid());
|
670
|
assertEquals("Taxon Nodes do not match. ", (Integer)expectedClassificationParent.getId(), classificationParent.getId());
|
671
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent.getClassification().getTitleCache(), classificationParent.getTitleCache());
|
672
|
assertEquals("Taxon Nodes do not match. ", expectedClassificationParent, taxonNodeService.load(classificationParent.getUuid()));
|
673
|
}
|
674
|
|
675
|
private void compareChildren(List<TaxonNode> expectedChildTaxonNodes, List<UuidAndTitleCache<TaxonNode>> childNodesUuidAndTitleCache){
|
676
|
assertEquals("Number of children does not match", expectedChildTaxonNodes.size(), childNodesUuidAndTitleCache.size());
|
677
|
UuidAndTitleCache<TaxonNode> foundMatch = null;
|
678
|
for (TaxonNode taxonNode : expectedChildTaxonNodes) {
|
679
|
foundMatch = null;
|
680
|
for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : childNodesUuidAndTitleCache) {
|
681
|
if(uuidAndTitleCache.getUuid().equals(taxonNode.getUuid())){
|
682
|
String titleCache = taxonNode.getTaxon().getTitleCache();
|
683
|
if(uuidAndTitleCache.getTitleCache().equals(titleCache)){
|
684
|
foundMatch = uuidAndTitleCache;
|
685
|
break;
|
686
|
}
|
687
|
}
|
688
|
}
|
689
|
assertTrue(String.format("no matching UuidAndTitleCache found for child %s", taxonNode), foundMatch!=null);
|
690
|
compareChildren(taxonNode.getChildNodes(), taxonNodeService.listChildNodesAsUuidAndTitleCache(foundMatch));
|
691
|
}
|
692
|
}
|
693
|
//
|
694
|
// private UuidAndTitleCache<TaxonNode> findMatchingUuidAndTitleCache(List<UuidAndTitleCache<TaxonNode>> childNodesUuidAndTitleCache,
|
695
|
// UuidAndTitleCache<TaxonNode> foundMatch, TaxonNode taxonNode) {
|
696
|
// for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : childNodesUuidAndTitleCache) {
|
697
|
// if(uuidAndTitleCache.getUuid().equals(taxonNode.getUuid())){
|
698
|
// String titleCache = taxonNode.getTaxon().getTitleCache();
|
699
|
// if(uuidAndTitleCache.getTitleCache().equals(titleCache)){
|
700
|
// foundMatch = uuidAndTitleCache;
|
701
|
// break;
|
702
|
// }
|
703
|
// }
|
704
|
// }
|
705
|
// return foundMatch;
|
706
|
// }
|
707
|
|
708
|
@Test
|
709
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
710
|
public void testSetSecundumForSubtree(){
|
711
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
712
|
// UUID taxon1uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
|
713
|
// UUID taxon5uuid = UUID.fromString("d0b99fee-a783-4dda-b8a2-8960703cfcc2");
|
714
|
Reference newSec = referenceService.find(UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7"));
|
715
|
|
716
|
//assert current state
|
717
|
Assert.assertNotNull(newSec);
|
718
|
Assert.assertNull(taxonService.find(1).getSec());
|
719
|
Assert.assertNull(taxonService.find(2).getSec());
|
720
|
Assert.assertNull(taxonService.find(3).getSec());
|
721
|
Assert.assertNull(taxonService.find(4).getSec());
|
722
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
723
|
Assert.assertNotNull(taxon5.getSec());
|
724
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
725
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
726
|
|
727
|
//set secundum
|
728
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(subTreeUuid);
|
729
|
config.setNewSecundum(newSec);
|
730
|
taxonNodeService.setSecundumForSubtree(config);
|
731
|
|
732
|
commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
733
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
734
|
Assert.assertNull(taxonService.find(2).getSec());
|
735
|
Assert.assertEquals(newSec, taxonService.find(3).getSec());
|
736
|
Assert.assertNull(taxonService.find(4).getSec());
|
737
|
taxon5 = taxonService.find(5);
|
738
|
Assert.assertEquals(newSec, taxon5.getSec());
|
739
|
Assert.assertNull(taxon5.getSecMicroReference());
|
740
|
}
|
741
|
|
742
|
@Test
|
743
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
744
|
public void testSetSecundumForSubtreeNoOverwrite(){
|
745
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
746
|
// UUID taxon1uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
|
747
|
// UUID taxon5uuid = UUID.fromString("d0b99fee-a783-4dda-b8a2-8960703cfcc2");
|
748
|
Reference newSec = referenceService.find(UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7"));
|
749
|
|
750
|
//assert current state
|
751
|
Assert.assertNotNull(newSec);
|
752
|
Assert.assertNull(taxonService.find(1).getSec());
|
753
|
Assert.assertNull(taxonService.find(2).getSec());
|
754
|
Assert.assertNull(taxonService.find(3).getSec());
|
755
|
Assert.assertNull(taxonService.find(4).getSec());
|
756
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
757
|
Assert.assertNotNull(taxon5.getSec());
|
758
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
759
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
760
|
|
761
|
//set secundum
|
762
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(subTreeUuid, newSec, null);
|
763
|
config.setOverwriteExistingAccepted(false);
|
764
|
config.setOverwriteExistingSynonyms(false);
|
765
|
taxonNodeService.setSecundumForSubtree(config);
|
766
|
|
767
|
commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
768
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
769
|
Assert.assertNull(taxonService.find(2).getSec());
|
770
|
Assert.assertEquals(newSec, taxonService.find(3).getSec());
|
771
|
Assert.assertNull(taxonService.find(4).getSec());
|
772
|
Reference oldTaxon5Sec = taxon5.getSec();
|
773
|
taxon5 = taxonService.find(5);
|
774
|
Assert.assertEquals(oldTaxon5Sec, taxon5.getSec());
|
775
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
776
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
777
|
}
|
778
|
|
779
|
@Test
|
780
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
781
|
public void testSetSecundumForSubtreeOnlyAccepted(){
|
782
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
783
|
Reference newSec = referenceService.find(UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7"));
|
784
|
|
785
|
//assert current state
|
786
|
Assert.assertNotNull(newSec);
|
787
|
Assert.assertNull(taxonService.find(1).getSec());
|
788
|
Assert.assertNull(taxonService.find(2).getSec());
|
789
|
Assert.assertNull(taxonService.find(3).getSec());
|
790
|
Assert.assertNull(taxonService.find(4).getSec());
|
791
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
792
|
Assert.assertNotNull(taxon5.getSec());
|
793
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
794
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
795
|
|
796
|
//set secundum
|
797
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(subTreeUuid, newSec, null);
|
798
|
config.setIncludeSynonyms(false);
|
799
|
taxonNodeService.setSecundumForSubtree(config);
|
800
|
|
801
|
// commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
802
|
Assert.assertEquals(newSec, taxonService.find(1).getSec());
|
803
|
Assert.assertNull(taxonService.find(2).getSec());
|
804
|
Assert.assertNull(taxonService.find(3).getSec());
|
805
|
Assert.assertNull(taxonService.find(4).getSec());
|
806
|
taxon5 = taxonService.find(5);
|
807
|
Assert.assertEquals(newSec, taxon5.getSec());
|
808
|
Assert.assertNull(taxon5.getSecMicroReference());
|
809
|
}
|
810
|
|
811
|
@Test
|
812
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
813
|
public void testSetSecundumForSubtreeOnlySynonyms(){
|
814
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
815
|
Reference newSec = referenceService.find(UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7"));
|
816
|
|
817
|
//assert current state
|
818
|
Assert.assertNotNull(newSec);
|
819
|
Assert.assertNull(taxonService.find(1).getSec());
|
820
|
Assert.assertNull(taxonService.find(2).getSec());
|
821
|
Assert.assertNull(taxonService.find(3).getSec());
|
822
|
Assert.assertNull(taxonService.find(4).getSec());
|
823
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
824
|
Assert.assertNotNull(taxon5.getSec());
|
825
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
826
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
827
|
|
828
|
//set secundum
|
829
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(subTreeUuid, newSec, null);
|
830
|
config.setIncludeAcceptedTaxa(false);
|
831
|
taxonNodeService.setSecundumForSubtree(config);
|
832
|
|
833
|
commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
834
|
Assert.assertNull(taxonService.find(1).getSec());
|
835
|
Assert.assertNull(taxonService.find(2).getSec());
|
836
|
Assert.assertEquals("Synonym should be updated", newSec, taxonService.find(3).getSec());
|
837
|
Assert.assertNull(taxonService.find(4).getSec());
|
838
|
Reference oldTaxon5Sec = taxon5.getSec();
|
839
|
taxon5 = taxonService.find(5);
|
840
|
Assert.assertEquals(oldTaxon5Sec, taxon5.getSec());
|
841
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
842
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
843
|
}
|
844
|
|
845
|
@Test
|
846
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
847
|
public void testSetSecundumForSubtreeNoShared(){
|
848
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
849
|
Reference newSec = referenceService.find(UUID.fromString("1d3fb074-d7ba-47e4-be94-b4cb1a99afa7"));
|
850
|
|
851
|
//assert current state
|
852
|
Assert.assertNotNull(newSec);
|
853
|
Assert.assertNull(taxonService.find(1).getSec());
|
854
|
Assert.assertNull(taxonService.find(2).getSec());
|
855
|
Assert.assertNull(taxonService.find(3).getSec());
|
856
|
Assert.assertNull(taxonService.find(4).getSec());
|
857
|
TaxonBase<?> taxon5 = taxonService.find(5);
|
858
|
Assert.assertNotNull(taxon5.getSec());
|
859
|
Assert.assertNotEquals(newSec, taxon5.getSec());
|
860
|
Assert.assertNotNull(taxon5.getSecMicroReference());
|
861
|
|
862
|
//set secundum
|
863
|
SecundumForSubtreeConfigurator config = new SecundumForSubtreeConfigurator(subTreeUuid, newSec, null);
|
864
|
config.setIncludeSharedTaxa(false);
|
865
|
taxonNodeService.setSecundumForSubtree(config);
|
866
|
|
867
|
commitAndStartNewTransaction(new String[]{"TaxonBase","TaxonBase_AUD"});
|
868
|
Assert.assertNull("Shared taxon must not be set", taxonService.find(1).getSec());
|
869
|
Assert.assertNull(taxonService.find(2).getSec());
|
870
|
Assert.assertNull("Synonym of shared taxon must not be set", taxonService.find(3).getSec());
|
871
|
Assert.assertNull(taxonService.find(4).getSec());
|
872
|
taxon5 = taxonService.find(5);
|
873
|
Assert.assertEquals(newSec, taxon5.getSec());
|
874
|
Assert.assertNull(taxon5.getSecMicroReference());
|
875
|
}
|
876
|
|
877
|
@Test
|
878
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
879
|
public void testSetPublishForSubtree(){
|
880
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
881
|
|
882
|
//assert current state
|
883
|
Assert.assertTrue(taxonService.find(1).isPublish());
|
884
|
Assert.assertTrue(taxonService.find(2).isPublish());
|
885
|
Assert.assertTrue(taxonService.find(3).isPublish());
|
886
|
Assert.assertTrue(taxonService.find(4).isPublish());
|
887
|
Assert.assertTrue(taxonService.find(5).isPublish());
|
888
|
|
889
|
//set publish
|
890
|
// SecundumForSubtreeConfigurator config = new SetPublishForSubtreeConfigurator(subTreeUuid);
|
891
|
// config.setNewSecundum(newSec);
|
892
|
boolean publish = false;
|
893
|
taxonNodeService.setPublishForSubtree(subTreeUuid, publish, true, true, true, null);
|
894
|
|
895
|
commitAndStartNewTransaction(new String[]{});
|
896
|
Assert.assertEquals(publish, taxonService.find(1).isPublish());
|
897
|
Assert.assertEquals(true, taxonService.find(2).isPublish());
|
898
|
Assert.assertEquals(publish, taxonService.find(3).isPublish());
|
899
|
Assert.assertEquals(true, taxonService.find(4).isPublish());
|
900
|
Assert.assertEquals(publish, taxonService.find(5).isPublish());
|
901
|
}
|
902
|
|
903
|
@Test
|
904
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
905
|
public void testSetPublishForSubtreeOnlyAccepted(){
|
906
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
907
|
|
908
|
//assert current state
|
909
|
Assert.assertTrue(taxonService.find(1).isPublish());
|
910
|
Assert.assertTrue(taxonService.find(2).isPublish());
|
911
|
Assert.assertTrue(taxonService.find(3).isPublish());
|
912
|
Assert.assertTrue(taxonService.find(4).isPublish());
|
913
|
Assert.assertTrue(taxonService.find(5).isPublish());
|
914
|
|
915
|
//set secundum
|
916
|
// SecundumForSubtreeConfigurator config = new SetPublishForSubtreeConfigurator(subTreeUuid, newSec, null);
|
917
|
// config.setIncludeSynonyms(false);
|
918
|
boolean publish = false;
|
919
|
taxonNodeService.setPublishForSubtree(subTreeUuid, publish, true, false, true, null);
|
920
|
|
921
|
commitAndStartNewTransaction();
|
922
|
Assert.assertEquals(publish, taxonService.find(1).isPublish());
|
923
|
Assert.assertEquals(true, taxonService.find(2).isPublish());
|
924
|
Assert.assertEquals(true, taxonService.find(3).isPublish());
|
925
|
Assert.assertEquals(true, taxonService.find(4).isPublish());
|
926
|
Assert.assertEquals(publish, taxonService.find(5).isPublish());
|
927
|
}
|
928
|
|
929
|
@Test
|
930
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
931
|
public void testSetPublishForSubtreeOnlySynonyms(){
|
932
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
933
|
|
934
|
//assert current state
|
935
|
Assert.assertTrue(taxonService.find(1).isPublish());
|
936
|
Assert.assertTrue(taxonService.find(2).isPublish());
|
937
|
Assert.assertTrue(taxonService.find(3).isPublish());
|
938
|
Assert.assertTrue(taxonService.find(4).isPublish());
|
939
|
Assert.assertTrue(taxonService.find(5).isPublish());
|
940
|
|
941
|
//set secundum
|
942
|
// SecundumForSubtreeConfigurator config = new SetPublishForSubtreeConfigurator(subTreeUuid, newSec, null);
|
943
|
// config.setIncludeAcceptedTaxa(false);
|
944
|
boolean publish = false;
|
945
|
taxonNodeService.setPublishForSubtree(subTreeUuid, publish, false, true, true, null);
|
946
|
|
947
|
commitAndStartNewTransaction(new String[]{});
|
948
|
Assert.assertEquals(true, taxonService.find(1).isPublish());
|
949
|
Assert.assertEquals(true, taxonService.find(2).isPublish());
|
950
|
Assert.assertEquals(publish, taxonService.find(3).isPublish());
|
951
|
Assert.assertEquals(true, taxonService.find(4).isPublish());
|
952
|
Assert.assertEquals(true, taxonService.find(5).isPublish());
|
953
|
}
|
954
|
|
955
|
|
956
|
@Test
|
957
|
@DataSet("TaxonNodeServiceImplTest.testSetSecundumForSubtree.xml")
|
958
|
public void testSetPublishForSubtreeNoShared(){
|
959
|
UUID subTreeUuid = UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
|
960
|
|
961
|
//assert current state
|
962
|
Assert.assertTrue(taxonService.find(1).isPublish());
|
963
|
Assert.assertTrue(taxonService.find(2).isPublish());
|
964
|
Assert.assertTrue(taxonService.find(3).isPublish());
|
965
|
Assert.assertTrue(taxonService.find(4).isPublish());
|
966
|
Assert.assertTrue(taxonService.find(5).isPublish());
|
967
|
|
968
|
//set secundum
|
969
|
// SecundumForSubtreeConfigurator config = new SetPublishForSubtreeConfigurator(subTreeUuid, newSec, null);
|
970
|
// config.setIncludeSharedTaxa(false);
|
971
|
boolean publish = false;
|
972
|
taxonNodeService.setPublishForSubtree(subTreeUuid, publish, true, true, false, null);
|
973
|
|
974
|
commitAndStartNewTransaction(new String[]{});
|
975
|
Assert.assertEquals("Shared taxon must not be set", true, taxonService.find(1).isPublish());
|
976
|
Assert.assertEquals(true, taxonService.find(2).isPublish());
|
977
|
Assert.assertEquals("Synonym of shared taxon must not be set", true, taxonService.find(3).isPublish());
|
978
|
Assert.assertEquals(true, taxonService.find(4).isPublish());
|
979
|
Assert.assertEquals(publish, taxonService.find(5).isPublish());
|
980
|
}
|
981
|
|
982
|
|
983
|
@Override
|
984
|
// @Test
|
985
|
public void createTestDataSet() throws FileNotFoundException {
|
986
|
UUID classificationUuid = UUID.fromString("029b4c07-5903-4dcf-87e8-406ed0e0285f");
|
987
|
UUID abiesUuid = UUID.fromString("f8306fd3-9825-41bf-94aa-a7b5790b553e");
|
988
|
UUID abiesAlbaUuid = UUID.fromString("c70f76e5-2dcb-41c5-ae6f-d756e0a0fae0");
|
989
|
UUID abiesAlbaSubBrotaUuid = UUID.fromString("06d58161-7707-44b5-b720-6c0eb916b37c");
|
990
|
UUID abiesPalmaUuid = UUID.fromString("6dfd30dd-e589-493a-b66a-19c4cb374f92");
|
991
|
UUID pinusUuid = UUID.fromString("5d8e8341-f5e9-4616-96cf-f0351dda42f4");
|
992
|
|
993
|
/*
|
994
|
* Checklist
|
995
|
* - Abies
|
996
|
* - Abies alba
|
997
|
* - Abieas alba subs. brota
|
998
|
* - Abies palma
|
999
|
* -Pinus
|
1000
|
*/
|
1001
|
Classification checklist = Classification.NewInstance("Checklist");
|
1002
|
checklist.setUuid(classificationUuid);
|
1003
|
|
1004
|
IBotanicalName abiesName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1005
|
abiesName.setGenusOrUninomial("Abies");
|
1006
|
Taxon abies = Taxon.NewInstance(abiesName, null);
|
1007
|
abies.setUuid(abiesUuid);
|
1008
|
|
1009
|
IBotanicalName abiesAlbaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1010
|
abiesAlbaName.setGenusOrUninomial("Abies");
|
1011
|
abiesAlbaName.setSpecificEpithet("alba");
|
1012
|
Taxon abiesAlba = Taxon.NewInstance(abiesAlbaName, null);
|
1013
|
abiesAlba.setUuid(abiesAlbaUuid);
|
1014
|
|
1015
|
IBotanicalName abiesAlbaSubBrotaName = TaxonNameFactory.NewBotanicalInstance(Rank.SUBSPECIES());
|
1016
|
abiesAlbaSubBrotaName.setGenusOrUninomial("Abies");
|
1017
|
abiesAlbaSubBrotaName.setSpecificEpithet("alba");
|
1018
|
abiesAlbaSubBrotaName.setInfraSpecificEpithet("brota");
|
1019
|
Taxon abiesAlbaSubBrota = Taxon.NewInstance(abiesAlbaSubBrotaName, null);
|
1020
|
abiesAlbaSubBrota.setUuid(abiesAlbaSubBrotaUuid);
|
1021
|
|
1022
|
IBotanicalName abiesPalmaName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
1023
|
abiesPalmaName.setGenusOrUninomial("Abies");
|
1024
|
abiesPalmaName.setSpecificEpithet("palma");
|
1025
|
Taxon abiesPalma = Taxon.NewInstance(abiesPalmaName, null);
|
1026
|
abiesPalma.setUuid(abiesPalmaUuid);
|
1027
|
|
1028
|
IBotanicalName pinusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
1029
|
pinusName.setGenusOrUninomial("Pinus");
|
1030
|
Taxon pinus = Taxon.NewInstance(pinusName, null);
|
1031
|
pinus.setUuid(pinusUuid);
|
1032
|
|
1033
|
checklist.addChildTaxon(abies, null, null);
|
1034
|
checklist.addParentChild(abies, abiesAlba, null, null);
|
1035
|
checklist.addParentChild(abiesAlba, abiesAlbaSubBrota, null, null);
|
1036
|
checklist.addParentChild(abies, abiesPalma, null, null);
|
1037
|
checklist.addChildTaxon(pinus, null, null);
|
1038
|
|
1039
|
taxonService.saveOrUpdate(abies);
|
1040
|
taxonService.saveOrUpdate(abiesAlba);
|
1041
|
taxonService.saveOrUpdate(abiesAlbaSubBrota);
|
1042
|
taxonService.saveOrUpdate(abiesPalma);
|
1043
|
taxonService.saveOrUpdate(pinus);
|
1044
|
classificationService.saveOrUpdate(checklist);
|
1045
|
|
1046
|
|
1047
|
setComplete();
|
1048
|
endTransaction();
|
1049
|
|
1050
|
String fileNameAppendix = "testGetUuidAndTitleCacheHierarchy";
|
1051
|
|
1052
|
writeDbUnitDataSetFile(new String[] {
|
1053
|
"TAXONBASE", "TAXONNAME",
|
1054
|
"TAXONRELATIONSHIP",
|
1055
|
"HOMOTYPICALGROUP",
|
1056
|
"CLASSIFICATION", "TAXONNODE",
|
1057
|
"LANGUAGESTRING",
|
1058
|
"HIBERNATE_SEQUENCES" // IMPORTANT!!!
|
1059
|
},
|
1060
|
fileNameAppendix );
|
1061
|
}
|
1062
|
|
1063
|
|
1064
|
}
|