1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
|
11
|
|
12
|
import java.util.Map;
|
13
|
import java.util.UUID;
|
14
|
|
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.Test;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
22
|
import org.unitils.spring.annotation.SpringBeanByType;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
26
|
import eu.etaxonomy.cdm.model.description.TextData;
|
27
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionElementDao;
|
28
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
29
|
|
30
|
/**
|
31
|
* @author a.mueller
|
32
|
* @date 25.11.2010
|
33
|
*
|
34
|
*/
|
35
|
public class DescriptionElementDaoHibernateImplTest extends CdmTransactionalIntegrationTest{
|
36
|
private static final Logger logger = Logger.getLogger(DescriptionElementDaoHibernateImplTest.class);
|
37
|
|
38
|
@SpringBeanByType
|
39
|
IDescriptionElementDao descriptionElementDao;
|
40
|
|
41
|
private UUID uuidSingleTextData = UUID.fromString("31a0160a-51b2-4565-85cf-2be58cb561d6");
|
42
|
private UUID uuidDobuleTextData = UUID.fromString("50f6b799-3585-40a7-b69d-e7be77b2651a");
|
43
|
|
44
|
private boolean printDatasets = false;
|
45
|
|
46
|
/**
|
47
|
* @throws java.lang.Exception
|
48
|
*/
|
49
|
@BeforeClass
|
50
|
public static void setUpBeforeClass() throws Exception {
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* @throws java.lang.Exception
|
55
|
*/
|
56
|
@Before
|
57
|
public void setUp() throws Exception {
|
58
|
}
|
59
|
|
60
|
// ***************************** TESTS ************************************/
|
61
|
|
62
|
|
63
|
|
64
|
/**
|
65
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#countMedia(eu.etaxonomy.cdm.model.description.DescriptionElementBase)}.
|
66
|
*/
|
67
|
@Test
|
68
|
public void testCountMedia() {
|
69
|
logger.warn("Not yet implemented");
|
70
|
}
|
71
|
|
72
|
|
73
|
/**
|
74
|
* See #2114
|
75
|
*/
|
76
|
@Test
|
77
|
@DataSet // (value="DescriptionElementDaoHibernateImplTest.xml")
|
78
|
public void testRetrieveMultiLanguageString(){
|
79
|
// int count = descriptionElementDao.count(TextData.class);
|
80
|
// Assert.assertTrue("There must exist TextData", count > 0);
|
81
|
|
82
|
//test read
|
83
|
TextData textDataTwo = (TextData)descriptionElementDao.findByUuid(uuidDobuleTextData);
|
84
|
Assert.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, textDataTwo.size());
|
85
|
Assert.assertTrue("One language should be English", textDataTwo.containsKey(Language.ENGLISH()));
|
86
|
Language eng = Language.ENGLISH();
|
87
|
// System.out.println("English: " + eng.getLabel() + "("+ eng.getId() + ", " + eng.getUuid() + ")");
|
88
|
//
|
89
|
// for (Language lang: multiLangText.keySet()){
|
90
|
// System.out.println(lang.getLabel() + "("+ lang.getId() + ", " + lang.getUuid() + ")");
|
91
|
// boolean equal = lang.equals(eng);
|
92
|
// System.out.println(equal);
|
93
|
// }
|
94
|
// boolean contains = multiLangText.keySet().contains(eng);
|
95
|
// String et = doubleLanguageTextData.getText(eng);
|
96
|
LanguageString englishText = textDataTwo.getLanguageText(eng);
|
97
|
Assert.assertNotNull("English text should exist", englishText);
|
98
|
Assert.assertEquals("The English text should be correct", "Praesent vitae turpis vitae sapien sodales sagittis.", englishText.getText());
|
99
|
LanguageString czechText = textDataTwo.getLanguageText(Language.CZECH());
|
100
|
Assert.assertNotNull("Czech", czechText);
|
101
|
Assert.assertEquals("The Czech text should be correct", "A Czech translation for Praesent ...", czechText.getText());
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* See #2114
|
106
|
*/
|
107
|
@Test
|
108
|
@DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
|
109
|
@ExpectedDataSet
|
110
|
public void testPersistMultiLanguageString(){
|
111
|
|
112
|
//test write
|
113
|
TextData singleLanguageTextData = (TextData)descriptionElementDao.findByUuid(uuidSingleTextData);
|
114
|
Map<Language, LanguageString> multiLangText = singleLanguageTextData.getMultilanguageText();
|
115
|
Assert.assertEquals("There should be exactly 1 languageText in the multilanguageText", 1, multiLangText.size());
|
116
|
Assert.assertTrue("The language should be English", multiLangText.containsKey(Language.ENGLISH()));
|
117
|
singleLanguageTextData.putText(Language.GERMAN(), "Ein test auf deutsch");
|
118
|
Assert.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, singleLanguageTextData.size());
|
119
|
String germanText = singleLanguageTextData.getText(Language.GERMAN());
|
120
|
Assert.assertNotNull("German text should exist", germanText);
|
121
|
|
122
|
LanguageString germanLanguageText = singleLanguageTextData.getLanguageText(Language.GERMAN());
|
123
|
Assert.assertNotNull("German language text should exist", germanLanguageText);
|
124
|
|
125
|
singleLanguageTextData.putText(Language.ENGLISH(), singleLanguageTextData.getText(Language.ENGLISH()));
|
126
|
descriptionElementDao.saveOrUpdate(singleLanguageTextData);
|
127
|
|
128
|
setComplete(); endTransaction();
|
129
|
try {if (printDatasets){printDataSet(System.out, new String[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
|
130
|
} catch(Exception e) { logger.warn(e);}
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* See #2114
|
135
|
*/
|
136
|
@Test
|
137
|
@DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
|
138
|
@ExpectedDataSet
|
139
|
public void testChangeLanguageString(){
|
140
|
|
141
|
//test write
|
142
|
TextData singleLanguageTextData = (TextData)descriptionElementDao.findByUuid(uuidSingleTextData);
|
143
|
Map<Language, LanguageString> multiLangText = singleLanguageTextData.getMultilanguageText();
|
144
|
Assert.assertEquals("There should be exactly 1 languageText in the multilanguageText", 1, multiLangText.size());
|
145
|
Assert.assertTrue("The language should be English", multiLangText.containsKey(Language.ENGLISH()));
|
146
|
|
147
|
singleLanguageTextData.putText(Language.ENGLISH(), "A new English text");
|
148
|
descriptionElementDao.saveOrUpdate(singleLanguageTextData);
|
149
|
|
150
|
setComplete(); endTransaction();
|
151
|
try {if (printDatasets){printDataSet(System.out, new String[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
|
152
|
} catch(Exception e) { logger.warn(e);}
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* See #2114
|
157
|
*/
|
158
|
@Test
|
159
|
@DataSet //(value="DescriptionElementDaoHibernateImplTest.xml")
|
160
|
@ExpectedDataSet
|
161
|
public void testRemoveLanguageString(){
|
162
|
|
163
|
//test write
|
164
|
TextData textDataTwo = (TextData)descriptionElementDao.findByUuid(uuidDobuleTextData);
|
165
|
Assert.assertEquals("There should be exactly 2 languageText in the multilanguageText", 2, textDataTwo.size());
|
166
|
|
167
|
Assert.assertTrue("The language should be English", textDataTwo.containsKey(Language.ENGLISH()));
|
168
|
|
169
|
textDataTwo.removeText(Language.ENGLISH());
|
170
|
Assert.assertEquals("There should be only 1 language left", 1, textDataTwo.size());
|
171
|
descriptionElementDao.saveOrUpdate(textDataTwo);
|
172
|
|
173
|
setComplete(); endTransaction();
|
174
|
try {if (printDatasets){printDataSet(System.out, new String[]{"LanguageString", "DescriptionElementBase", "DESCRIPTIONELEMENTBASE_LANGUAGESTRING"});}
|
175
|
} catch(Exception e) { logger.warn(e);}
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#count(java.lang.Class, java.lang.String)}.
|
180
|
*/
|
181
|
@Test
|
182
|
public void testCountClassOfQextendsDescriptionElementBaseString() {
|
183
|
logger.warn("Not yet implemented");
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* 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)}.
|
188
|
*/
|
189
|
@Test
|
190
|
public void testGetMedia() {
|
191
|
logger.warn("Not yet implemented");
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* 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)}.
|
196
|
*/
|
197
|
@Test
|
198
|
public void testSearch() {
|
199
|
logger.warn("Not yet implemented");
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#purgeIndex()}.
|
204
|
*/
|
205
|
@Test
|
206
|
public void testPurgeIndex() {
|
207
|
logger.warn("Not yet implemented");
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#rebuildIndex()}.
|
212
|
*/
|
213
|
@Test
|
214
|
public void testRebuildIndex() {
|
215
|
logger.warn("Not yet implemented");
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#optimizeIndex()}.
|
220
|
*/
|
221
|
@Test
|
222
|
public void testOptimizeIndex() {
|
223
|
logger.warn("Not yet implemented");
|
224
|
}
|
225
|
|
226
|
/**
|
227
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#count(java.lang.String)}.
|
228
|
*/
|
229
|
@Test
|
230
|
public void testCountString() {
|
231
|
logger.warn("Not yet implemented");
|
232
|
}
|
233
|
|
234
|
/**
|
235
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.description.DescriptionElementDaoImpl#suggestQuery(java.lang.String)}.
|
236
|
*/
|
237
|
@Test
|
238
|
public void testSuggestQuery() {
|
239
|
logger.warn("Not yet implemented");
|
240
|
}
|
241
|
|
242
|
}
|