Project

General

Profile

Download (20.2 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.api.service;
12

    
13
import static org.junit.Assert.assertEquals;
14
import static org.junit.Assert.assertFalse;
15
import static org.junit.Assert.assertNotNull;
16
import static org.junit.Assert.assertNull;
17
import static org.junit.Assert.assertTrue;
18

    
19
import java.io.FileNotFoundException;
20
import java.util.ArrayList;
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.hibernate.HibernateProxyHelper;
33
import eu.etaxonomy.cdm.model.common.CdmBase;
34
import eu.etaxonomy.cdm.model.description.PolytomousKey;
35
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
36
import eu.etaxonomy.cdm.model.name.BotanicalName;
37
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
38
import eu.etaxonomy.cdm.model.name.Rank;
39
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
40
import eu.etaxonomy.cdm.model.reference.Reference;
41
import eu.etaxonomy.cdm.model.taxon.Classification;
42
import eu.etaxonomy.cdm.model.taxon.Synonym;
43
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
44
import eu.etaxonomy.cdm.model.taxon.Taxon;
45
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
46
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
47
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
48
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
49

    
50
/**
51
 * @author n.hoffmann
52
 * @created Dec 16, 2010
53
 */
54
//@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
55
public class TaxonNodeServiceImplTest extends CdmTransactionalIntegrationTest{
56

    
57

    
58
	@SpringBeanByType
59
	private ITaxonNodeService taxonNodeService;
60

    
61
	@SpringBeanByType
62
	private IClassificationService classificationService;
63

    
64
	@SpringBeanByType
65
	private IReferenceService referenceService;
66

    
67
	@SpringBeanByType
68
	private ITermService termService;
69

    
70
	@SpringBeanByType
71
    private INameService nameService;
72

    
73
	@SpringBeanByType
74
	private ITaxonService taxonService;
75

    
76
	@SpringBeanByType
77
	private IPolytomousKeyService polKeyService;
78

    
79
	@SpringBeanByType
80
	private IPolytomousKeyNodeService polKeyNodeService;
81

    
82

    
83
	private static final UUID t1Uuid = UUID.fromString("55c3e41a-c629-40e6-aa6a-ff274ac6ddb1");
84
	private static final UUID t2Uuid = UUID.fromString("2659a7e0-ff35-4ee4-8493-b453756ab955");
85
	private static final UUID classificationUuid = UUID.fromString("6c2bc8d9-ee62-4222-be89-4a8e31770878");
86
	private static final UUID classification2Uuid = UUID.fromString("43d67247-936f-42a3-a739-bbcde372e334");
87
	private static final UUID referenceUuid = UUID.fromString("de7d1205-291f-45d9-9059-ca83fc7ade14");
88
	private static final UUID node1Uuid= UUID.fromString("484a1a77-689c-44be-8e65-347d835f47e8");
89
	private static final UUID node2Uuid = UUID.fromString("2d41f0c2-b785-4f73-a436-cc2d5e93cc5b");
90

    
91
	private static final UUID node4Uuid = UUID.fromString("2fbf7bf5-22dd-4c1a-84e4-c8c93d1f0342");
92
	private static final UUID node5Uuid = UUID.fromString("c4d5170a-7967-4dac-ab76-ae2019eefde5");
93
	private static final UUID node6Uuid = UUID.fromString("b419ba5e-9c8b-449c-ad86-7abfca9a7340");
94
	private static final UUID rootNodeUuid = UUID.fromString("324a1a77-689c-44be-8e65-347d835f4111");
95

    
96

    
97
	private Taxon t1;
98
	private Taxon t2;
99
	private Taxon t4;
100
//	private Synonym s1;
101
	private SynonymRelationshipType synonymRelationshipType;
102
	private Reference<?> reference;
103
	private String referenceDetail;
104
	private Classification classification;
105
	private TaxonNode node1;
106
	private TaxonNode node2;
107

    
108
    private TaxonNode node4;
109

    
110
	/**
111
	 * @throws java.lang.Exception
112
	 */
113
	@Before
114
	public void setUp() throws Exception {
115
	}
116

    
117
	/**
118
	 * 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.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
119
	 */
120
	@Test
121
	@DataSet
122
	public final void testMakeTaxonNodeASynonymOfAnotherTaxonNode() {
123
		classification = classificationService.load(classificationUuid);
124
		node1 = taxonNodeService.load(node1Uuid);
125
		node2 = taxonNodeService.load(node2Uuid);
126
		node4 = taxonNodeService.load(node4Uuid);
127
		reference = referenceService.load(referenceUuid);
128
//		synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
129
		synonymRelationshipType = CdmBase.deproxy(termService.load(SynonymRelationshipType.uuidHomotypicSynonymOf), SynonymRelationshipType.class) ;
130
		referenceDetail = "test";
131

    
132
		//
133
		//TODO
134

    
135
//		printDataSet(System.err, new String [] {"TaxonNode"});
136

    
137
		// descriptions
138
		t1 = node1.getTaxon();
139
		PolytomousKey polKey = PolytomousKey.NewInstance();
140
		PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
141
		keyNode.setKey(polKey);
142
		polKeyNodeService.save(keyNode);
143
		polKeyService.save(polKey);
144

    
145
		//nameRelations
146

    
147
		t1.getName().addRelationshipFromName(BotanicalName.NewInstance(Rank.SPECIES()), NameRelationshipType.ALTERNATIVE_NAME(), null );
148

    
149
		//taxonRelations
150
		t1.addTaxonRelation(Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null), TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
151
		Synonym synonym = Synonym.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
152
		UUID uuidSynonym = taxonService.save(synonym).getUuid();
153

    
154
		t1.addHomotypicSynonym(synonym, null, null);
155
		UUID uuidT1 = taxonService.saveOrUpdate(t1);
156
		t1 = null;
157
		t1 =(Taxon) taxonService.load(uuidT1);
158
		t1 = (Taxon)HibernateProxyHelper.deproxy(t1);
159
		TaxonNameBase nameT1 = t1.getName();
160
		UUID t1UUID = t1.getUuid();
161
		t2 = node2.getTaxon();
162
		assertEquals(2, t1.getDescriptions().size());
163
		Assert.assertTrue(t2.getSynonyms().isEmpty());
164
		Assert.assertTrue(t2.getDescriptions().size() == 0);
165
		assertEquals(2,t1.getSynonyms().size());
166
		UUID synUUID = null;
167
		DeleteResult result;
168

    
169
		t4 = node4.getTaxon();
170
        UUID uuidT4 = t4.getUuid();
171
        t4 = (Taxon) taxonService.load(uuidT4);
172
        TaxonNameBase name4 = nameService.load(t4.getName().getUuid());
173
        result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node4, node2, synonymRelationshipType, reference, referenceDetail);
174
        if (result.isError() || result.isAbort()){
175
            Assert.fail();
176
        }
177
        t4 = (Taxon)taxonService.find(uuidT4);
178
        assertNull(t4);
179

    
180

    
181
		//Taxon can't be deleted because of the polytomous key node
182

    
183
		result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymRelationshipType, reference, referenceDetail);
184
		if (result.isError() || result.isAbort()){
185
			Assert.fail();
186
		}
187
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
188
		t1 = (Taxon)taxonService.find(t1Uuid);
189
		assertNotNull(t1);//because of the polytomous key node
190
		node1 = taxonNodeService.load(node1Uuid);
191
		assertNull(node1);
192

    
193

    
194

    
195

    
196
		Set<CdmBase> updatedObjects = result.getUpdatedObjects();
197
		Iterator<CdmBase> it = updatedObjects.iterator();
198
		Taxon taxon;
199
		if (it.hasNext()) {
200
			CdmBase updatedObject = it.next();
201
			if(updatedObject.isInstanceOf(Taxon.class)){
202
				taxon = HibernateProxyHelper.deproxy(updatedObject, Taxon.class);
203
				Set<Synonym> syns =  taxon.getSynonyms();
204
				assertNotNull(syns);
205
				assertEquals(4,syns.size());
206

    
207
				Set<TaxonNameBase> typifiedNames =taxon.getHomotypicGroup().getTypifiedNames();
208
				assertEquals(typifiedNames.size(),4);
209
				assertTrue(taxon.getHomotypicGroup().equals( nameT1.getHomotypicalGroup()));
210

    
211
				assertEquals(taxon, t2);
212

    
213
			} else{
214
				Assert.fail();
215
			}
216

    
217

    
218
		}
219

    
220

    
221

    
222
	}
