3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.description
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.junit
.Assert
;
17 import org
.junit
.Before
;
18 import org
.junit
.BeforeClass
;
19 import org
.junit
.Ignore
;
20 import org
.junit
.Test
;
21 import org
.unitils
.dbunit
.annotation
.DataSet
;
22 import org
.unitils
.dbunit
.annotation
.ExpectedDataSet
;
23 import org
.unitils
.dbunit
.datasetfactory
.impl
.MultiSchemaXmlDataSetFactory
;
24 import org
.unitils
.spring
.annotation
.SpringBeanByType
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
27 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
28 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
29 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
30 import eu
.etaxonomy
.cdm
.model
.description
.State
;
31 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
32 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
33 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
34 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
35 import eu
.etaxonomy
.cdm
.test
.integration
.CdmTransactionalIntegrationTest
;
42 public class DescriptionElementDaoHibernateImplTest
extends CdmTransactionalIntegrationTest
{
43 private static final Logger logger
= Logger
.getLogger(DescriptionElementDaoHibernateImplTest
.class);
46 IDescriptionElementDao descriptionElementDao
;
49 IDefinedTermDao termDao
;
52 private UUID uuidSingleTextData
= UUID
.fromString("31a0160a-51b2-4565-85cf-2be58cb561d6");
53 private UUID uuidDobuleTextData
= UUID
.fromString("50f6b799-3585-40a7-b69d-e7be77b2651a");
55 private boolean printDatasets
= false;
58 * @throws java.lang.Exception
61 public static void setUpBeforeClass() throws Exception
{
65 * @throws java.lang.Exception
68 public void setUp() throws Exception
{
71 // ***************************** TESTS ************************************/
76 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#countMedia(eu.etaxonomy.cdm.model.description.DescriptionElementBase)}.
79 public void testCountMedia() {
80 logger
.warn("Not yet implemented");
88 @DataSet // (value="DescriptionElementDaoHibernateImplTest.xml")
89 public void testRetrieveMultiLanguageString(){
90 // int count = descriptionElementDao.count(TextData.class);
91 // Assert.assertTrue("There must exist TextData", count > 0);
94 TextData textDataTwo
= (TextData
)descriptionElementDao
.findByUuid(uuidDobuleTextData
);
95 Assert
.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, textDataTwo
.size());
96 Assert
.assertTrue("One language should be English", textDataTwo
.containsKey(Language
.ENGLISH()));
97 Language eng
= Language
.ENGLISH();
98 // System.out.println("English: " + eng.getLabel() + "("+ eng.getId() + ", " + eng.getUuid() + ")");
100 // for (Language lang: multiLangText.keySet()){
101 // System.out.println(lang.getLabel() + "("+ lang.getId() + ", " + lang.getUuid() + ")");
102 // boolean equal = lang.equals(eng);
103 // System.out.println(equal);
105 // boolean contains = multiLangText.keySet().contains(eng);
106 // String et = doubleLanguageTextData.getText(eng);
107 LanguageString englishText
= textDataTwo
.getLanguageText(eng
);
108 Assert
.assertNotNull("English text should exist", englishText
);
109 Assert
.assertEquals("The English text should be correct", "Praesent vitae turpis vitae sapien sodales sagittis.", englishText
.getText());
110 LanguageString czechText
= textDataTwo
.getLanguageText(Language
.CZECH());
111 Assert
.assertNotNull("Czech", czechText
);
112 Assert
.assertEquals("The Czech text should be correct", "A Czech translation for Praesent ...", czechText
.getText());
119 @DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
121 public void testPersistMultiLanguageString(){
124 TextData singleLanguageTextData
= (TextData
)descriptionElementDao
.findByUuid(uuidSingleTextData
);
125 Map
<Language
, LanguageString
> multiLangText
= singleLanguageTextData
.getMultilanguageText();
126 Assert
.assertEquals("There should be exactly 1 languageText in the multilanguageText", 1, multiLangText
.size());
127 Assert
.assertTrue("The language should be English", multiLangText
.containsKey(Language
.ENGLISH()));
128 singleLanguageTextData
.putText(Language
.GERMAN(), "Ein test auf deutsch");
129 Assert
.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, singleLanguageTextData
.size());
130 String germanText
= singleLanguageTextData
.getText(Language
.GERMAN());
131 Assert
.assertNotNull("German text should exist", germanText
);
133 LanguageString germanLanguageText
= singleLanguageTextData
.getLanguageText(Language
.GERMAN());
134 Assert
.assertNotNull("German language text should exist", germanLanguageText
);
136 singleLanguageTextData
.putText(Language
.ENGLISH(), singleLanguageTextData
.getText(Language
.ENGLISH()));
137 descriptionElementDao
.saveOrUpdate(singleLanguageTextData
);
139 setComplete(); endTransaction();
140 try {if (printDatasets
){printDataSet(System
.out
, new String
[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
141 } catch(Exception e
) { logger
.warn(e
);}
148 @DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
150 public void testChangeLanguageString(){
153 TextData singleLanguageTextData
= (TextData
)descriptionElementDao
.findByUuid(uuidSingleTextData
);
154 Map
<Language
, LanguageString
> multiLangText
= singleLanguageTextData
.getMultilanguageText();
155 Assert
.assertEquals("There should be exactly 1 languageText in the multilanguageText", 1, multiLangText
.size());
156 Assert
.assertTrue("The language should be English", multiLangText
.containsKey(Language
.ENGLISH()));
158 singleLanguageTextData
.putText(Language
.ENGLISH(), "A new English text");
159 descriptionElementDao
.saveOrUpdate(singleLanguageTextData
);
161 setComplete(); endTransaction();
162 try {if (printDatasets
){printDataSet(System
.out
, new String
[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
163 } catch(Exception e
) { logger
.warn(e
);}
170 @DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
172 public void testRemoveLanguageString(){
175 TextData textDataTwo
= (TextData
)descriptionElementDao
.findByUuid(uuidDobuleTextData
);
176 Assert
.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, textDataTwo
.size());
178 Assert
.assertTrue("The language should be English", textDataTwo
.containsKey(Language
.ENGLISH()));
180 textDataTwo
.removeText(Language
.ENGLISH());
181 Assert
.assertEquals("There should be only 1 language left", 1, textDataTwo
.size());
182 descriptionElementDao
.saveOrUpdate(textDataTwo
);
184 setComplete(); endTransaction();
185 try {if (printDatasets
){printDataSet(System
.out
, new String
[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
186 } catch(Exception e
) { logger
.warn(e
);}
190 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#count(java.lang.Class, java.lang.String)}.
193 public void testCountClassOfQextendsDescriptionElementBaseString() {
194 logger
.warn("Not yet implemented");
198 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#getMedia(eu.etaxonomy.cdm.model.description.DescriptionElementBase, java.lang.Integer, java.lang.Integer, java.util.List)}.
201 public void testGetMedia() {
202 logger
.warn("Not yet implemented");
206 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#search(java.lang.Class, java.lang.String, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)}.
209 public void testSearch() {
210 logger
.warn("Not yet implemented");
214 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#purgeIndex()}.
217 public void testPurgeIndex() {
218 logger
.warn("Not yet implemented");
222 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#rebuildIndex()}.
225 public void testRebuildIndex() {
226 logger
.warn("Not yet implemented");
230 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#optimizeIndex()}.
233 public void testOptimizeIndex() {
234 logger
.warn("Not yet implemented");
238 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#count(java.lang.String)}.
241 public void testCountString() {
242 logger
.warn("Not yet implemented");
246 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#suggestQuery(java.lang.String)}.
249 public void testSuggestQuery() {
250 logger
.warn("Not yet implemented");
253 @Test //cascading for modifying text didn't work
254 @ExpectedDataSet(factory
=MultiSchemaXmlDataSetFactory
.class)
255 @Ignore //FIXME unitils3 upgrade problem: Differences found between the expected data set and actual database content.
256 public void testSaveCategoricalData(){
257 UUID uuidDummyState
= UUID
.fromString("881b9c80-626d-47a6-b308-a63ee5f4178f");
258 // State state = State.NewInstance("TestState", "TestState", "TestState");
259 // termDao.saveOrUpdate(state);
260 State state
= (State
)termDao
.findByUuid(uuidDummyState
);
261 CategoricalData data
= CategoricalData
.NewInstance();
262 data
.setUuid(UUID
.fromString("5c3f2340-f675-4d50-af96-89a2a12993b8"));
263 data
.setFeature(Feature
.DESCRIPTION());
264 StateData stateData
= StateData
.NewInstance(state
);
265 stateData
.setUuid(UUID
.fromString("04b9190d-d4ab-4c3a-8dec-8293dc820ddc"));
266 stateData
.putModifyingText(Language
.ENGLISH(), "test modifier");
267 LanguageString langString
= stateData
.getModifyingText().get(Language
.ENGLISH());
268 langString
.setUuid(UUID
.fromString("53a91bd4-d758-47ec-a385-94799bdb9f32"));
269 data
.addStateData(stateData
);
270 // Modifier modifier = Modifier.NewInstance("my test modifier", "test", null);
271 // TODO still throws JDBC batch update exception, one reason may be that in hibernate_sequence nextVal for definedtermbase is "1"
272 // stateData.addModifier(modifier);
274 descriptionElementDao
.save(data
);
276 // commitAndStartNewTransaction(new String[]{"Hibernate_sequences","DescriptionElementBase","DescriptionElementBase_StateData","StateData_DefinedTermBase", "StateData", "StateData_LanguageString", "LanguageString"});