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
.Iterator
;
13 import java
.util
.List
;
16 import java
.util
.UUID
;
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
;
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
;
60 public class CdmEntitySessionAwareTest
extends RemotingSessionAwareTest
{
62 @SuppressWarnings("unused")
63 private static final Logger logger
= LogManager
.getLogger(CdmEntitySessionAwareTest
.class);
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");
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();
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"));
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();
92 Assert
.assertEquals("Achillea sec. Cyprus", taxon
.getTitleCache());
93 Assert
.assertEquals(tsItr
.hasNext(), false);
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");
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");
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");
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);
118 // TODO : Add tests for Annotations , Markers
122 public void testReadPolytomousKeyDataFromNodes() {
123 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
), PolytomousKey
.class);
124 PolytomousKeyNode rootNode
= pKey
.getRoot();
126 Assert
.assertEquals(2750, rootNode
.getId());
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()));
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()));
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());
156 public void testAddGrandChildPolytomousKeyNode() {
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();
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);
180 //grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
181 //KeyStatement ks = grandChildNode.getStatement();
182 Assert
.assertTrue(0 != ks
.getId());
186 public void testAddGreatGrandChildPolytomousKeyNode() {
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
);
193 polytomousKeyNodeService
.merge(grandChildNode
, true);
195 Assert
.assertFalse(pKey
.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
199 public void testSavePolytomousKeyNodeData() {
200 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
202 PolytomousKeyNode pkeynode
= pkey
.getRoot();
203 String newQuestion
= "New Question";
204 String newStatement
= "New Statement";
206 Assert
.assertEquals("Question 1",pkeynode
.getQuestion().getLabel().get(Language
.ENGLISH()).getText());
207 for(PolytomousKeyNode node
: pkeynode
.getChildren()) {
209 node
.setQuestion(null);
210 node
.setStatement(null);
212 //FIXME:Remoting Add tests for feature after fixing problem
214 //Feature feature = pkeynode.getFeature();
215 //Assert.assertEquals(feature.getTitleCache(),"Systematics");
216 //pkeynode.setFeature(null);
218 Assert
.assertEquals(pkeynode
.getChildAt(0).getModifyingText().get(Language
.ENGLISH()).getText(),"Modifying Text 1a");
219 String modifyingText
= "Modifying Text 1a updated";
221 //pkeynode.getChildAt(0).putModifyingText(Language.ENGLISH(), modifyingText);
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
);
229 polytomousKeyService
.merge(pkey
, true);
231 pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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
));
241 Assert
.assertEquals(pkeynode
.getChildAt(1).getTaxon(), taxon
);
243 polytomousKeyService
.merge(pkey
, true);
245 pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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());
255 //Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
259 public void testSavePolytomousKeyNodeDataWithSameSubKey() {
261 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
263 PolytomousKeyNode pkeynode
= pkey
.getRoot();
265 PolytomousKey subkey1
= CdmBase
.deproxy(pkeynode
.getChildAt(0).getSubkey(), PolytomousKey
.class);
266 String subkey1title
= subkey1
.getTitleCache();
267 subkey1
.setTitleCache(subkey1title
+ "test", true);
269 PolytomousKey subkey2
= CdmBase
.deproxy(pkeynode
.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey
.class);
270 String subkey2title
= subkey2
.getTitleCache();
271 subkey2
.setTitleCache(subkey2title
+ "test", true);
273 Assert
.assertSame(subkey1
, subkey2
);
275 polytomousKeyService
.merge(pkey
, true);
279 public void testSavePolytomousKeyNodeDataWithSameSubKeyUsingService() {
281 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
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);
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);
296 Assert
.assertNotSame(childNode0
, childNode1
);
298 Assert
.assertSame(subkey1
, subkey2
);
300 polytomousKeyService
.merge(pkey
, true);
304 public void testSavePolytomousKeyNodeDataWithSameLanguageInLabel() {
306 PolytomousKey pkey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
307 PolytomousKeyNode pkeynode
= pkey
.getRoot();
309 Map
<Language
, LanguageString
> label1
= pkeynode
.getQuestion().getLabel();
312 Map
<Language
, LanguageString
> label2
= pkeynode
.getChildAt(0).getStatement().getLabel();
315 polytomousKeyService
.merge(pkey
, true);
319 public void testDeleteSubKeyInPolytomousSubKeyWithoutInitializing() {
320 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
322 PolytomousKeyNode rootNode
= pKey
.getRoot();
324 PolytomousKeyNode childNode
= rootNode
.getChildAt(0);
325 PolytomousKey subKey
= HibernateProxyHelper
.deproxy( childNode
.getSubkey(), PolytomousKey
.class);;
327 DeleteResult result
= polytomousKeyService
.delete(subKey
.getUuid());
328 //A used subKey can't be deleted
333 List
<Integer
> ids
= new ArrayList
<>();
337 List
<PolytomousKeyNode
> nodes
= polytomousKeyNodeService
.loadByIds(ids
, null);
338 for (PolytomousKeyNode child
:nodes
){
339 child
.setSubkey(null);
340 // polytomousKeyNodeService.merge(child);
342 polytomousKeyNodeService
.merge(nodes
, true);
343 result
= polytomousKeyService
.delete(subKey
.getUuid());
348 // retrieving subkey shows its null
349 subKey
= CdmBase
.deproxy(polytomousKeyService
.find(subKeyUuid
),PolytomousKey
.class);
350 Assert
.assertNull(subKey
);
352 pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
357 public void testDeleteSubKeyInPolytomousNode() {
358 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
360 PolytomousKeyNode rootNode
= pKey
.getRoot();
361 List
<PolytomousKeyNode
> children
= rootNode
.getChildren();
362 PolytomousKeyNode child
= rootNode
.getChildAt(0);
363 polytomousKeyNodeService
.delete(child
.getUuid(), true);
365 pKey
= CdmBase
.deproxy(polytomousKeyService
.load(polytomousKeyUuid
),PolytomousKey
.class);
367 rootNode
= pKey
.getRoot();
368 children
= rootNode
.getChildren();
369 Assert
.assertFalse(children
.contains(child
));
373 public void testDeleteSubKeyInPolytomousSubKeyAfterInitializing() {
375 PolytomousKey pKey
= CdmBase
.deproxy(polytomousKeyService
.find(polytomousKeyUuid
),PolytomousKey
.class);
377 PolytomousKeyNode rootNode
= pKey
.getRoot();
378 PolytomousKeyNode child
= rootNode
.getChildAt(0);
379 PolytomousKey subKey
= child
.getSubkey();
380 // this call initializes the subkey
383 polytomousKeyService
.delete(subKey
);
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
390 PolytomousKeyNode subKeyRootNode
= subKey
.getRoot();
391 Assert
.assertNotNull(subKey
);
395 public void testSaveNewTermVocabulary() {
396 TermVocabulary
<Feature
> termVocabulary
=
397 TermVocabulary
.NewInstance(TermType
.Feature
,
404 List
<TermVocabulary
<?
extends DefinedTermBase
<?
>>> vocabularies
= (List
)vocabularyService
.findByTermType(TermType
.Feature
, null);
406 for(TermVocabulary
<?
> vocab
: vocabularies
) {
407 vocab
.getTermsOrderedByLabels(Language
.ENGLISH());
410 termVocabulary
= vocabularyService
.merge(termVocabulary
);
411 vocabularies
.add(termVocabulary
);
412 termVocabulary
.setLabel("Test");
413 vocabularyService
.merge(new ArrayList
<>(vocabularies
));
415 vocabularyService
.delete(termVocabulary
);
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");
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());
434 termService
.delete(updateTerms
);
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());
443 Assert
.assertNotNull(newTerm
);
444 @SuppressWarnings("unchecked")
445 TermVocabulary
<Feature
> vocNameFeature
= vocabularyService
.find(vocNameFeatureUuid
);
446 @SuppressWarnings("unchecked")
447 TermVocabulary
<Feature
> vocFeature
= vocabularyService
.find(vocFeatureUuid
);
449 @SuppressWarnings("rawtypes")
450 List
<TermVocabulary
> vocs
= new ArrayList
<>();
452 vocs
.add(vocNameFeature
);
453 vocs
.add(vocFeature
);
455 vocNameFeature
.addTerm(newTerm
);
457 @SuppressWarnings({ "unchecked", "rawtypes"})
458 List
<MergeResult
<TermVocabulary
<Feature
>>> mergeResults
= (List
)vocabularyService
.merge(vocs
, true);
460 for(MergeResult
<TermVocabulary
<Feature
>> result
: mergeResults
){
461 TermVocabulary
<Feature
> voc
= result
.getMergedEntity();
462 if(voc
.getUuid().equals(vocNameFeatureUuid
)) {
463 vocNameFeature
= voc
;
467 Assert
.assertTrue(vocNameFeature
.getTerms().contains(newTerm
));
469 for(Feature obj
: vocNameFeature
.getTerms()) {
471 if("CreateTest".equals(dtb
.getLabel())) {
473 Assert
.assertNotNull(dtb
.getCreatedBy());
474 Assert
.assertNotNull(dtb
.getCreated());
476 System
.err
.println(dtb
.getLabel() + " " + dtb
.getCreatedBy() + " " + dtb
.getUuid());
477 Assert
.assertNull(dtb
.getCreatedBy());
480 newTerm
.setLabel("UpdateTest");
481 newTerm
= (Feature
)termService
.merge(newTerm
);
482 Assert
.assertNotNull(newTerm
.getUpdatedBy());
483 Assert
.assertNotNull(newTerm
.getUpdated());
485 Assert
.assertNull(vocNameFeature
.getCreatedBy());
486 Assert
.assertNull(vocFeature
.getCreatedBy());
488 if(termService
.find(newTerm
.getUuid()) != null) {
489 termService
.delete(newTerm
.getUuid());
495 public void testUpdatePerson() {
497 Person person
= (Person
) CdmApplicationState
.getCurrentAppConfig().getAgentService().load(personUuid
);
498 person
.setGivenName("Me");
499 CdmApplicationState
.getCurrentAppConfig().getAgentService().merge(person
, true);
503 public void testCreatePerson() {
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);
513 public void testThreadLocalActiveSession() {
514 MockSessionOwner
<CdmBase
> so1
= new MockSessionOwner
<>();
515 final ICdmEntitySession activeSession
= getCdmEntitySessionManager().newSession(so1
, true);
516 TestThread thread
= new TestThread(true) {
518 public void doRun() throws InterruptedException
{
519 ICdmEntitySession threadLocalActiveSession
= getCdmEntitySessionManager().getActiveSession();
520 Assert
.assertEquals(threadLocalActiveSession
, activeSession
);
523 invokeThread(thread
);
524 MockSessionOwner
<CdmBase
> so2
= new MockSessionOwner
<>();
525 ICdmEntitySession newActiveSession
= getCdmEntitySessionManager().newSession(so2
, true);
526 Assert
.assertFalse(activeSession
.equals(newActiveSession
));