223

    
224
	/**
225
	 * 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.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
226
	 */
227
	@Test
228
	@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
229
	public final void testMakeTaxonNodeAHeterotypicSynonymOfAnotherTaxonNode() {
230
		classification = classificationService.load(classificationUuid);
231
		node1 = taxonNodeService.load(node1Uuid);
232
		node2 = taxonNodeService.load(node2Uuid);
233
		reference = referenceService.load(referenceUuid);
234
//		synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
235
		synonymRelationshipType = CdmBase.deproxy(termService.load(SynonymRelationshipType.uuidHeterotypicSynonymOf), SynonymRelationshipType.class) ;
236
		referenceDetail = "test";
237

    
238
		//
239
		//TODO
240

    
241
//		printDataSet(System.err, new String [] {"TaxonNode"});
242

    
243
		// descriptions
244
		t1 = node1.getTaxon();
245
		PolytomousKey polKey = PolytomousKey.NewInstance();
246
		PolytomousKeyNode keyNode = PolytomousKeyNode.NewInstance("", "", t1, null);
247
		keyNode.setKey(polKey);
248
		polKeyNodeService.save(keyNode);
249
		polKeyService.save(polKey);
250

    
251
		//nameRelations
252

    
253
		t1.getName().addRelationshipFromName(BotanicalName.NewInstance(Rank.SPECIES()), NameRelationshipType.ALTERNATIVE_NAME(), null );
254
		TaxonNameBase name1 = t1.getName();
255
		UUID name1UUID = name1.getUuid();
256
		//taxonRelations
257
		t1.addTaxonRelation(Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null), TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
258
		Synonym synonym = Synonym.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
259
		UUID uuidSynonym = taxonService.save(synonym).getUuid();
260
		t1.addHomotypicSynonym(synonym, null, null);
261
		TaxonNameBase nameT1 = t1.getName();
262
		UUID t1UUID = t1.getUuid();
263
		t2 = node2.getTaxon();
264
		assertEquals(2, t1.getDescriptions().size());
265
		Assert.assertTrue(t2.getSynonyms().isEmpty());
266
		Assert.assertTrue(t2.getDescriptions().size() == 0);
267
		assertEquals(2,t1.getSynonyms().size());
268
		UUID synUUID = null;
269
		DeleteResult result;
270
		result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymRelationshipType, reference, referenceDetail);
