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