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.IOException;
|
16
|
import java.sql.SQLException;
|
17
|
import java.util.List;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.dbunit.dataset.DataSetException;
|
22
|
import org.dbunit.dataset.IDataSet;
|
23
|
import org.dbunit.dataset.xml.FlatXmlDataSet;
|
24
|
import org.junit.Assert;
|
25
|
import org.junit.Before;
|
26
|
import org.junit.Ignore;
|
27
|
import org.junit.Test;
|
28
|
import org.unitils.dbunit.annotation.DataSet;
|
29
|
import org.unitils.dbunit.annotation.ExpectedDataSet;
|
30
|
import org.unitils.spring.annotation.SpringBeanByType;
|
31
|
|
32
|
import eu.etaxonomy.cdm.model.agent.Person;
|
33
|
import eu.etaxonomy.cdm.model.agent.Team;
|
34
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
35
|
import eu.etaxonomy.cdm.model.name.Rank;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
37
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
38
|
import eu.etaxonomy.cdm.model.reference.IGeneric;
|
39
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
40
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
41
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
42
|
import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
|
43
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
44
|
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
|
45
|
|
46
|
/**
|
47
|
* @author a.mueller
|
48
|
* @created 18.03.2009
|
49
|
* @version 1.0
|
50
|
*/
|
51
|
public class CacheStrategyGeneratorTest extends CdmIntegrationTest {
|
52
|
@SuppressWarnings("unused")
|
53
|
private static Logger logger = Logger.getLogger(CacheStrategyGeneratorTest.class);
|
54
|
|
55
|
private UUID uuid;
|
56
|
private TaxonBase cdmBase;
|
57
|
|
58
|
@SpringBeanByType
|
59
|
private ITaxonNameDao cdmEntityDaoBase;
|
60
|
|
61
|
@SpringBeanByType
|
62
|
private IAgentDao agentDao;
|
63
|
|
64
|
/**
|
65
|
* @throws java.lang.Exception
|
66
|
*/
|
67
|
@Before
|
68
|
public void setUp() throws Exception {
|
69
|
uuid = UUID.fromString("8d77c380-c76a-11dd-ad8b-0800200c9a66");
|
70
|
cdmBase = Taxon.NewInstance(null, null);
|
71
|
cdmBase.setUuid(UUID.fromString("e463b270-c76b-11dd-ad8b-0800200c9a66"));
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
|
76
|
* @throws Exception
|
77
|
*/
|
78
|
@Test
|
79
|
public void testDaos() throws Exception {
|
80
|
assertNotNull("cdmEntityDaoBase should exist",cdmEntityDaoBase);
|
81
|
assertNotNull("agentDao should exist",agentDao);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
86
|
*/
|
87
|
@Test
|
88
|
@DataSet("CacheStrategyGeneratorTest.xml")
|
89
|
//@ExpectedDataSet
|
90
|
public void testOnSaveOrUpdateNames() {
|
91
|
//names
|
92
|
BotanicalName name = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("a49a3963-c4ea-4047-8588-2f8f15352730"));
|
93
|
name.setTitleCache(null, false);
|
94
|
name.setNameCache(null, false);
|
95
|
name.setGenusOrUninomial("Abies");
|
96
|
name.setAuthorshipCache("Mill.", true);
|
97
|
cdmEntityDaoBase.saveOrUpdate(name);
|
98
|
BotanicalName name2 = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("05a438d6-065f-49ef-84db-c7dc2c259975"));
|
99
|
name2.setProtectedFullTitleCache(false);
|
100
|
name2.setProtectedTitleCache(false);
|
101
|
name2.setProtectedNameCache(false);
|
102
|
name2.setGenusOrUninomial("Abies");
|
103
|
name2.setSpecificEpithet("alba");
|
104
|
name2.setAuthorshipCache("Mill.", true);
|
105
|
ReferenceFactory refFactory = ReferenceFactory.newInstance();
|
106
|
IBook ref = refFactory.newBook();
|
107
|
ref.setTitle("My Book");
|
108
|
name2.setNomenclaturalReference(ref);
|
109
|
name2.setNomenclaturalMicroReference("44");
|
110
|
|
111
|
cdmEntityDaoBase.saveOrUpdate(name2);
|
112
|
|
113
|
Assert.assertEquals(name, cdmEntityDaoBase.findByUuid(name.getUuid()));
|
114
|
BotanicalName nameTest = (BotanicalName)cdmEntityDaoBase.findByUuid(name.getUuid());
|
115
|
|
116
|
Assert.assertEquals(name2, cdmEntityDaoBase.findByUuid(name2.getUuid()));
|
117
|
logger.debug("FulltitleCache: "+ cdmEntityDaoBase.findByUuid(name2.getUuid()).getFullTitleCache());
|
118
|
logger.debug("updated: " + cdmEntityDaoBase.findByUuid(name2.getUuid()).getUpdated());
|
119
|
BotanicalName name3 = BotanicalName.NewInstance(Rank.GENUS());
|
120
|
name3.setFullTitleCache("Test: MyBook");
|
121
|
name3.setTitleCache("Test", true);
|
122
|
cdmEntityDaoBase.saveOrUpdate(name3);
|
123
|
List<TaxonNameBase> taxa = cdmEntityDaoBase.findByTitle("Test");
|
124
|
|
125
|
TaxonNameBase nameBase = taxa.get (0);
|
126
|
BotanicalName botName = (BotanicalName)nameBase;
|
127
|
|
128
|
logger.debug("created "+botName.getCreated());
|
129
|
logger.debug("updated: " +botName.getUpdated());
|
130
|
// BotanicalName name3 = (BotanicalName)cdmEntityDaoBase.findByUuid(UUID.fromString("049a3963-c4ea-4047-8588-2f8f15352730"));
|
131
|
// printDataSet(System.err, new String[]{"TaxonNameBase", "ReferenceBase"});
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
|
136
|
*/
|
137
|
@Test
|
138
|
@DataSet("CacheStrategyGeneratorTest.xml")
|
139
|
//@ExpectedDataSet
|
140
|
public void testOnSaveOrUpdateAgents() {
|
141
|
|
142
|
// 646dad4b-0f0e-4f5a-b059-8099ad9a6125
|
143
|
// ca904533-2a70-49f3-9a0e-5e4bcc12c154
|
144
|
// 4c4e15e3-3a4f-4505-900a-fae2555ac9e4
|
145
|
|
146
|
//person
|
147
|
Person person1;
|
148
|
Person person2;
|
149
|
Person person3;person1 = Person.NewInstance();
|
150
|
|
151
|
person1.setUuid(UUID.fromString("646dad4b-0f0e-4f5a-b059-8099ad9a6125"));
|
152
|
person1.setFirstname("P1FN");
|
153
|
person1.setLastname("P1LN");
|
154
|
person1.setPrefix("Dr1.");
|
155
|
person1.setSuffix("Suff1");
|
156
|
|
157
|
person2 = Person.NewInstance();
|
158
|
person2.setUuid(UUID.fromString("ca904533-2a70-49f3-9a0e-5e4bcc12c154"));
|
159
|
person2.setNomenclaturalTitle("P2NomT");
|
160
|
person2.setLastname("P2LN");
|
161
|
person2.setFirstname("P2FN");
|
162
|
person2.setSuffix("P2Suff");
|
163
|
|
164
|
person3 = Person.NewInstance(); //empty person
|
165
|
person3.setUuid(UUID.fromString("4c4e15e3-3a4f-4505-900a-fae2555ac9e4"));
|
166
|
|
167
|
// System.out.println(person1.getTitleCache());
|
168
|
// System.out.println(person1.getNomenclaturalTitle());
|
169
|
// System.out.println(person2.getTitleCache());
|
170
|
// System.out.println(person2.getNomenclaturalTitle());
|
171
|
// System.out.println(person3.getTitleCache());
|
172
|
// System.out.println(person3.getNomenclaturalTitle());
|
173
|
|
174
|
agentDao.saveOrUpdate(person1);
|
175
|
agentDao.saveOrUpdate(person2);
|
176
|
agentDao.saveOrUpdate(person3);
|
177
|
|
178
|
//Teams
|
179
|
Team team1 = Team.NewInstance();
|
180
|
team1.addTeamMember(person1);
|
181
|
team1.setUuid(UUID.fromString("db957a0a-1494-49bb-8d17-d3eaa2076573"));
|
182
|
agentDao.saveOrUpdate(team1);
|
183
|
|
184
|
Person person4 = (Person)agentDao.findByUuid(UUID.fromString("4c4e15e3-3a4f-4505-900a-fae2555ac9e4"));
|
185
|
Assert.assertEquals(person3, person4);
|
186
|
Team team2 = (Team) agentDao.findByUuid(UUID.fromString("db957a0a-1494-49bb-8d17-d3eaa2076573"));
|
187
|
Assert.assertEquals(team1, team2);
|
188
|
|
189
|
}
|
190
|
|
191
|
}
|
192
|
|
193
|
|