271

    
272
		if (!result.getUpdatedObjects().iterator().hasNext()){
273
			Assert.fail();
274
		}
275
		Taxon newAcceptedTaxon = (Taxon)result.getUpdatedObjects().iterator().next();
276
		assertNotNull(taxonService.find(t1Uuid));
277
		assertNull(taxonNodeService.find(node1Uuid));
278

    
279

    
280
		synonym = (Synonym)taxonService.find(uuidSynonym);
281

    
282
		assertNotNull(synonym);
283
		keyNode.setTaxon(null);
284
		polKeyNodeService.saveOrUpdate(keyNode);
285
		HibernateProxyHelper.deproxy(t2);
286
		HibernateProxyHelper.deproxy(t2.getHomotypicGroup());
287
		HibernateProxyHelper.deproxy(t2.getName());
288
//		syn = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode(node1, node2, synonymRelationshipType, reference, referenceDetail);
289
//		if (syn == null){
290
//			Assert.fail();
291
//		}
292
//		synUUID = syn.getUuid();
293

    
294

    
295
		termService.saveOrUpdate(synonymRelationshipType);
296
		Assert.assertFalse(t2.getSynonyms().isEmpty());
297
		assertEquals(3,t2.getSynonyms().size());
298
		assertEquals(2, t2.getDescriptions().size());
