2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.description
;
12 import java
.util
.UUID
;
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
;
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
;
26 public class PolytomousKeyDaoHibernateImplTest
extends CdmTransactionalIntegrationTest
{
29 PolytomousKeyDaoImpl polytomousKeyDao
;
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());
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());
61 newRoot
.addChild(child1
);
62 newRoot
.addChild(child3
);
63 newRoot
.addChild(child2
, 1);
65 UUID newKeyUuid
= polytomousKeyDao
.save(newKey
);
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());
73 // printDataSet(System.out, new String[]{"PolytomousKeyNode", "KeyStatement", "KeyStatement_LanguageString", "LanguageString"});
74 System
.out
.println("End test1");
78 public void testDeletePolyotomousKey(){
79 UUID uuid
= UUID
.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
80 PolytomousKey existingKey
= polytomousKeyDao
.findByUuid(uuid
);
81 Assert
.assertNotNull("",existingKey
);
83 polytomousKeyDao
.delete(existingKey
);
85 commitAndStartNewTransaction(null);
87 try {if (true){printDataSet(System
.out
, new String
[]{"POLYTOMOUSKEY", "POLYTOMOUSKEYNODE"});}
88 } catch(Exception e
) { logger
.warn(e
);}
90 PolytomousKey nonExistingKey
= polytomousKeyDao
.findByUuid(uuid
);
91 Assert
.assertNull("", nonExistingKey
);
95 public void testNothing(){
96 //maybe deleted once testSavePolytomousKey() works correctly