1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 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.taxeditor.session;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
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
|
import org.unitils.dbunit.annotation.DataSet;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
28
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
29
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
30
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
31
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
32
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
33
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
34
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
35
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
36
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
37
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
38
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
39
|
import eu.etaxonomy.cdm.model.agent.Person;
|
40
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
41
|
import eu.etaxonomy.cdm.model.common.Credit;
|
42
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
43
|
import eu.etaxonomy.cdm.model.common.Extension;
|
44
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
45
|
import eu.etaxonomy.cdm.model.common.Language;
|
46
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
47
|
import eu.etaxonomy.cdm.model.common.TermType;
|
48
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
49
|
import eu.etaxonomy.cdm.model.description.Feature;
|
50
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
51
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
52
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
53
|
import eu.etaxonomy.cdm.model.media.Rights;
|
54
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
55
|
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
|
56
|
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
|
57
|
import eu.etaxonomy.taxeditor.httpinvoker.TestThread;
|
58
|
|
59
|
|
60
|
/**
|
61
|
* @author cmathew
|
62
|
* @date 7 Oct 2014
|
63
|
*
|
64
|
*/
|
65
|
@DataSet
|
66
|
public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
|
67
|
|
68
|
private static final Logger logger = Logger.getLogger(CdmEntitySessionAwareTest.class);
|
69
|
|
70
|
UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
|
71
|
UUID subKeyUuid = UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01");
|
72
|
//UUID polytomousKeyUuid = UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
|
73
|
UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
|
74
|
UUID personUuid = UUID.fromString("945d08f2-eb92-45b6-9252-6275ea6d338b");
|
75
|
|
76
|
|
77
|
|
78
|
IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
|
79
|
IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
|
80
|
ICommonService commonService = getRemoteApplicationController().getCommonService();
|
81
|
ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
82
|
IVocabularyService vocabularyService = getRemoteApplicationController().getVocabularyService();
|
83
|
ITermService termService = getRemoteApplicationController().getTermService();
|
84
|
IUserService userService = getRemoteApplicationController().getUserService();
|
85
|
|
86
|
//Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
87
|
|
88
|
|
89
|
|
90
|
@BeforeClass
|
91
|
public static void initializePolytomousKeyTest() {
|
92
|
}
|
93
|
|
94
|
|
95
|
@Test
|
96
|
@Ignore
|
97
|
public void readAllPolytomousKeys() {
|
98
|
List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
|
99
|
Iterator<PolytomousKey> pKeysItr = pKeys.iterator();
|
100
|
Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
|
101
|
Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
|
102
|
}
|
103
|
|
104
|
|
105
|
@Test
|
106
|
//@DataSet("PolytomousKeyTest.readPolytmousKeyData.xml")
|
107
|
public void readPolytmousKeyData() {
|
108
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
109
|
Set<Taxon> taxonomicScope = pKey.getTaxonomicScope();
|
110
|
Iterator<Taxon> tsItr = taxonomicScope.iterator();
|
111
|
Taxon taxon = tsItr.next();
|
112
|
|
113
|
Assert.assertEquals("Achillea sec. Cyprus", taxon.getTitleCache());
|
114
|
Assert.assertEquals(tsItr.hasNext(), false);
|
115
|
|
116
|
List<Credit> credits = pKey.getCredits();
|
117
|
AgentBase agent = credits.get(0).getAgent();
|
118
|
Assert.assertEquals(agent.getId(),4809);
|
119
|
Assert.assertEquals(agent.getTitleCache(),"R. A. Graham");
|
120
|
Assert.assertEquals(credits.get(0).getText(),"Credits Text Test");
|
121
|
|
122
|
Set<Extension> exts = pKey.getExtensions();
|
123
|
Iterator<Extension> extItr = exts.iterator();
|
124
|
Extension ext = extItr.next();
|
125
|
Assert.assertEquals(ext.getValue(), "http://test.com");
|
126
|
|
127
|
Set<Rights> rights = pKey.getRights();
|
128
|
Iterator<Rights> rightsItr = rights.iterator();
|
129
|
Rights right = rightsItr.next();
|
130
|
Assert.assertEquals(right.getText(),"Rights Text Test");
|
131
|
|
132
|
Set<IdentifiableSource> sources = pKey.getSources();
|
133
|
Iterator<IdentifiableSource> sourcesItr = sources.iterator();
|
134
|
IdentifiableSource source = sourcesItr.next();
|
135
|
Assert.assertEquals(source.getId(), 23710);
|
136
|
source = sourcesItr.next();
|
137
|
Assert.assertEquals(source.getId(), 23711);
|
138
|
|
139
|
// TO DO : Added tests for Annotations , Markers
|
140
|
}
|
141
|
|
142
|
|
143
|
|
144
|
@Test
|
145
|
public void readPolytomousKeyDataFromNodes() {
|
146
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
147
|
PolytomousKeyNode rootNode = pKey.getRoot();
|
148
|
|
149
|
|
150
|
Assert.assertEquals(rootNode.getId(), 2750);
|
151
|
|
152
|
Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751);
|
153
|
Assert.assertEquals(rootNode.getChildAt(0).getParent().getId(), rootNode.getId());
|
154
|
Assert.assertEquals(rootNode.getKey().getId(), pKey.getId());
|
155
|
Integer sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(0), "sortIndex");
|
156
|
Assert.assertEquals(sortIndex, new Integer(0));
|
157
|
String statement = "Capitula without ligulate ray-florets; leaves entire or subentire";
|
158
|
Assert.assertEquals(rootNode.getChildAt(0).getStatement().getLabelText(Language.ENGLISH()), statement);
|
159
|
|
160
|
Assert.assertEquals(rootNode.getChildAt(1).getId(), 2753);
|
161
|
Assert.assertEquals(rootNode.getChildAt(1).getParent().getId(), rootNode.getId());
|
162
|
Assert.assertEquals(rootNode.getChildAt(1).getKey().getId(), pKey.getId());
|
163
|
sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1), "sortIndex");
|
164
|
Assert.assertEquals(sortIndex, new Integer(1));
|
165
|
statement = "Capitula with ligulate ray-florets; leaves pinnatisect";
|
166
|
Assert.assertEquals(rootNode.getChildAt(1).getStatement().getLabelText(Language.ENGLISH()), statement);
|
167
|
|
168
|
Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getId(), 2754);
|
169
|
Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getParent().getId(), rootNode.getChildAt(1).getId());
|
170
|
Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getKey().getId(), pKey.getId());
|
171
|
sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1).getChildAt(0), "sortIndex");
|
172
|
Assert.assertEquals(sortIndex, new Integer(0));
|
173
|
statement = "Ray-florets yellow";
|
174
|
Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getStatement().getLabelText(Language.ENGLISH()), statement);
|
175
|
Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getChildAt(0).getTaxon().getTitleCache(), "Achillea arabica Kotschy sec. Cyprus");
|
176
|
}
|
177
|
|
178
|
@Test
|
179
|
@Ignore
|
180
|
public void addGrandChildPolytomousKeyNode() {
|
181
|
|
182
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
183
|
PolytomousKeyNode rootChildNode = pKey.getRoot().getChildAt(0);
|
184
|
PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance();
|
185
|
rootChildNode.addChild(grandChildNode);
|
186
|
|
187
|
MergeResult<PolytomousKey> result = polytomousKeyService.merge(pKey, true);
|
188
|
pKey = result.getMergedEntity();
|
189
|
grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
|
190
|
Assert.assertTrue(0 != grandChildNode.getId());
|
191
|
KeyStatement ks = KeyStatement.NewInstance("test");
|
192
|
grandChildNode.setStatement(ks);
|
193
|
polytomousKeyService.merge(pKey, true);
|
194
|
|
195
|
//grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
|
196
|
//KeyStatement ks = grandChildNode.getStatement();
|
197
|
Assert.assertTrue(0 != ks.getId());
|
198
|
|
199
|
}
|
200
|
|
201
|
@Test
|
202
|
public void addGreatGrandChildPolytomousKeyNode() {
|
203
|
|
204
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
205
|
PolytomousKeyNode rootChildNode = pKey.getRoot().getChildAt(0);
|
206
|
PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance();
|
207
|
rootChildNode.addChild(grandChildNode);
|
208
|
|
209
|
|
210
|
polytomousKeyNodeService.merge(grandChildNode);
|
211
|
|
212
|
|
213
|
Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
|
214
|
}
|
215
|
|
216
|
@Test
|
217
|
public void savePolytomousKeyNodeData() {
|
218
|
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
219
|
|
220
|
PolytomousKeyNode pkeynode = pkey.getRoot();
|
221
|
String newQuestion = "New Question";
|
222
|
String newStatement = "New Statement";
|
223
|
|
224
|
Assert.assertEquals("Question 1",pkeynode.getQuestion().getLabel().get(Language.ENGLISH()).getText());
|
225
|
for(PolytomousKeyNode node : pkeynode.getChildren()) {
|
226
|
|
227
|
node.setQuestion(null);
|
228
|
node.setStatement(null);
|
229
|
}
|
230
|
//FIXME:Remoting Add tests for feature after fixing problem
|
231
|
|
232
|
//Feature feature = pkeynode.getFeature();
|
233
|
//Assert.assertEquals(feature.getTitleCache(),"Systematics");
|
234
|
//pkeynode.setFeature(null);
|
235
|
|
236
|
Assert.assertEquals(pkeynode.getChildAt(0).getModifyingText().get(Language.ENGLISH()).getText(),"Modifying Text 1a");
|
237
|
String modifyingText = "Modifying Text 1a updated";
|
238
|
|
239
|
//pkeynode.getChildAt(0).putModifyingText(Language.ENGLISH(), modifyingText);
|
240
|
|
241
|
Assert.assertEquals(pkeynode.getChildAt(0).getSubkey().getId(),751);
|
242
|
Assert.assertEquals("Asphodeline", pkeynode.getChildAt(0).getSubkey().getTitleCache());
|
243
|
Assert.assertNull(pkeynode.getChildAt(1).getTaxon());
|
244
|
Taxon taxon = CdmBase.deproxy(taxonService.find(taxon1Uuid),Taxon.class);
|
245
|
pkeynode.getChildAt(1).setTaxon(taxon);
|
246
|
|
247
|
polytomousKeyService.merge(pkey);
|
248
|
|
249
|
pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
250
|
|
251
|
|
252
|
pkeynode = pkey.getRoot();
|
253
|
for(PolytomousKeyNode node : pkeynode.getChildren()) {
|
254
|
Assert.assertNull(node.getQuestion());
|
255
|
node.setQuestion(KeyStatement.NewInstance(Language.ENGLISH(),newQuestion));
|
256
|
Assert.assertNull(node.getStatement());
|
257
|
node.setStatement(KeyStatement.NewInstance(Language.ENGLISH(),newStatement));
|
258
|
}
|
259
|
|
260
|
Assert.assertEquals(pkeynode.getChildAt(1).getTaxon(), taxon);
|
261
|
|
262
|
polytomousKeyService.merge(pkey);
|
263
|
|
264
|
pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
265
|
|
266
|
pkeynode = pkey.getRoot();
|
267
|
for(PolytomousKeyNode node : pkeynode.getChildren()) {
|
268
|
Assert.assertNotNull(node.getQuestion());
|
269
|
Map<Language, LanguageString> label = node.getQuestion().getLabel();
|
270
|
Assert.assertEquals(newQuestion, label.get(Language.ENGLISH()).getText());
|
271
|
Assert.assertNotNull(node.getStatement());
|
272
|
Assert.assertEquals(newStatement, node.getStatement().getLabel(Language.ENGLISH()).getText());
|
273
|
}
|
274
|
//Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
|
275
|
|
276
|
}
|
277
|
|
278
|
|
279
|
@Test
|
280
|
public void savePolytomousKeyNodeDataWithSameSubKey() {
|
281
|
|
282
|
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
283
|
|
284
|
|
285
|
PolytomousKeyNode pkeynode = pkey.getRoot();
|
286
|
|
287
|
PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class);
|
288
|
String subkey1title = subkey1.getTitleCache();
|
289
|
subkey1.setTitleCache(subkey1title + "test", true);
|
290
|
|
291
|
|
292
|
PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class);
|
293
|
String subkey2title = subkey2.getTitleCache();
|
294
|
subkey2.setTitleCache(subkey2title + "test", true);
|
295
|
|
296
|
Assert.assertSame(subkey1, subkey2);
|
297
|
|
298
|
polytomousKeyService.merge(pkey);
|
299
|
}
|
300
|
|
301
|
@Test
|
302
|
public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
|
303
|
|
304
|
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
305
|
|
306
|
|
307
|
PolytomousKeyNode pkeynode = pkey.getRoot();
|
308
|
//because of the check for null values in getChildren it isn't a persistent list anymore
|
309
|
// PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
|
310
|
PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 0);
|
311
|
PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
|
312
|
String subkey1title = subkey1.getTitleCache();
|
313
|
subkey1.setTitleCache(subkey1title + "test", true);
|
314
|
|
315
|
PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 1);
|
316
|
PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
|
317
|
String subkey2title = subkey2.getTitleCache();
|
318
|
subkey2.setTitleCache(subkey2title + "test", true);
|
319
|
|
320
|
Assert.assertNotSame(childNode0, childNode1);
|
321
|
|
322
|
Assert.assertSame(subkey1, subkey2);
|
323
|
|
324
|
polytomousKeyService.merge(pkey);
|
325
|
}
|
326
|
|
327
|
|
328
|
|
329
|
@Test
|
330
|
public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
|
331
|
|
332
|
PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
333
|
PolytomousKeyNode pkeynode = pkey.getRoot();
|
334
|
|
335
|
Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel();
|
336
|
label1.size();
|
337
|
|
338
|
|
339
|
Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel();
|
340
|
label2.size();
|
341
|
|
342
|
|
343
|
polytomousKeyService.merge(pkey);
|
344
|
}
|
345
|
|
346
|
@Test
|
347
|
public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() {
|
348
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
349
|
|
350
|
|
351
|
PolytomousKeyNode rootNode = pKey.getRoot();
|
352
|
|
353
|
PolytomousKeyNode childNode = rootNode.getChildAt(0);
|
354
|
PolytomousKey subKey = HibernateProxyHelper.deproxy( childNode.getSubkey(), PolytomousKey.class);;
|
355
|
|
356
|
|
357
|
DeleteResult result = polytomousKeyService.delete(subKey.getUuid());
|
358
|
//A used subKey can't be deleted
|
359
|
if (result.isOk()){
|
360
|
Assert.fail();
|
361
|
}
|
362
|
|
363
|
|
364
|
Set<Integer> ids = new HashSet<Integer>();
|
365
|
ids.add(2753);
|
366
|
ids.add(2754);
|
367
|
ids.add(2751);
|
368
|
List<PolytomousKeyNode> nodes = polytomousKeyNodeService.findById(ids);
|
369
|
for (PolytomousKeyNode child:nodes){
|
370
|
child.setSubkey(null);
|
371
|
// polytomousKeyNodeService.merge(child);
|
372
|
}
|
373
|
polytomousKeyNodeService.merge(nodes, true);
|
374
|
result = polytomousKeyService.delete(subKey.getUuid());
|
375
|
if (!result.isOk()){
|
376
|
Assert.fail();
|
377
|
}
|
378
|
|
379
|
|
380
|
|
381
|
|
382
|
// retrieving subkey shows its null
|
383
|
subKey = CdmBase.deproxy(polytomousKeyService.find(subKeyUuid),PolytomousKey.class);
|
384
|
Assert.assertNull(subKey);
|
385
|
|
386
|
pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
387
|
|
388
|
|
389
|
}
|
390
|
|
391
|
|
392
|
@Test
|
393
|
public void deleteSubKeyInPolytomousNode() {
|
394
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
395
|
|
396
|
|
397
|
PolytomousKeyNode rootNode = pKey.getRoot();
|
398
|
List<PolytomousKeyNode> children = rootNode.getChildren();
|
399
|
PolytomousKeyNode child = rootNode.getChildAt(0);
|
400
|
polytomousKeyNodeService.delete(child.getUuid(), true);
|
401
|
|
402
|
pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
403
|
|
404
|
rootNode = pKey.getRoot();
|
405
|
children = rootNode.getChildren();
|
406
|
Assert.assertFalse(children.contains(child));
|
407
|
}
|
408
|
|
409
|
@Test
|
410
|
public void deleteSubKeyInPolytomousSubKeyAfterInitializing() {
|
411
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
412
|
|
413
|
|
414
|
PolytomousKeyNode rootNode = pKey.getRoot();
|
415
|
PolytomousKeyNode child = rootNode.getChildAt(0);
|
416
|
PolytomousKey subKey = child.getSubkey();
|
417
|
// this call initializes the subkey
|
418
|
subKey.getRoot();
|
419
|
|
420
|
polytomousKeyService.delete(subKey);
|
421
|
|
422
|
// since subKey was initialized before the delete, it will be
|
423
|
// accesible even after the delete. This behaviour is similar
|
424
|
// to hibernate session delete where the deleted object is
|
425
|
// made transient, but not deleted from the object graph
|
426
|
|
427
|
PolytomousKeyNode subKeyRootNode = subKey.getRoot();
|
428
|
Assert.assertNotNull(subKey);
|
429
|
}
|
430
|
|
431
|
@Test
|
432
|
public void saveNewTermVocabulary() {
|
433
|
TermVocabulary termVocabulary =
|
434
|
TermVocabulary.NewInstance(TermType.Feature,
|
435
|
null,
|
436
|
"Untitled",
|
437
|
null,
|
438
|
null);
|
439
|
try {
|
440
|
List<TermVocabulary<DefinedTermBase>> vocabularies = vocabularyService.findByTermType(TermType.Feature);
|
441
|
|
442
|
for(TermVocabulary vocab : vocabularies) {
|
443
|
vocab.getTermsOrderedByLabels(Language.ENGLISH());
|
444
|
}
|
445
|
|
446
|
termVocabulary = vocabularyService.merge(termVocabulary);
|
447
|
vocabularies.add(termVocabulary);
|
448
|
termVocabulary.setLabel("Test");
|
449
|
vocabularyService.merge(new ArrayList<TermVocabulary>(vocabularies));
|
450
|
} finally {
|
451
|
vocabularyService.delete(termVocabulary);
|
452
|
}
|
453
|
}
|
454
|
|
455
|
@Test
|
456
|
public void saveNewTerm() {
|
457
|
UUID vocNameFeatureUuid = UUID.fromString("fa7ca3eef-4092-49e1-beec-ed5096193e5e");
|
458
|
UUID vocFeatureUuid = UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8");
|
459
|
DefinedTermBase newTerm = TermType.Feature.getEmptyDefinedTermBase();
|
460
|
newTerm.setLabel("CreateTest");
|
461
|
|
462
|
try {
|
463
|
if(termService.findByRepresentationText("UpdateTest", Feature.class, null, null) != null) {
|
464
|
Pager<Feature> terms = termService.findByRepresentationText("UpdateTest", Feature.class, null, null);
|
465
|
if (!terms.getRecords().isEmpty()){
|
466
|
termService.delete(terms.getRecords().get(0).getUuid());
|
467
|
}
|
468
|
}
|
469
|
|
470
|
Assert.assertNotNull(newTerm);
|
471
|
TermVocabulary vocNameFeature = vocabularyService.find(vocNameFeatureUuid);
|
472
|
TermVocabulary vocFeature = vocabularyService.find(vocFeatureUuid);
|
473
|
|
474
|
List<TermVocabulary> vocs = new ArrayList<TermVocabulary>();
|
475
|
|
476
|
vocs.add(vocNameFeature);
|
477
|
vocs.add(vocFeature);
|
478
|
|
479
|
vocNameFeature.addTerm(newTerm);
|
480
|
|
481
|
vocs = vocabularyService.merge(vocs);
|
482
|
for(TermVocabulary voc : vocs) {
|
483
|
if(voc.getUuid().equals(vocNameFeatureUuid)) {
|
484
|
vocNameFeature = voc;
|
485
|
}
|
486
|
}
|
487
|
|
488
|
Assert.assertTrue(vocNameFeature.getTerms().contains(newTerm));
|
489
|
|
490
|
for(Object obj : vocNameFeature.getTerms()) {
|
491
|
DefinedTermBase dtb = (DefinedTermBase)obj;
|
492
|
if("CreateTest".equals(dtb.getLabel())) {
|
493
|
newTerm = dtb;
|
494
|
Assert.assertNotNull(dtb.getCreatedBy());
|
495
|
Assert.assertNotNull(dtb.getCreated());
|
496
|
} else {
|
497
|
System.err.println(dtb.getLabel() + " " + dtb.getCreatedBy() + " " + dtb.getUuid());
|
498
|
Assert.assertNull(dtb.getCreatedBy());
|
499
|
}
|
500
|
}
|
501
|
newTerm.setLabel("UpdateTest");
|
502
|
newTerm = termService.merge(newTerm);
|
503
|
Assert.assertNotNull(newTerm.getUpdatedBy());
|
504
|
Assert.assertNotNull(newTerm.getUpdated());
|
505
|
|
506
|
Assert.assertNull(vocNameFeature.getCreatedBy());
|
507
|
Assert.assertNull(vocFeature.getCreatedBy());
|
508
|
} finally {
|
509
|
if(termService.find(newTerm.getUuid()) != null) {
|
510
|
termService.delete(newTerm.getUuid());
|
511
|
}
|
512
|
}
|
513
|
}
|
514
|
|
515
|
|
516
|
@Test
|
517
|
public void updatePerson() {
|
518
|
// Test for #5138
|
519
|
Person person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().load(personUuid);
|
520
|
person.setFirstname("Me");
|
521
|
CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person);
|
522
|
}
|
523
|
|
524
|
|
525
|
@Test
|
526
|
public void createPerson() {
|
527
|
// Test for #5138
|
528
|
Person person = Person.NewInstance();
|
529
|
person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person);
|
530
|
person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().load(person.getUuid());
|
531
|
person.setFirstname("Some");
|
532
|
CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person);
|
533
|
}
|
534
|
|
535
|
@Test
|
536
|
public void testThreadLocalActiveSession() throws InterruptedException {
|
537
|
MockSessionOwner<CdmBase> so1 = new MockSessionOwner<CdmBase>();
|
538
|
final ICdmEntitySession activeSession = getCdmEntitySessionManager().newSession(so1, true);
|
539
|
TestThread thread = new TestThread(true) {
|
540
|
@Override
|
541
|
public void doRun() throws InterruptedException {
|
542
|
ICdmEntitySession threadLocalActiveSession = getCdmEntitySessionManager().getActiveSession();
|
543
|
Assert.assertEquals(threadLocalActiveSession, activeSession);
|
544
|
}
|
545
|
};
|
546
|
invokeThread(thread);
|
547
|
MockSessionOwner<CdmBase> so2 = new MockSessionOwner<CdmBase>();
|
548
|
ICdmEntitySession newActiveSession = getCdmEntitySessionManager().newSession(so2, true);
|
549
|
Assert.assertFalse(activeSession.equals(newActiveSession));
|
550
|
thread.unblock();
|
551
|
|
552
|
}
|
553
|
}
|