1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.tmp;
|
5
|
|
6
|
import java.io.FileNotFoundException;
|
7
|
import java.util.List;
|
8
|
import java.util.UUID;
|
9
|
|
10
|
import org.junit.Assert;
|
11
|
import org.junit.Before;
|
12
|
import org.junit.Test;
|
13
|
import org.unitils.spring.annotation.SpringBeanByType;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
16
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
20
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
|
21
|
import eu.etaxonomy.cdm.persistence.dao.taxon.tmp.TaxonNodeFilter;
|
22
|
import eu.etaxonomy.cdm.persistence.dao.taxon.tmp.TaxonNodeFilterDaoHibernateImpl;
|
23
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @date 2014/06/13
|
28
|
*
|
29
|
*/
|
30
|
public class TaxonNodeFilterDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
|
31
|
|
32
|
@SpringBeanByType
|
33
|
private ITaxonNodeDao taxonNodeDao;
|
34
|
|
35
|
@SpringBeanByType
|
36
|
private IClassificationDao classificationDao;
|
37
|
|
38
|
@SpringBeanByType
|
39
|
private TaxonNodeFilterDaoHibernateImpl filterDao;
|
40
|
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
private Classification classification1;
|
46
|
private TaxonNode node1;
|
47
|
private TaxonNode node2;
|
48
|
private TaxonNode node3;
|
49
|
private TaxonNode node4;
|
50
|
private TaxonNode node5;
|
51
|
|
52
|
/**
|
53
|
* @throws java.lang.Exception
|
54
|
*/
|
55
|
@Before
|
56
|
public void setUp() throws Exception {
|
57
|
classification1 = Classification.NewInstance("TestClassification");
|
58
|
Reference citation = null;
|
59
|
String microCitation = null;
|
60
|
Taxon taxon1 = Taxon.NewInstance(null, null);
|
61
|
Taxon taxon2 = Taxon.NewInstance(null, null);
|
62
|
Taxon taxon3 = Taxon.NewInstance(null, null);
|
63
|
Taxon taxon4 = Taxon.NewInstance(null, null);
|
64
|
Taxon taxon5 = Taxon.NewInstance(null, null);
|
65
|
node1 = classification1.addChildTaxon(taxon1, citation, microCitation);
|
66
|
node2 = classification1.addChildTaxon(taxon2, citation, microCitation);
|
67
|
node3 = node1.addChildTaxon(taxon3, citation, microCitation);
|
68
|
node4 = node3.addChildTaxon(taxon4, citation, microCitation);
|
69
|
node5 = node3.addChildTaxon(taxon5, citation, microCitation);
|
70
|
classificationDao.save(classification1);
|
71
|
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.taxon.tmp.TaxonNodeFilterDaoHibernateImpl#listUuids(eu.etaxonomy.cdm.persistence.dao.taxon.tmp.TaxonNodeFilter)}.
|
76
|
*/
|
77
|
@Test
|
78
|
public void testListUuids() {
|
79
|
Classification classification = classificationDao.findByUuid(classification1.getUuid());
|
80
|
TaxonNodeFilter filter = new TaxonNodeFilter(node1);
|
81
|
List<UUID> listUuid = filterDao.listUuids(filter);
|
82
|
Assert.assertEquals("All 4 children should be returned", 4, listUuid.size());
|
83
|
Assert.assertTrue(listUuid.contains(node4.getUuid()));
|
84
|
Assert.assertFalse(listUuid.contains(node2.getUuid()));
|
85
|
Assert.assertFalse(listUuid.contains(classification.getRootNode().getUuid()));
|
86
|
|
87
|
|
88
|
filter = new TaxonNodeFilter(classification.getRootNode());
|
89
|
listUuid = filterDao.listUuids(filter);
|
90
|
//FIXME still unclear if (empty) root node should be part of the result
|
91
|
Assert.assertEquals("All 6 children should be returned", 6, listUuid.size());
|
92
|
|
93
|
filter = new TaxonNodeFilter(node3);
|
94
|
listUuid = filterDao.listUuids(filter);
|
95
|
Assert.assertEquals("All 3 children should be returned", 3, listUuid.size());
|
96
|
|
97
|
filter.or(node2);
|
98
|
listUuid = filterDao.listUuids(filter);
|
99
|
Assert.assertEquals("All 3 children and node 2 should be returned", 4, listUuid.size());
|
100
|
Assert.assertTrue(listUuid.contains(node2.getUuid()));
|
101
|
|
102
|
filter = new TaxonNodeFilter(node1).not(node4);
|
103
|
listUuid = filterDao.listUuids(filter);
|
104
|
Assert.assertEquals("Node and 2 children but not node4 should be returned", 3, listUuid.size());
|
105
|
Assert.assertFalse(listUuid.contains(node4.getUuid()));
|
106
|
|
107
|
|
108
|
|
109
|
|
110
|
|
111
|
}
|
112
|
|
113
|
/* (non-Javadoc)
|
114
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
115
|
*/
|
116
|
@Override
|
117
|
public void createTestDataSet() throws FileNotFoundException {
|
118
|
// TODO Auto-generated method stub
|
119
|
|
120
|
}
|
121
|
|
122
|
}
|