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