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