2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.session
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashSet
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
17 import java
.util
.UUID
;
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
;
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
;
62 public class CdmEntitySessionAwareTest
extends RemotingSessionAwareTest
{
64 @SuppressWarnings("unused")
65 private static final Logger logger
= LogManager
.getLogger(CdmEntitySessionAwareTest
.class);
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");
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();
81 //Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
84 public static void initializePolytomousKeyTest() {
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"));
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();
104 Assert
.assertEquals("Achillea sec. Cyprus", taxon
.getTitleCache());
105 Assert
.assertEquals(tsItr
.hasNext(), false);
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");
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");
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");
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);
130 // TO DO : Added tests for Annotations , Markers
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();
139 Assert
.assertEquals(rootNode
.getId(), 2750);
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
);
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
);
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");
169 public void addGrandChildPolytomousKeyNode() {
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
);
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);
184 //grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
185 //KeyStatement ks = grandChildNode.getStatement();
186 Assert
.assertTrue(0 != ks
.getId());
191 public void addGreatGrandChildPolytomousKeyNode() {
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
);
198 polytomousKeyNodeService
.merge(grandChildNode
, true);
200 Assert
.assertFalse(pKey
.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
204 public void savePolytomousKeyNodeData() {
205 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
207 PolytomousKeyNode pkeynode
= pkey
.getRoot();
208 String newQuestion
= "New Question";
209 String newStatement
= "New Statement";
211 Assert
.assertEquals("Question 1",pkeynode
.getQuestion().getLabel().get(Language
.ENGLISH()).getText());
212 for(PolytomousKeyNode node
: pkeynode
.getChildren()) {
214 node
.setQuestion(null);
215 node
.setStatement(null);
217 //FIXME:Remoting Add tests for feature after fixing problem
219 //Feature feature = pkeynode.getFeature();
220 //Assert.assertEquals(feature.getTitleCache(),"Systematics");
221 //pkeynode.setFeature(null);
223 Assert
.assertEquals(pkeynode
.getChildAt(0).getModifyingText().get(Language
.ENGLISH()).getText(),"Modifying Text 1a");
224 String modifyingText
= "Modifying Text 1a updated";
226 //pkeynode.getChildAt(0).putModifyingText(Language.ENGLISH(), modifyingText);
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
);
234 polytomousKeyService
.merge(pkey
, true);
236 pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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
));
246 Assert
.assertEquals(pkeynode
.getChildAt(1).getTaxon(), taxon
);
248 polytomousKeyService
.merge(pkey
, true);
250 pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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());
260 //Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
265 public void savePolytomousKeyNodeDataWithSameSubKey() {
267 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
269 PolytomousKeyNode pkeynode
= pkey
.getRoot();
271 PolytomousKey subkey1
= CdmBase
.deproxy(pkeynode
.getChildAt(0).getSubkey(), PolytomousKey
.class);
272 String subkey1title
= subkey1
.getTitleCache();
273 subkey1
.setTitleCache(subkey1title
+ "test", true);
275 PolytomousKey subkey2
= CdmBase
.deproxy(pkeynode
.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey
.class);
276 String subkey2title
= subkey2
.getTitleCache();
277 subkey2
.setTitleCache(subkey2title
+ "test", true);
279 Assert
.assertSame(subkey1
, subkey2
);
281 polytomousKeyService
.merge(pkey
, true);
285 public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
287 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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);
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);
302 Assert
.assertNotSame(childNode0
, childNode1
);
304 Assert
.assertSame(subkey1
, subkey2
);
306 polytomousKeyService
.merge(pkey
, true);
310 public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
312 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
313 PolytomousKeyNode pkeynode
= pkey
.getRoot();
315 Map
<Language
, LanguageString
> label1
= pkeynode
.getQuestion().getLabel();
318 Map
<Language
, LanguageString
> label2
= pkeynode
.getChildAt(0).getStatement().getLabel();
321 polytomousKeyService
.merge(pkey
, true);
325 public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() {
326 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
328 PolytomousKeyNode rootNode
= pKey
.getRoot();
330 PolytomousKeyNode childNode
= rootNode
.getChildAt(0);
331 PolytomousKey subKey
= HibernateProxyHelper
.deproxy( childNode
.getSubkey(), PolytomousKey
.class);;
333 DeleteResult result
= polytomousKeyService
.delete(subKey
.getUuid());
334 //A used subKey can't be deleted
339 Set
<Integer
> ids
= new HashSet
<Integer
>();
343 List
<PolytomousKeyNode
> nodes
= polytomousKeyNodeService
.findById(ids
);
344 for (PolytomousKeyNode child
:nodes
){
345 child
.setSubkey(null);
346 // polytomousKeyNodeService.merge(child);
348 polytomousKeyNodeService
.merge(nodes
, true);
349 result
= polytomousKeyService
.delete(subKey
.getUuid());
354 // retrieving subkey shows its null
355 subKey
= CdmBase
.deproxy(polytomousKeyService
.find(subKeyUuid
),PolytomousKey
.class);
356 Assert
.assertNull(subKey
);
358 pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
363 public void deleteSubKeyInPolytomousNode() {
364 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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);
372 pKey
= CdmBase
.deproxy(polytomousKeyService
.load(polytomousKeyUuid
),PolytomousKey
.class);
374 rootNode
= pKey
.getRoot();
375 children
= rootNode
.getChildren();
376 Assert
.assertFalse(children
.contains(child
));
380 public void deleteSubKeyInPolytomousSubKeyAfterInitializing() {
381 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
384 PolytomousKeyNode rootNode
= pKey
.getRoot();
385 PolytomousKeyNode child
= rootNode
.getChildAt(0);
386 PolytomousKey subKey
= child
.getSubkey();
387 // this call initializes the subkey
390 polytomousKeyService
.delete(subKey
);
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
397 PolytomousKeyNode subKeyRootNode
= subKey
.getRoot();
398 Assert
.assertNotNull(subKey
);
402 public void saveNewTermVocabulary() {
403 TermVocabulary
<Feature
> termVocabulary
=
404 TermVocabulary
.NewInstance(TermType
.Feature
,
410 List
<TermVocabulary
<?
extends DefinedTermBase
<?
>>> vocabularies
= (List
)vocabularyService
.findByTermType(TermType
.Feature
, null);
412 for(TermVocabulary
<?
> vocab
: vocabularies
) {
413 vocab
.getTermsOrderedByLabels(Language
.ENGLISH());
416 termVocabulary
= vocabularyService
.merge(termVocabulary
);
417 vocabularies
.add(termVocabulary
);
418 termVocabulary
.setLabel("Test");
419 vocabularyService
.merge(new ArrayList
<>(vocabularies
));
421 vocabularyService
.delete(termVocabulary
);
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");
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());
440 termService
.delete(updateTerms
);
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());
449 Assert
.assertNotNull(newTerm
);
450 @SuppressWarnings("unchecked")
451 TermVocabulary
<Feature
> vocNameFeature
= vocabularyService
.find(vocNameFeatureUuid
);
452 @SuppressWarnings("unchecked")
453 TermVocabulary
<Feature
> vocFeature
= vocabularyService
.find(vocFeatureUuid
);
455 @SuppressWarnings("rawtypes")
456 List
<TermVocabulary
> vocs
= new ArrayList
<>();
458 vocs
.add(vocNameFeature
);
459 vocs
.add(vocFeature
);
461 vocNameFeature
.addTerm(newTerm
);
463 List
<MergeResult
<TermVocabulary
<Feature
>>> mergeResults
= (List
)vocabularyService
.merge(vocs
, true);
465 for(MergeResult
<TermVocabulary
<Feature
>> result
: mergeResults
){
466 TermVocabulary
<Feature
> voc
= result
.getMergedEntity();
467 if(voc
.getUuid().equals(vocNameFeatureUuid
)) {
468 vocNameFeature
= voc
;
472 Assert
.assertTrue(vocNameFeature
.getTerms().contains(newTerm
));
474 for(Feature obj
: vocNameFeature
.getTerms()) {
476 if("CreateTest".equals(dtb
.getLabel())) {
478 Assert
.assertNotNull(dtb
.getCreatedBy());
479 Assert
.assertNotNull(dtb
.getCreated());
481 System
.err
.println(dtb
.getLabel() + " " + dtb
.getCreatedBy() + " " + dtb
.getUuid());
482 Assert
.assertNull(dtb
.getCreatedBy());
485 newTerm
.setLabel("UpdateTest");
486 newTerm
= (Feature
)termService
.merge(newTerm
);
487 Assert
.assertNotNull(newTerm
.getUpdatedBy());
488 Assert
.assertNotNull(newTerm
.getUpdated());
490 Assert
.assertNull(vocNameFeature
.getCreatedBy());
491 Assert
.assertNull(vocFeature
.getCreatedBy());
493 if(termService
.find(newTerm
.getUuid()) != null) {
494 termService
.delete(newTerm
.getUuid());
500 public void updatePerson() {
502 Person person
= (Person
) CdmApplicationState
.getCurrentAppConfig().getAgentService().load(personUuid
);
503 person
.setGivenName("Me");
504 CdmApplicationState
.getCurrentAppConfig().getAgentService().merge(person
, true);
508 public void createPerson() {
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);
518 public void testThreadLocalActiveSession() {
519 MockSessionOwner
<CdmBase
> so1
= new MockSessionOwner
<>();
520 final ICdmEntitySession activeSession
= getCdmEntitySessionManager().newSession(so1
, true);
521 TestThread thread
= new TestThread(true) {
523 public void doRun() throws InterruptedException
{
524 ICdmEntitySession threadLocalActiveSession
= getCdmEntitySessionManager().getActiveSession();
525 Assert
.assertEquals(threadLocalActiveSession
, activeSession
);
528 invokeThread(thread
);
529 MockSessionOwner
<CdmBase
> so2
= new MockSessionOwner
<>();
530 ICdmEntitySession newActiveSession
= getCdmEntitySessionManager().newSession(so2
, true);
531 Assert
.assertFalse(activeSession
.equals(newActiveSession
));