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