1
|
/**
|
2
|
* Copyright (C) 2014 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.taxeditor.lazyloading;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Level;
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.Assert;
|
22
|
import org.junit.BeforeClass;
|
23
|
import org.junit.Ignore;
|
24
|
import org.junit.Test;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
28
|
import eu.etaxonomy.cdm.model.agent.Person;
|
29
|
import eu.etaxonomy.cdm.model.agent.Team;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
32
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
33
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
34
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
35
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
37
|
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
|
38
|
|
39
|
|
40
|
|
41
|
/**
|
42
|
* Test class which tests remoting for persistent cdm entities.
|
43
|
*
|
44
|
* FIXME:Remoting saving tests are ignored until the merge development is underway
|
45
|
* @author c.mathew
|
46
|
*
|
47
|
*/
|
48
|
//FIXME:Remoting need to create a proper dataset for this test
|
49
|
//Could be combined with AbstractLazyInitializerTest
|
50
|
@Ignore
|
51
|
public class RemoteLazyLoadingTest extends BaseRemotingTest {
|
52
|
|
53
|
private static final Logger logger = Logger.getLogger(RemoteLazyLoadingTest.class);
|
54
|
|
55
|
private static IClassificationService classificationService;
|
56
|
private static ITaxonService taxonService;
|
57
|
|
58
|
private static List<TaxonNode> taxonNodes;
|
59
|
|
60
|
private final UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
|
61
|
private final UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
|
62
|
|
63
|
|
64
|
@BeforeClass
|
65
|
public static void initializeRemoteLazyLoading() {
|
66
|
|
67
|
Logger.getRootLogger().setLevel(Level.DEBUG);
|
68
|
taxonService = getRemoteApplicationController().getTaxonService();
|
69
|
|
70
|
classificationService= getRemoteApplicationController().getClassificationService();
|
71
|
//List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
|
72
|
// Assert.assertFalse(classifications.isEmpty());
|
73
|
//
|
74
|
// Classification classification = classifications.get(0);
|
75
|
// Assert.assertNotNull(classification);
|
76
|
taxonNodes = classificationService.getAllNodes();
|
77
|
Assert.assertFalse(taxonNodes.isEmpty());
|
78
|
|
79
|
}
|
80
|
|
81
|
|
82
|
|
83
|
@Test
|
84
|
public void testCDMEntityGet() {
|
85
|
Iterator<TaxonNode> taxonNodeItr = taxonNodes.iterator();
|
86
|
int maxcount = 30;
|
87
|
int count = 0;
|
88
|
while(taxonNodeItr.hasNext() && count <= maxcount) {
|
89
|
TaxonNode taxonNode = taxonNodeItr.next();
|
90
|
Assert.assertNotNull(taxonNode);
|
91
|
|
92
|
Taxon taxon = taxonNode.getTaxon();
|
93
|
Assert.assertNotNull(taxon);
|
94
|
|
95
|
String taxonTitle = taxon.getTitleCache();
|
96
|
logger.info("Taxon : " + taxonTitle);
|
97
|
|
98
|
TaxonNameBase name = taxon.getName();
|
99
|
Assert.assertNotNull(name);
|
100
|
|
101
|
String nameTitle = name.getTitleCache();
|
102
|
logger.info("Taxon Name : " + nameTitle);
|
103
|
|
104
|
count++;
|
105
|
}
|
106
|
|
107
|
|
108
|
}
|
109
|
|
110
|
@Test
|
111
|
public void test() {
|
112
|
|
113
|
}
|
114
|
|
115
|
@Test
|
116
|
public void testCDMEntitySaveEager() {
|
117
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
118
|
String oldTitleCache = taxon.getTitleCache();
|
119
|
|
120
|
System.out.println("Taxon title : " + oldTitleCache);
|
121
|
|
122
|
taxon.setTitleCache(oldTitleCache + ":updated");
|
123
|
taxonService.merge(taxon);
|
124
|
|
125
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
126
|
System.out.println("New Taxon Title : " + taxonNew.getTitleCache());
|
127
|
|
128
|
Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(taxonNew.getTitleCache()));
|
129
|
|
130
|
taxonNew.setTitleCache(oldTitleCache);
|
131
|
taxonService.merge(taxonNew);
|
132
|
|
133
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
134
|
System.out.println("Old Taxon Title : " + taxonOld.getTitleCache());
|
135
|
|
136
|
Assert.assertEquals("Title caches should be equal",oldTitleCache,taxonOld.getTitleCache());
|
137
|
|
138
|
}
|
139
|
|
140
|
|
141
|
@Test
|
142
|
public void testCDMEntityUpdate() {
|
143
|
|
144
|
Team combAuthor = Team.NewInstance();
|
145
|
combAuthor.addTeamMember(Person.NewTitledInstance("test member"));
|
146
|
BotanicalName name = BotanicalName.NewInstance(null, "Test1", null, null, null, null, null, null, null);
|
147
|
name.setCombinationAuthorTeam(combAuthor);
|
148
|
Taxon taxon = Taxon.NewInstance(name, null);
|
149
|
UUID taxonUuid = taxonService.save(taxon);
|
150
|
|
151
|
// Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
152
|
// NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
153
|
// String oldTitleCache = nvn.getTitleCache();
|
154
|
// System.out.println("Taxon Name Title : " + oldTitleCache);
|
155
|
// nvn.setTitleCache(oldTitleCache + ":updated", true);
|
156
|
//
|
157
|
// taxon.setTitleCache(oldTitleCache + ":updated",true);
|
158
|
// try {
|
159
|
// taxonService.update(taxon);
|
160
|
// } catch (LazyInitializationException lie) {
|
161
|
// lie.printStackTrace();
|
162
|
// }
|
163
|
|
164
|
List<String> TAXON_INIT_STRATEGY = Arrays.asList(new String[] {
|
165
|
"name"
|
166
|
});
|
167
|
Taxon taxonNew = (Taxon)taxonService.findTaxonByUuid(taxonUuid,TAXON_INIT_STRATEGY);
|
168
|
NonViralName nvn = CdmBase.deproxy(taxonNew.getName(),NonViralName.class);
|
169
|
Team team = CdmBase.deproxy(nvn.getCombinationAuthorTeam(),Team.class);
|
170
|
String oldTitleCache = nvn.getTitleCache();
|
171
|
System.out.println("Taxon Name Title : " + oldTitleCache);
|
172
|
nvn.setTitleCache(oldTitleCache + ":updated", true);
|
173
|
taxonService.update(taxonNew);
|
174
|
|
175
|
}
|
176
|
|
177
|
|
178
|
@Test
|
179
|
public void testCDMEntitySaveLazy() {
|
180
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
181
|
|
182
|
NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
183
|
String oldTitleCache = nvn.getTitleCache();
|
184
|
System.out.println("Taxon Name Title : " + oldTitleCache);
|
185
|
nvn.setTitleCache(oldTitleCache + ":updated", true);
|
186
|
taxonService.update(taxon);
|
187
|
|
188
|
// Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
189
|
// NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
190
|
// System.out.println("New Taxon Name Title : " + nvnNew.getTitleCache());
|
191
|
//
|
192
|
// Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,nvnNew.getTitleCache());
|
193
|
//
|
194
|
// nvnNew.setTitleCache(oldTitleCache, true);
|
195
|
// taxonService.update(taxon);
|
196
|
//
|
197
|
// Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
198
|
// NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
199
|
// System.out.println("Old Taxon Name Title : " + nvnNew.getTitleCache());
|
200
|
//
|
201
|
// Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache());
|
202
|
}
|
203
|
|
204
|
@Test
|
205
|
public void testCDMEntitySaveLazyNew() {
|
206
|
Team combAuthor = Team.NewInstance();
|
207
|
combAuthor.addTeamMember(Person.NewTitledInstance("test member"));
|
208
|
BotanicalName name = BotanicalName.NewInstance(null, "Test1", null, null, null, null, null, null, null);
|
209
|
name.setCombinationAuthorTeam(combAuthor);
|
210
|
Taxon tax1 = Taxon.NewInstance(name, null);
|
211
|
UUID taxonUuid1 = taxonService.save(tax1);
|
212
|
|
213
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
214
|
|
215
|
NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
216
|
String oldTitleCache = nvn.getTitleCache();
|
217
|
logger.info("Taxon Name Title : " + oldTitleCache);
|
218
|
nvn.setTitleCache(oldTitleCache + ":updated",false);
|
219
|
taxonService.update(taxon);
|
220
|
|
221
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
222
|
NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
223
|
logger.info("New Taxon Name Title : " + nvnNew.getTitleCache());
|
224
|
|
225
|
Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(nvnNew.getTitleCache()));
|
226
|
|
227
|
nvnNew.setTitleCache(oldTitleCache, true);
|
228
|
taxonService.update(taxon);
|
229
|
|
230
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
231
|
NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class);
|
232
|
logger.info("Old Taxon Name Title : " + nvnNew.getTitleCache());
|
233
|
|
234
|
Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache());
|
235
|
}
|
236
|
@Ignore
|
237
|
@Test
|
238
|
public void testCDMEntitySaveCollection() {
|
239
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
240
|
|
241
|
Set<SynonymRelationship> synRelations = taxon.getSynonymRelations();
|
242
|
Set<String> relToTitles = new HashSet<String>();
|
243
|
Iterator<SynonymRelationship> srItr = synRelations.iterator();
|
244
|
while(srItr.hasNext()) {
|
245
|
SynonymRelationship sr = srItr.next();
|
246
|
System.out.println("Synonym Title Cache : " + sr.getSynonym().getTitleCache());
|
247
|
relToTitles.add(sr.getSynonym().getTitleCache());
|
248
|
sr.getSynonym().setTitleCache(sr.getSynonym().getTitleCache() + ":updated");
|
249
|
|
250
|
}
|
251
|
taxonService.merge(taxon);
|
252
|
|
253
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
254
|
Set<SynonymRelationship> synRelationsNew = taxonNew.getSynonymRelations();
|
255
|
|
256
|
Iterator<SynonymRelationship> srItrNew = synRelationsNew.iterator();
|
257
|
Iterator<String> relToTitlesItr = relToTitles.iterator();
|
258
|
while(srItrNew.hasNext() && relToTitlesItr.hasNext()) {
|
259
|
SynonymRelationship srNew = srItrNew.next();
|
260
|
String relToTitle = relToTitlesItr.next();
|
261
|
System.out.println("New Synonym Title Cache: " + srNew.getSynonym().getTitleCache());
|
262
|
Assert.assertTrue("Synonym Title caches should not be equal", srNew.getSynonym().getTitleCache().equals(relToTitle));
|
263
|
srNew.getSynonym().setTitleCache(relToTitle);
|
264
|
}
|
265
|
|
266
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
267
|
|
268
|
Set<SynonymRelationship> synRelationsOld = taxonNew.getSynonymRelations();
|
269
|
Iterator<SynonymRelationship> srItrOld = synRelationsOld.iterator();
|
270
|
relToTitlesItr = relToTitles.iterator();
|
271
|
while(srItrOld.hasNext() && relToTitlesItr.hasNext()) {
|
272
|
SynonymRelationship srOld = srItrOld.next();
|
273
|
String relToTitle = relToTitlesItr.next();
|
274
|
System.out.println("New Synonym Title Cache: " + srOld.getSynonym().getTitleCache());
|
275
|
Assert.assertEquals("Synonym Title caches should be equal", srOld.getSynonym().getTitleCache(), relToTitle);
|
276
|
|
277
|
}
|
278
|
}
|
279
|
}
|