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