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