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.persistence.dao.hibernate.description;
|
11
|
|
12
|
import java.io.FileNotFoundException;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.junit.Assert;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.Test;
|
18
|
import org.unitils.dbunit.annotation.DataSet;
|
19
|
import org.unitils.spring.annotation.SpringBeanByType;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.common.Language;
|
22
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
23
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
24
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
25
|
|
26
|
@DataSet
|
27
|
public class PolytomousKeyDaoHibernateImplTest extends CdmTransactionalIntegrationTest {
|
28
|
|
29
|
@SpringBeanByType
|
30
|
PolytomousKeyDaoImpl polytomousKeyDao;
|
31
|
|
32
|
|
33
|
@Before
|
34
|
public void setUp() {
|
35
|
|
36
|
}
|
37
|
|
38
|
@Test
|
39
|
@DataSet("PolytomousKeyDaoHibernateImplTest.xml")
|
40
|
// @ExpectedDataSet //for some reason this result in an infinite waiting of the connection pool
|
41
|
public void testSavePolytomousKey() {
|
42
|
PolytomousKey existingKey = polytomousKeyDao.findByUuid(UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097"));
|
43
|
Assert.assertNotNull("",existingKey);
|
44
|
PolytomousKeyNode root = existingKey.getRoot();
|
45
|
Assert.assertNotNull("Root should not be null",root);
|
46
|
Assert.assertEquals(2, root.childCount());
|
47
|
|
48
|
//new key
|
49
|
PolytomousKey newKey = PolytomousKey.NewInstance();
|
50
|
PolytomousKeyNode newRoot = newKey.getRoot();
|
51
|
PolytomousKeyNode child1 = PolytomousKeyNode.NewInstance();
|
52
|
child1.addQuestionText("Question1", null);
|
53
|
child1.addQuestionText("Question1German", Language.GERMAN());
|
54
|
child1.addStatementText("Statement1", null);
|
55
|
PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance();
|
56
|
child2.addStatementText("Statement2", null);
|
57
|
child2.addQuestionText("Question2German", Language.DEFAULT());
|
58
|
PolytomousKeyNode child3 = PolytomousKeyNode.NewInstance();
|
59
|
child3.addStatementText("Statement3", null);
|
60
|
child3.addStatementText("Statement3German", Language.GERMAN());
|
61
|
|
62
|
newRoot.addChild(child1);
|
63
|
newRoot.addChild(child3);
|
64
|
newRoot.addChild(child2, 1);
|
65
|
|
66
|
newKey = polytomousKeyDao.save(newKey);
|
67
|
|
68
|
//doesn't make sense as long as there is no new session
|
69
|
PolytomousKey newKeyFromDb = polytomousKeyDao.findByUuid(newKey.getUuid());
|
70
|
// List<PolytomousKeyNode> children = newKeyFromDb.getRoot().getChildren();
|
71
|
// Assert.assertEquals(child1.getUuid(), children.get(0).getUuid());
|
72
|
// Assert.assertNotSame(child1.getUuid(), children.get(0).getUuid());
|
73
|
|
74
|
// printDataSet(System.out, new String[]{"PolytomousKeyNode", "KeyStatement", "KeyStatement_LanguageString", "LanguageString"});
|
75
|
System.out.println("End test1");
|
76
|
}
|
77
|
|
78
|
@Test
|
79
|
public void testDeletePolyotomousKey(){
|
80
|
UUID uuid = UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
|
81
|
PolytomousKey existingKey = polytomousKeyDao.findByUuid(uuid);
|
82
|
Assert.assertNotNull("",existingKey);
|
83
|
|
84
|
polytomousKeyDao.delete(existingKey);
|
85
|
|
86
|
commitAndStartNewTransaction(null);
|
87
|
|
88
|
try {if (true){printDataSet(System.out, new String[]{"POLYTOMOUSKEY", "POLYTOMOUSKEYNODE"});}
|
89
|
} catch(Exception e) { logger.warn(e);}
|
90
|
|
91
|
PolytomousKey nonExistingKey = polytomousKeyDao.findByUuid(uuid);
|
92
|
Assert.assertNull("", nonExistingKey);
|
93
|
}
|
94
|
|
95
|
@Test
|
96
|
public void testNothing(){
|
97
|
//maybe deleted once testSavePolytomousKey() works correctly
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
102
|
*/
|
103
|
@Override
|
104
|
public void createTestDataSet() throws FileNotFoundException {
|
105
|
// TODO Auto-generated method stub
|
106
|
|
107
|
}
|
108
|
}
|