299

    
300
		result = taxonService.deleteTaxon(t1.getUuid(), null, null);
301
		if (result.isAbort() || result.isError()){
302
			Assert.fail();
303
		}
304
		assertNull(taxonService.find(t1Uuid));
305
		assertNull(taxonNodeService.find(node1Uuid));
306
		name1 = nameService.find(name1UUID);
307
		synonym = (Synonym)taxonService.find(uuidSynonym);
308
		assertNotNull(name1);
309
		assertEquals(1, name1.getTaxonBases().size());
310
		assertNotNull(synonym);
311

    
312
		Synonym syn =(Synonym) name1.getTaxonBases().iterator().next();
313

    
314
		assertEquals(syn.getName().getHomotypicalGroup(), synonym.getName().getHomotypicalGroup());
315
		assertFalse(newAcceptedTaxon.getHomotypicGroup().equals( syn.getName().getHomotypicalGroup()));
316

    
317
		assertEquals(newAcceptedTaxon, t2);
318
		TaxonNameBase name = syn.getName();
319
		assertEquals(name, nameT1);
320
	}
321

    
322

    
323
	@Test
324
	@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
325
	public final void testIndexCreateNode() {
326
		Taxon taxon = Taxon.NewInstance(null, null);
327
		classification = classificationService.load(classificationUuid);
328
		node2 = taxonNodeService.load(node2Uuid);
329
		String oldTreeIndex = node2.treeIndex();
330

    
331
		TaxonNode newNode = node2.addChildTaxon(taxon, null, null);
332
		taxonNodeService.saveOrUpdate(node2);
333
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
334
		newNode = taxonNodeService.load(newNode.getUuid());
335
		Assert.assertEquals("", oldTreeIndex + newNode.getId() + "#", newNode.treeIndex());
336
	}
337

    
338

    
339
	@Test
340
	@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
341
	public final void testIndexMoveNode() {
342
		//in classification
343
		classification = classificationService.load(classificationUuid);
344
		node1 = taxonNodeService.load(node1Uuid);
345
		node2 = taxonNodeService.load(node2Uuid);
346
		node2.addChildNode(node1, null, null);
347
		taxonNodeService.saveOrUpdate(node1);
348
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
349
		TaxonNode node6 = taxonNodeService.load(node6Uuid);
350
		Assert.assertEquals("Node6 treeindex is not correct", node2.treeIndex() + "2#4#6#", node6.treeIndex());
351

    
352
		//root of new classification
353
		Classification classification2 = classificationService.load(classification2Uuid);
354
		node1 = taxonNodeService.load(node1Uuid);
355
		classification2.setRootNode(HibernateProxyHelper.deproxy(classification2.getRootNode(),TaxonNode.class));
356
		classification2.addChildNode(node1, null, null);
357
		taxonNodeService.saveOrUpdate(node1);
358
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
359
		node1 = taxonNodeService.load(node1Uuid);
360
		Assert.assertEquals("Node1 treeindex is not correct", "#t2#8#2#", node1.treeIndex());
361
		node6 = taxonNodeService.load(node6Uuid);
362
		Assert.assertEquals("Node6 treeindex is not correct", "#t2#8#2#4#6#", node6.treeIndex());
363

    
364
		//into new classification
365
		node2 = taxonNodeService.load(node2Uuid);
366
		TaxonNode node5 = taxonNodeService.load(node5Uuid);
367
		node5.addChildNode(node2, null, null);
368
		taxonNodeService.saveOrUpdate(node5);
369
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
370
		node2 = taxonNodeService.load(node2Uuid);
371
		Assert.assertEquals("Node3 treeindex is not correct", "#t2#8#2#5#3#", node2.treeIndex());
372

    
373
}
374

    
375
	@Test
