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.hibernate;
|
11
|
|
12
|
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.util.List;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
import org.unitils.dbunit.annotation.DataSet;
|
24
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
25
|
import org.unitils.spring.annotation.SpringBeanByType;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
28
|
import eu.etaxonomy.cdm.model.agent.Person;
|
29
|
import eu.etaxonomy.cdm.model.agent.Team;
|
30
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
31
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
32
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
33
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
36
|
import eu.etaxonomy.cdm.model.reference.IArticle;
|
37
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
38
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
39
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
40
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
41
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
42
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
43
|
import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
|
44
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
45
|
import eu.etaxonomy.cdm.persistence.dao.molecular.IAmplificationDao;
|
46
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
47
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
48
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
49
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
50
|
|
51
|
/**
|
52
|
* @author a.mueller
|
53
|
* @created 18.03.2009
|
54
|
*/
|
55
|
public class CacheStrategyGeneratorTest extends CdmTransactionalIntegrationTest {
|
56
|
private static Logger logger = Logger.getLogger(CacheStrategyGeneratorTest.class);
|
57
|
|
58
|
private TaxonBase<?> cdmBase;
|
59
|
|
60
|
@SpringBeanByType
|
61
|
private ITaxonNameDao cdmEntityDaoBase;
|
62
|
|
63
|
@SpringBeanByType
|
64
|
private IAgentDao agentDao;
|
65
|
|
66
|
@SpringBeanByType
|
67
|
private IReferenceDao referenceDao;
|
68
|
|
69
|
@SpringBeanByType
|
70
|
private IAmplificationDao amplificationDao;
|
71
|
|
72
|
@SpringBeanByType
|
73
|
private IDefinedTermDao termDao;
|
74
|
|
75
|
|
76
|
/**
|
77
|
* @throws java.lang.Exception
|
78
|
*/
|
79
|
@Before
|
80
|
public void setUp() throws Exception {
|
81
|
cdmBase = Taxon.NewInstance(null, null);
|
82
|
cdmBase.setUuid(UUID.fromString("e463b270-c76b-11dd-ad8b-0800200c9a66"));
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
|
87
|
* @throws Exception
|
88
|
*/
|
89
|
@Test
|
90
|
public void testDaos() throws Exception {
|
91
|
assertNotNull("cdmEntityDaoBase should exist",cdmEntityDaoBase);
|
92
|
assertNotNull("agentDao should exist",agentDao);
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
97
|
*/
|
98
|
@Test
|
99
|
@DataSet("CacheStrategyGeneratorTest.xml")
|
100
|
@ExpectedDataSet
|
101
|
public void testOnSaveOrUpdateNames() {
|
102
|
//names
|
103
|
BotanicalName name = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("a49a3963-c4ea-4047-8588-2f8f15352730"));
|
104
|
name.setTitleCache(null, false);
|
105
|
name.setNameCache(null, false);
|
106
|
name.setGenusOrUninomial("Abies");
|
107
|
name.setAuthorshipCache("Mill.", true);
|
108
|
cdmEntityDaoBase.saveOrUpdate(name);
|
109
|
BotanicalName name2 = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("05a438d6-065f-49ef-84db-c7dc2c259975"));
|
110
|
name2.setProtectedFullTitleCache(false);
|
111
|
name2.setProtectedTitleCache(false);
|
112
|
name2.setProtectedNameCache(false);
|
113
|
name2.setGenusOrUninomial("Abies");
|
114
|
name2.setSpecificEpithet("alba");
|
115
|
name2.setAuthorshipCache("Mill.", true);
|
116
|
IBook ref = ReferenceFactory.newBook();
|
117
|
ref.setTitle("My Book");
|
118
|
name2.setNomenclaturalReference(ref);
|
119
|
name2.setNomenclaturalMicroReference("44");
|
120
|
|
121
|
cdmEntityDaoBase.saveOrUpdate(name2);
|
122
|
|
123
|
Assert.assertEquals(name, cdmEntityDaoBase.findByUuid(name.getUuid()));
|
124
|
BotanicalName nameTest = (BotanicalName)cdmEntityDaoBase.findByUuid(name.getUuid());
|
125
|
|
126
|
Assert.assertEquals(name2, cdmEntityDaoBase.findByUuid(name2.getUuid()));
|
127
|
logger.debug("FulltitleCache: "+ cdmEntityDaoBase.findByUuid(name2.getUuid()).getFullTitleCache());
|
128
|
logger.debug("updated: " + cdmEntityDaoBase.findByUuid(name2.getUuid()).getUpdated());
|
129
|
BotanicalName name3 = BotanicalName.NewInstance(Rank.GENUS());
|
130
|
name3.setFullTitleCache("Test: MyBook");
|
131
|
name3.setTitleCache("Test", true);
|
132
|
cdmEntityDaoBase.saveOrUpdate(name3);
|
133
|
List<TaxonNameBase> taxa = cdmEntityDaoBase.findByTitle("Test");
|
134
|
|
135
|
TaxonNameBase<?,?> nameBase = taxa.get (0);
|
136
|
BotanicalName botName = (BotanicalName)nameBase;
|
137
|
|
138
|
logger.debug("created "+botName.getCreated());
|
139
|
logger.debug("updated: " +botName.getUpdated());
|
140
|
// BotanicalName name3 = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("049a3963-c4ea-4047-8588-2f8f15352730"));
|
141
|
// printDataSet(System.err, new String[]{"TaxonNameBase", "Reference"});
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
146
|
*/
|
147
|
@Test
|
148
|
@DataSet("CacheStrategyGeneratorTest.xml")
|
149
|
@ExpectedDataSet
|
150
|
public void testOnSaveOrUpdateAgents() {
|
151
|
|
152
|
//person
|
153
|
Person person1;
|
154
|
Person person2;
|
155
|
Person person3;
|
156
|
|
157
|
person1 = makePerson1();
|
158
|
|
159
|
person2 = makePerson2();
|
160
|
|
161
|
person3 = Person.NewInstance(); //empty person
|
162
|
person3.setUuid(UUID.fromString("4c4e15e3-3a4f-4505-900a-fae2555ac9e4"));
|
163
|
|
164
|
// System.out.println(person1.getTitleCache());
|
165
|
// System.out.println(person1.getNomenclaturalTitle());
|
166
|
// System.out.println(person2.getTitleCache());
|
167
|
// System.out.println(person2.getNomenclaturalTitle());
|
168
|
// System.out.println(person3.getTitleCache());
|
169
|
// System.out.println(person3.getNomenclaturalTitle());
|
170
|
|
171
|
agentDao.saveOrUpdate(person1);
|
172
|
agentDao.saveOrUpdate(person2);
|
173
|
agentDao.saveOrUpdate(person3);
|
174
|
|
175
|
//Teams
|
176
|
Team team1 = Team.NewInstance();
|
177
|
team1.addTeamMember(person1);
|
178
|
team1.setUuid(UUID.fromString("db957a0a-1494-49bb-8d17-d3eaa2076573"));
|
179
|
agentDao.saveOrUpdate(team1);
|
180
|
|
181
|
Person person4 = (Person)agentDao.findByUuid(UUID.fromString("4c4e15e3-3a4f-4505-900a-fae2555ac9e4"));
|
182
|
Assert.assertEquals(person3, person4);
|
183
|
Team team2 = (Team) agentDao.findByUuid(UUID.fromString("db957a0a-1494-49bb-8d17-d3eaa2076573"));
|
184
|
Assert.assertEquals(team1, team2);
|
185
|
}
|
186
|
|
187
|
|
188
|
|
189
|
private Person makePerson1() {
|
190
|
Person person1;
|
191
|
person1 = Person.NewInstance();
|
192
|
|
193
|
person1.setUuid(UUID.fromString("646dad4b-0f0e-4f5a-b059-8099ad9a6125"));
|
194
|
person1.setFirstname("P1FN");
|
195
|
person1.setLastname("P1LN");
|
196
|
person1.setPrefix("Dr1.");
|
197
|
person1.setSuffix("Suff1");
|
198
|
return person1;
|
199
|
}
|
200
|
|
201
|
private Person makePerson2() {
|
202
|
Person person2;
|
203
|
person2 = Person.NewInstance();
|
204
|
person2.setUuid(UUID.fromString("ca904533-2a70-49f3-9a0e-5e4bcc12c154"));
|
205
|
person2.setNomenclaturalTitle("P2NomT");
|
206
|
person2.setLastname("P2LN");
|
207
|
person2.setFirstname("P2FN");
|
208
|
person2.setSuffix("P2Suff");
|
209
|
return person2;
|
210
|
}
|
211
|
|
212
|
/**
|
213
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
214
|
*/
|
215
|
@Test
|
216
|
@DataSet("CacheStrategyGeneratorTest.xml")
|
217
|
@ExpectedDataSet
|
218
|
//TODO correct abbrevTitleCache for article still unclear (open question: with or without article title ?)
|
219
|
public void testOnSaveOrUpdateReferences() {
|
220
|
//References
|
221
|
IJournal journal1 = ReferenceFactory.newJournal();
|
222
|
Person journalAuthor = makePerson1();
|
223
|
|
224
|
journal1.setTitle("My journal");
|
225
|
journal1.setUuid(UUID.fromString("a7fdf3b8-acd8-410a-afcd-1768d29d67e9"));
|
226
|
journal1.setAbbrevTitle("M. Journ.");
|
227
|
journal1.setAuthorship(journalAuthor);
|
228
|
|
229
|
referenceDao.save((Reference)journal1);
|
230
|
|
231
|
Person articleAuthor = makePerson2();
|
232
|
IArticle article1 = ReferenceFactory.newArticle();
|
233
|
article1.setUuid(UUID.fromString("eb090fbc-5895-405c-aba5-cac287efb128"));
|
234
|
article1.setAbbrevTitle("M. Art.");
|
235
|
article1.setVolume("1");
|
236
|
article1.setDatePublished(TimePeriod.NewInstance(1972));
|
237
|
article1.setInJournal(journal1);
|
238
|
article1.setAuthorship(articleAuthor);
|
239
|
article1.getAbbrevTitleCache();
|
240
|
|
241
|
referenceDao.saveOrUpdate((Reference)article1);
|
242
|
|
243
|
commit();
|
244
|
}
|
245
|
|
246
|
@Test
|
247
|
// @DataSet("CacheStrategyGeneratorTest.xml")
|
248
|
// @ExpectedDataSet
|
249
|
public void testOnSaveOrUpdateAmplification() {
|
250
|
Amplification amplification = Amplification.NewInstance();
|
251
|
UUID amplUuid = UUID.fromString("11e6b2d5-3eb5-4434-9c56-5bb4c1102147");
|
252
|
amplification.setUuid(amplUuid);
|
253
|
|
254
|
amplificationDao.save(amplification);
|
255
|
Assert.assertEquals("<Amplification:11e6b2d5-3eb5-4434-9c56-5bb4c1102147>", amplification.getLabelCache());
|
256
|
|
257
|
Person author = Person.NewTitledInstance("Person");
|
258
|
Institution institution = Institution.NewInstance();
|
259
|
institution.setName("My institute");
|
260
|
DefinedTerm marker = DefinedTerm.NewDnaMarkerInstance("marker", "marker", "dm");
|
261
|
|
262
|
amplification.setActor(author);
|
263
|
amplification.setTimeperiod(TimePeriodParser.parseString("2008"));
|
264
|
amplification.setDnaMarker(marker);
|
265
|
amplification.setInstitution(institution);
|
266
|
|
267
|
|
268
|
termDao.save(marker);
|
269
|
amplificationDao.saveOrUpdate(amplification);
|
270
|
Assert.assertEquals("My institute_Person_marker_2008", amplification.getLabelCache());
|
271
|
}
|
272
|
|
273
|
/* (non-Javadoc)
|
274
|
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
|
275
|
*/
|
276
|
@Override
|
277
|
public void createTestDataSet() throws FileNotFoundException {
|
278
|
// TODO Auto-generated method stub
|
279
|
}
|
280
|
}
|
281
|
|