ref #9359 upgrade TaxEditor to log4j2
[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.logging.log4j.LogManager;import org.apache.logging.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 = LogManager.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 @Ignore //ignore preliminary to allow full build
135 public void readPolytomousKeyDataFromNodes() {
136 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
137 PolytomousKeyNode rootNode = pKey.getRoot();
138
139 Assert.assertEquals(rootNode.getId(), 2750);
140
141 Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751);
142 Assert.assertEquals(rootNode.getChildAt(0).getParent().getId(), rootNode.getId());
143 Assert.assertEquals(rootNode.getKey().getId(), pKey.getId());
144 Integer sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(0), "sortIndex");
145 Assert.assertEquals(sortIndex, new Integer(0));
146 String statement = "Capitula without ligulate ray-florets; leaves entire or subentire";
147 Assert.assertEquals(rootNode.getChildAt(0).getStatement().getLabelText(Language.ENGLISH()), statement);
148
149 Assert.assertEquals(rootNode.getChildAt(1).getId(), 2753);
150 Assert.assertEquals(rootNode.getChildAt(1).getParent().getId(), rootNode.getId());
151 Assert.assertEquals(rootNode.getChildAt(1).getKey().getId(), pKey.getId());
152 sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1), "sortIndex");
153 Assert.assertEquals(sortIndex, new Integer(1));
154 statement = "Capitula with ligulate ray-florets; leaves pinnatisect";
155 Assert.assertEquals(rootNode.getChildAt(1).getStatement().getLabelText(Language.ENGLISH()), statement);
156
157 Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getId(), 2754);
158 Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getParent().getId(), rootNode.getChildAt(1).getId());
159 Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getKey().getId(), pKey.getId());
160 sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1).getChildAt(0), "sortIndex");
161 Assert.assertEquals(sortIndex, new Integer(0));
162 statement = "Ray-florets yellow";
163 Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getStatement().getLabelText(Language.ENGLISH()), statement);
164 Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getChildAt(0).getTaxon().getTitleCache(), "Achillea arabica Kotschy sec. Cyprus");
165 }
166
167 @Test
168 @Ignore
169 public void addGrandChildPolytomousKeyNode() {
170
171 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
172 PolytomousKeyNode rootChildNode = pKey.getRoot().getChildAt(0);
173 PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance();
174 rootChildNode.addChild(grandChildNode);
175
176 MergeResult<PolytomousKey> result = polytomousKeyService.merge(pKey, true);
177 pKey = result.getMergedEntity();
178 grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
179 Assert.assertTrue(0 != grandChildNode.getId());
180 KeyStatement ks = KeyStatement.NewInstance("test");
181 grandChildNode.setStatement(ks);
182 polytomousKeyService.merge(pKey, true);
183
184 //grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
185 //KeyStatement ks = grandChildNode.getStatement();
186 Assert.assertTrue(0 != ks.getId());
187
188 }
189
190 @Test
191 public void addGreatGrandChildPolytomousKeyNode() {
192
193 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
194 PolytomousKeyNode rootChildNode = pKey.getRoot().getChildAt(0);
195 PolytomousKeyNode grandChildNode = PolytomousKeyNode.NewInstance();
196 rootChildNode.addChild(grandChildNode);
197
198 polytomousKeyNodeService.merge(grandChildNode, true);
199
200 Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
201 }
202
203 @Test
204 public void savePolytomousKeyNodeData() {
205 PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
206
207 PolytomousKeyNode pkeynode = pkey.getRoot();
208 String newQuestion = "New Question";
209 String newStatement = "New Statement";
210
211 Assert.assertEquals("Question 1",pkeynode.getQuestion().getLabel().get(Language.ENGLISH()).getText());
212 for(PolytomousKeyNode node : pkeynode.getChildren()) {
213
214 node.setQuestion(null);
215 node.setStatement(null);
216 }
217 //FIXME:Remoting Add tests for feature after fixing problem
218
219 //Feature feature = pkeynode.getFeature();
220 //Assert.assertEquals(feature.getTitleCache(),"Systematics");
221 //pkeynode.setFeature(null);
222
223 Assert.assertEquals(pkeynode.getChildAt(0).getModifyingText().get(Language.ENGLISH()).getText(),"Modifying Text 1a");
224 String modifyingText = "Modifying Text 1a updated";
225
226 //pkeynode.getChildAt(0).putModifyingText(Language.ENGLISH(), modifyingText);
227
228 Assert.assertEquals(pkeynode.getChildAt(0).getSubkey().getId(),751);
229 Assert.assertEquals("Asphodeline", pkeynode.getChildAt(0).getSubkey().getTitleCache());
230 Assert.assertNull(pkeynode.getChildAt(1).getTaxon());
231 Taxon taxon = CdmBase.deproxy(taxonService.find(taxon1Uuid),Taxon.class);
232 pkeynode.getChildAt(1).setTaxon(taxon);
233
234 polytomousKeyService.merge(pkey, true);
235
236 pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
237
238 pkeynode = pkey.getRoot();
239 for(PolytomousKeyNode node : pkeynode.getChildren()) {
240 Assert.assertNull(node.getQuestion());
241 node.setQuestion(KeyStatement.NewInstance(Language.ENGLISH(),newQuestion));
242 Assert.assertNull(node.getStatement());
243 node.setStatement(KeyStatement.NewInstance(Language.ENGLISH(),newStatement));
244 }
245
246 Assert.assertEquals(pkeynode.getChildAt(1).getTaxon(), taxon);
247
248 polytomousKeyService.merge(pkey, true);
249
250 pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
251
252 pkeynode = pkey.getRoot();
253 for(PolytomousKeyNode node : pkeynode.getChildren()) {
254 Assert.assertNotNull(node.getQuestion());
255 Map<Language, LanguageString> label = node.getQuestion().getLabel();
256 Assert.assertEquals(newQuestion, label.get(Language.ENGLISH()).getText());
257 Assert.assertNotNull(node.getStatement());
258 Assert.assertEquals(newStatement, node.getStatement().getLabel(Language.ENGLISH()).getText());
259 }
260 //Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
261 }
262
263
264 @Test
265 public void savePolytomousKeyNodeDataWithSameSubKey() {
266
267 PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
268
269 PolytomousKeyNode pkeynode = pkey.getRoot();
270
271 PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class);
272 String subkey1title = subkey1.getTitleCache();
273 subkey1.setTitleCache(subkey1title + "test", true);
274
275 PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class);
276 String subkey2title = subkey2.getTitleCache();
277 subkey2.setTitleCache(subkey2title + "test", true);
278
279 Assert.assertSame(subkey1, subkey2);
280
281 polytomousKeyService.merge(pkey, true);
282 }
283
284 @Test
285 public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
286
287 PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
288
289 PolytomousKeyNode pkeynode = pkey.getRoot();
290 //because of the check for null values in getChildren it isn't a persistent list anymore
291 // PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
292 PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 0);
293 PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
294 String subkey1title = subkey1.getTitleCache();
295 subkey1.setTitleCache(subkey1title + "test", true);
296
297 PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 1);
298 PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
299 String subkey2title = subkey2.getTitleCache();
300 subkey2.setTitleCache(subkey2title + "test", true);
301
302 Assert.assertNotSame(childNode0, childNode1);
303
304 Assert.assertSame(subkey1, subkey2);
305
306 polytomousKeyService.merge(pkey, true);
307 }
308
309 @Test
310 public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
311
312 PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
313 PolytomousKeyNode pkeynode = pkey.getRoot();
314
315 Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel();
316 label1.size();
317
318 Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel();
319 label2.size();
320
321 polytomousKeyService.merge(pkey, true);
322 }
323
324 @Test
325 public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() {
326 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
327
328 PolytomousKeyNode rootNode = pKey.getRoot();
329
330 PolytomousKeyNode childNode = rootNode.getChildAt(0);
331 PolytomousKey subKey = HibernateProxyHelper.deproxy( childNode.getSubkey(), PolytomousKey.class);;
332
333 DeleteResult result = polytomousKeyService.delete(subKey.getUuid());
334 //A used subKey can't be deleted
335 if (result.isOk()){
336 Assert.fail();
337 }
338
339 Set<Integer> ids = new HashSet<Integer>();
340 ids.add(2753);
341 ids.add(2754);
342 ids.add(2751);
343 List<PolytomousKeyNode> nodes = polytomousKeyNodeService.findById(ids);
344 for (PolytomousKeyNode child:nodes){
345 child.setSubkey(null);
346 // polytomousKeyNodeService.merge(child);
347 }
348 polytomousKeyNodeService.merge(nodes, true);
349 result = polytomousKeyService.delete(subKey.getUuid());
350 if (!result.isOk()){
351 Assert.fail();
352 }
353
354 // retrieving subkey shows its null
355 subKey = CdmBase.deproxy(polytomousKeyService.find(subKeyUuid),PolytomousKey.class);
356 Assert.assertNull(subKey);
357
358 pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
359 }
360
361
362 @Test
363 public void deleteSubKeyInPolytomousNode() {
364 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
365
366
367 PolytomousKeyNode rootNode = pKey.getRoot();
368 List<PolytomousKeyNode> children = rootNode.getChildren();
369 PolytomousKeyNode child = rootNode.getChildAt(0);
370 DeleteResult result = polytomousKeyNodeService.delete(child.getUuid(), true);
371
372 pKey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid),PolytomousKey.class);
373
374 rootNode = pKey.getRoot();
375 children = rootNode.getChildren();
376 Assert.assertFalse(children.contains(child));
377 }
378
379 @Test
380 public void deleteSubKeyInPolytomousSubKeyAfterInitializing() {
381 PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
382
383
384 PolytomousKeyNode rootNode = pKey.getRoot();
385 PolytomousKeyNode child = rootNode.getChildAt(0);
386 PolytomousKey subKey = child.getSubkey();
387 // this call initializes the subkey
388 subKey.getRoot();
389
390 polytomousKeyService.delete(subKey);
391
392 // since subKey was initialized before the delete, it will be
393 // accesible even after the delete. This behaviour is similar
394 // to hibernate session delete where the deleted object is
395 // made transient, but not deleted from the object graph
396
397 PolytomousKeyNode subKeyRootNode = subKey.getRoot();
398 Assert.assertNotNull(subKey);
399 }
400
401 @Test
402 public void saveNewTermVocabulary() {
403 TermVocabulary<Feature> termVocabulary =
404 TermVocabulary.NewInstance(TermType.Feature,
405 null,
406 "Untitled",
407 null,
408 null);
409 try {
410 List<TermVocabulary<? extends DefinedTermBase<?>>> vocabularies = (List)vocabularyService.findByTermType(TermType.Feature, null);
411
412 for(TermVocabulary<?> vocab : vocabularies) {
413 vocab.getTermsOrderedByLabels(Language.ENGLISH());
414 }
415
416 termVocabulary = vocabularyService.merge(termVocabulary);
417 vocabularies.add(termVocabulary);
418 termVocabulary.setLabel("Test");
419 vocabularyService.merge(new ArrayList<>(vocabularies));
420 } finally {
421 vocabularyService.delete(termVocabulary);
422 }
423 }
424
425 @Test
426 public void saveNewTerm() {
427 UUID vocNameFeatureUuid = UUID.fromString("fa7ca3eef-4092-49e1-beec-ed5096193e5e");
428 UUID vocFeatureUuid = UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8");
429 Feature newTerm = (Feature)TermType.Feature.getEmptyDefinedTermBase(null);
430 newTerm.setLabel("CreateTest");
431
432 try {
433 List<Feature> features = termService.list(Feature.class, 100, 0, null, null);
434 List<UUID> updateTerms = new ArrayList<>();
435 for (Feature feature:features){
436 if (feature.getLabel().equals("UpdateTest")){
437 updateTerms.add(feature.getUuid());
438 }
439 }
440 termService.delete(updateTerms);
441
442 // if(termService.findByRepresentationText("UpdateTest", Feature.class, null, null) != null) {
443 // Pager<Feature> terms = termService.findByRepresentationText("UpdateTest", Feature.class, null, null);
444 // if (!terms.getRecords().isEmpty()){
445 // termService.delete(terms.getRecords().get(0).getUuid());
446 // }
447 // }
448
449 Assert.assertNotNull(newTerm);
450 @SuppressWarnings("unchecked")
451 TermVocabulary<Feature> vocNameFeature = vocabularyService.find(vocNameFeatureUuid);
452 @SuppressWarnings("unchecked")
453 TermVocabulary<Feature> vocFeature = vocabularyService.find(vocFeatureUuid);
454
455 @SuppressWarnings("rawtypes")
456 List<TermVocabulary> vocs = new ArrayList<>();
457
458 vocs.add(vocNameFeature);
459 vocs.add(vocFeature);
460
461 vocNameFeature.addTerm(newTerm);
462
463 List<MergeResult<TermVocabulary<Feature>>> mergeResults = (List)vocabularyService.merge(vocs, true);
464
465 for(MergeResult<TermVocabulary<Feature>> result : mergeResults){
466 TermVocabulary<Feature> voc = result.getMergedEntity();
467 if(voc.getUuid().equals(vocNameFeatureUuid)) {
468 vocNameFeature = voc;
469 }
470 }
471
472 Assert.assertTrue(vocNameFeature.getTerms().contains(newTerm));
473
474 for(Feature obj : vocNameFeature.getTerms()) {
475 Feature dtb = obj;
476 if("CreateTest".equals(dtb.getLabel())) {
477 newTerm = dtb;
478 Assert.assertNotNull(dtb.getCreatedBy());
479 Assert.assertNotNull(dtb.getCreated());
480 } else {
481 System.err.println(dtb.getLabel() + " " + dtb.getCreatedBy() + " " + dtb.getUuid());
482 Assert.assertNull(dtb.getCreatedBy());
483 }
484 }
485 newTerm.setLabel("UpdateTest");
486 newTerm = (Feature)termService.merge(newTerm);
487 Assert.assertNotNull(newTerm.getUpdatedBy());
488 Assert.assertNotNull(newTerm.getUpdated());
489
490 Assert.assertNull(vocNameFeature.getCreatedBy());
491 Assert.assertNull(vocFeature.getCreatedBy());
492 } finally {
493 if(termService.find(newTerm.getUuid()) != null) {
494 termService.delete(newTerm.getUuid());
495 }
496 }
497 }
498
499 @Test
500 public void updatePerson() {
501 // Test for #5138
502 Person person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().load(personUuid);
503 person.setGivenName("Me");
504 CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person, true);
505 }
506
507 @Test
508 public void createPerson() {
509 // Test for #5138
510 Person person = Person.NewInstance();
511 person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person);
512 person = (Person) CdmApplicationState.getCurrentAppConfig().getAgentService().load(person.getUuid());
513 person.setGivenName("Some");
514 CdmApplicationState.getCurrentAppConfig().getAgentService().merge(person, true);
515 }
516
517 @Test
518 public void testThreadLocalActiveSession() {
519 MockSessionOwner<CdmBase> so1 = new MockSessionOwner<>();
520 final ICdmEntitySession activeSession = getCdmEntitySessionManager().newSession(so1, true);
521 TestThread thread = new TestThread(true) {
522 @Override
523 public void doRun() throws InterruptedException {
524 ICdmEntitySession threadLocalActiveSession = getCdmEntitySessionManager().getActiveSession();
525 Assert.assertEquals(threadLocalActiveSession, activeSession);
526 }
527 };
528 invokeThread(thread);
529 MockSessionOwner<CdmBase> so2 = new MockSessionOwner<>();
530 ICdmEntitySession newActiveSession = getCdmEntitySessionManager().newSession(so2, true);
531 Assert.assertFalse(activeSession.equals(newActiveSession));
532 thread.unblock();
533
534 }
535 }