376
	@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonNodeServiceImplTest-indexing.xml")
377
	public final void testIndexDeleteNode() {
378
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
379
		node1 = taxonNodeService.load(node1Uuid);
380
		TaxonNode node4 = taxonNodeService.load(node4Uuid);
381
		String treeIndex = node1.treeIndex();
382
		TaxonNode node6 = taxonNodeService.load(node6Uuid);
383
		treeIndex= node6.treeIndex();
384

    
385
		HibernateProxyHelper.deproxy(node1, TaxonNode.class);
386
		node1.deleteChildNode(node4, false);
387
		TaxonNode node5 = taxonNodeService.load(node5Uuid);
388
		treeIndex = node5.treeIndex();
389

    
390
		node6 = taxonNodeService.load(node6Uuid);
391

    
392
		treeIndex = node6.treeIndex();
393
		Taxon newTaxon= Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null);
394
		UUID taxonNewUuid = taxonService.save(newTaxon).getUuid();
395

    
396
		node5.addChildTaxon(newTaxon, null, null);
397
		String node5TreeIndex =node5.treeIndex();
398
		taxonNodeService.saveOrUpdate(node5);
399

    
400
		commitAndStartNewTransaction(new String[]{"TaxonNode"});
401
		node5 = taxonNodeService.load(node5Uuid);
402
		List<TaxonNode> children =  node5.getChildNodes();
403
		TaxonNode node = children.get(0);
404
		int id = node.getId();
405
		Assert.assertEquals("Node6 treeindex is not correct", "#t1#1#2#6#", treeIndex);
406
		Assert.assertEquals("new node treeindex is not correct", node5TreeIndex + id +"#", node.treeIndex());
407
	}
408

    
409

    
410
	@Test
411
	@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
412
	public final void testDeleteNode(){
413
		classification = classificationService.load(classificationUuid);
414
		node1 = taxonNodeService.load(node1Uuid);
415
		node2 = taxonNodeService.load(rootNodeUuid);
416
		node1 = (TaxonNode)HibernateProxyHelper.deproxy(node1);
417

    
418
		TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null), null, null);
419
		UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
420
		newNode = taxonNodeService.load(uuidNewNode);
421
		UUID taxUUID = newNode.getTaxon().getUuid();
422
		UUID nameUUID = newNode.getTaxon().getName().getUuid();
423

    
424
		DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
425
		if (!result.isOk()){
426
			Assert.fail();
427
		}
428
		newNode = taxonNodeService.load(uuidNewNode);
429
		node1 = taxonNodeService.load(node1Uuid);
430
		assertNull(newNode);
431
		assertNull(node1);
432

    
433
		t1 = (Taxon) taxonService.load(t1Uuid);
434
		assertNull(t1);
435
		Taxon newTaxon = (Taxon)taxonService.load(taxUUID);
436
		assertNull(newTaxon);
437
		BotanicalName name = (BotanicalName)nameService.load(nameUUID);
438
		assertNull(name);
439

    
440

    
441
	}
442

    
443
	@Test
444
    @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
445

    
446
    public final void testDeleteNodeWithReusedTaxon(){
447
        classification = classificationService.load(classificationUuid);
448
        node1 = taxonNodeService.load(node1Uuid);
449
        node2 = taxonNodeService.load(rootNodeUuid);
450
        node1 = (TaxonNode)HibernateProxyHelper.deproxy(node1);
451

    
452

    
453
        Classification classification2 = Classification.NewInstance("Classification2");
454
        TaxonNode nodeClassification2 =classification2.addChildTaxon(node1.getTaxon(), null, null);
455
        assertEquals(node1.getTaxon().getUuid(), t1Uuid);
456
        classificationService.save(classification2);
457
        List<TaxonNode> nodesOfClassification2 = taxonNodeService.listAllNodesForClassification(classification2, null, null);
458
        UUID nodeUUID = nodesOfClassification2.get(0).getUuid();
459
        assertEquals(nodeUUID, nodeClassification2.getUuid());
460
        Taxon newTaxon = Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()),  null);
