Project

General

Profile

Download (3.83 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.persistence.dao.hibernate.taxon;
11

    
12
import static junit.framework.Assert.assertNotNull;
13
import static org.junit.Assert.assertEquals;
14

    
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import org.junit.After;
21
import org.junit.Before;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24
import org.unitils.spring.annotation.SpringBeanByType;
25

    
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
30
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
31
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
32
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
33
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonomicTreeDao;
34
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
35

    
36
public class TaxonNodeDaoHibernateImplTest extends
37
		CdmTransactionalIntegrationTest {
38

    
39
	@SpringBeanByType	
40
	private ITaxonNodeDao taxonNodeDao;
41
	
42
	@SpringBeanByType
43
	private ITaxonomicTreeDao taxonomicTreeDao;
44
	
45
	@SpringBeanByType
46
	private ITaxonDao taxonDao;
47
	
48
	private UUID uuid1;
49
	private UUID uuid2;
50
	private UUID uuid3;
51
	
52
	@Before
53
	public void setUp(){
54
		uuid1 = UUID.fromString("20c8f083-5870-4cbd-bf56-c5b2b98ab6a7");
55
		uuid2 = UUID.fromString("770239f6-4fa8-496b-8738-fe8f7b2ad519");
56
		AuditEventContextHolder.clearContext(); 
57
	}
58
	
59
	@After
60
	public void tearDown(){
61
		AuditEventContextHolder.clearContext(); 
62
	}
63
	
64
	
65
	@Test
66
	@DataSet
67
	public void testInit() {
68
		assertNotNull("Instance of ITaxonDao expected",taxonNodeDao);
69
		assertNotNull("Instance of IReferenceDao expected",taxonomicTreeDao);
70
	}	
71
	
72
	@Test
73
	@DataSet
74
	public void testFindByUuid() {
75
		TaxonNode taxonNode = (TaxonNode) taxonNodeDao.findByUuid(uuid1);
76
		TaxonomicTree.class.getDeclaredConstructors();
77
		assertNotNull("findByUuid should return a taxon node", taxonNode);
78
	}
79
	
80
	@Test
81
	@DataSet
82
	public void testTaxonomicTree() {
83
		TaxonomicTree taxonTree =  taxonomicTreeDao.findByUuid(UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9"));
84
		
85
		assertNotNull("findByUuid should return a taxon tree", taxonTree);
86
		assertNotNull("taxonomic tree should have a name",taxonTree.getName());
87
		assertEquals("taxonomic tree should have a name which is 'Name'",taxonTree.getName().getText(),"Name");
88
		TaxonNode taxNode = (TaxonNode) taxonNodeDao.findByUuid(uuid1);
89
		TaxonNode taxNode2 = (TaxonNode) taxonNodeDao.findByUuid(uuid2);
90
		Set<TaxonNode> rootNodes = new HashSet<TaxonNode>();
91
		
92
		rootNodes.add(taxNode);
93
		
94
	
95
		for (TaxonNode rootNode : rootNodes){
96
			taxonTree.addChildNode(rootNode, rootNode.getReference(), rootNode.getMicroReference(), rootNode.getSynonymToBeUsed());
97
		}
98
		
99
		//taxonTree.addChildNode(taxNode, taxNode.getReference(), taxNode.getMicroReference(), taxNode.getSynonymToBeUsed());
100
		
101
		//old: taxonTree.setRootNodes(rootNodes);
102
		taxNode.addChildNode(taxNode2, null, null,null);
103
		
104
		Taxon taxon2 = taxNode2.getTaxon();
105
		Taxon taxon = taxNode.getTaxon();
106
		UUID uuidTaxon = taxon.getUuid();
107
		UUID uuidTaxon2 = taxon2.getUuid();
108
	
109
		List<TaxonBase> taxa = taxonDao.getAllTaxonBases(10, 0);
110
		assertEquals("there should be only two taxa", 5, taxa.size());
111
		
112
		taxonNodeDao.delete(taxNode2);
113
				
114
		taxa = taxonDao.getAllTaxonBases(10, 0);
115
		assertEquals("there should be only one taxon left", 4, taxa.size());
116
		
117
		taxonomicTreeDao.delete(taxonTree);
118
		taxonTree = taxonomicTreeDao.findByUuid(UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9"));
119
		assertEquals("The tree should be null", null, taxonTree);
120
		
121
		
122
	}
123
}
(2-2/2)