461
        taxonService.save(newTaxon);
462
        TaxonNode newNode = node1.addChildTaxon(newTaxon,null, null);
463
        UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
464
        newNode = taxonNodeService.load(uuidNewNode);
465
        UUID taxUUID = newNode.getTaxon().getUuid();
466
        UUID nameUUID = newNode.getTaxon().getName().getUuid();
467

    
468
        DeleteResult result = taxonNodeService.deleteTaxonNode(node1, null);
469
        if (!result.isOk()){
470
            Assert.fail();
471
        }
472
        taxonService.getSession().flush();
473
        newNode = taxonNodeService.load(uuidNewNode);
474
        node1 = taxonNodeService.load(node1Uuid);
475
        assertNull(newNode);
476
        assertNull(node1);
477
        assertNotNull(taxonNodeService.load(nodeUUID));
478

    
479
        t1 = (Taxon) taxonService.load(t1Uuid);
480
        assertNotNull(t1);
481
        newTaxon = (Taxon)taxonService.load(taxUUID);
482
        assertNull(newTaxon);
483
        BotanicalName name = (BotanicalName)nameService.load(nameUUID);
484
        assertNull(name);
485

    
486

    
487
    }
488

    
489

    
490

    
491
	@Test
492
	@DataSet
493
	public final void testDeleteNodes(){
494
		classification = classificationService.load(classificationUuid);
495
		node1 = taxonNodeService.load(node1Uuid);
496
		node2 = taxonNodeService.load(rootNodeUuid);
497
		node1 = (TaxonNode)HibernateProxyHelper.deproxy(node1);
498
		node2 = (TaxonNode)HibernateProxyHelper.deproxy(node2);
499
		TaxonNode newNode = node1.addChildTaxon(Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null), null, null);
500
		UUID uuidNewNode = taxonNodeService.save(newNode).getUuid();
501
		List<TaxonNode> treeNodes = new ArrayList<TaxonNode>();
502
		treeNodes.add(node1);
503
		treeNodes.add(node2);
504

    
505
		DeleteResult result = taxonNodeService.deleteTaxonNodes(treeNodes, null);
506

    
507

    
508
		newNode = taxonNodeService.load(uuidNewNode);
509
		node1 = taxonNodeService.load(node1Uuid);
510
		assertNull(newNode);
511
		assertNull(node1);
512
		taxonService.getSession().flush();
513
		t1 = (Taxon) taxonService.load(t1Uuid);
514
		assertNull(t1);
515
		t2 = (Taxon) taxonService.load(t2Uuid);
516
		assertNull(t2);
517

    
518

    
519
	}
520
	@Test
521
	@DataSet
522
	public void testMoveTaxonNode(){
523
	    classification = classificationService.load(classificationUuid);
524
	  //  Set<TaxonNode>  nodes = classification.getAllNodes();
525
	    List<TaxonNode>  nodes = classification.getChildNodes();
526
	    System.out.println(nodes.size());
527
	    classification.addChildTaxon(Taxon.NewInstance(BotanicalName.NewInstance(Rank.SPECIES()), null), nodes.size(), null, null);
528
	   nodes =  classification.getChildNodes();
529
	    System.out.println(nodes.size());
530

    
531
	}
532

    
533
    /* (non-Javadoc)
534
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
535
     */
536
    @Override
537
    public void createTestDataSet() throws FileNotFoundException {
538
        // TODO Auto-generated method stub
539

    
540
    }
541

    
542

    
543
}
(23-23/31)