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.
10 package eu
.etaxonomy
.taxeditor
.lazyloading
;
12 import java
.util
.Arrays
;
13 import java
.util
.HashSet
;
14 import java
.util
.Iterator
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.apache
.log4j
.Level
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.junit
.Assert
;
22 import org
.junit
.BeforeClass
;
23 import org
.junit
.Ignore
;
24 import org
.junit
.Test
;
26 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
28 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
29 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
38 import eu
.etaxonomy
.taxeditor
.httpinvoker
.BaseRemotingTest
;
43 * Test class which tests remoting for persistent cdm entities.
45 * FIXME:Remoting saving tests are ignored until the merge development is underway
50 public class RemoteLazyLoadingTest
extends BaseRemotingTest
{
52 private static final Logger logger
= Logger
.getLogger(RemoteLazyLoadingTest
.class);
54 private static IClassificationService classificationService
;
55 private static ITaxonService taxonService
;
57 private static List
<TaxonNode
> taxonNodes
;
59 private final UUID taxonUuid1
= UUID
.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
60 private final UUID taxonUuid2
= UUID
.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
64 public static void initializeRemoteLazyLoading() {
66 Logger
.getRootLogger().setLevel(Level
.DEBUG
);
67 taxonService
= getRemoteApplicationController().getTaxonService();
69 classificationService
= getRemoteApplicationController().getClassificationService();
70 //List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
71 // Assert.assertFalse(classifications.isEmpty());
73 // Classification classification = classifications.get(0);
74 // Assert.assertNotNull(classification);
75 taxonNodes
= classificationService
.getAllNodes();
76 Assert
.assertFalse(taxonNodes
.isEmpty());
83 public void testCDMEntityGet() {
84 Iterator
<TaxonNode
> taxonNodeItr
= taxonNodes
.iterator();
87 while(taxonNodeItr
.hasNext() && count
<= maxcount
) {
88 TaxonNode taxonNode
= taxonNodeItr
.next();
89 Assert
.assertNotNull(taxonNode
);
91 Taxon taxon
= taxonNode
.getTaxon();
92 Assert
.assertNotNull(taxon
);
94 String taxonTitle
= taxon
.getTitleCache();
95 logger
.info("Taxon : " + taxonTitle
);
97 TaxonNameBase name
= taxon
.getName();
98 Assert
.assertNotNull(name
);
100 String nameTitle
= name
.getTitleCache();
101 logger
.info("Taxon Name : " + nameTitle
);
115 public void testCDMEntitySaveEager() {
116 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
117 String oldTitleCache
= taxon
.getTitleCache();
119 System
.out
.println("Taxon title : " + oldTitleCache
);
121 taxon
.setTitleCache(oldTitleCache
+ ":updated");
122 taxonService
.merge(taxon
);
124 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
125 System
.out
.println("New Taxon Title : " + taxonNew
.getTitleCache());
127 Assert
.assertNotEquals("Title caches should not be equal",oldTitleCache
,taxonNew
.getTitleCache());
129 taxonNew
.setTitleCache(oldTitleCache
);
130 taxonService
.merge(taxonNew
);
132 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
133 System
.out
.println("Old Taxon Title : " + taxonOld
.getTitleCache());
135 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,taxonOld
.getTitleCache());
141 public void testCDMEntityUpdate() {
143 Team combAuthor
= Team
.NewInstance();
144 combAuthor
.addTeamMember(Person
.NewTitledInstance("test member"));
145 BotanicalName name
= BotanicalName
.NewInstance(null, "Test1", null, null, null, null, null, null, null);
146 name
.setCombinationAuthorTeam(combAuthor
);
147 Taxon taxon
= Taxon
.NewInstance(name
, null);
148 UUID taxonUuid
= taxonService
.save(taxon
);
150 // Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
151 // NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class);
152 // String oldTitleCache = nvn.getTitleCache();
153 // System.out.println("Taxon Name Title : " + oldTitleCache);
154 // nvn.setTitleCache(oldTitleCache + ":updated", true);
156 // taxon.setTitleCache(oldTitleCache + ":updated",true);
158 // taxonService.update(taxon);
159 // } catch (LazyInitializationException lie) {
160 // lie.printStackTrace();
163 List
<String
> TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[] {
166 Taxon taxonNew
= (Taxon
)taxonService
.findTaxonByUuid(taxonUuid
,TAXON_INIT_STRATEGY
);
167 NonViralName nvn
= CdmBase
.deproxy(taxonNew
.getName(),NonViralName
.class);
168 Team team
= CdmBase
.deproxy(nvn
.getCombinationAuthorTeam(),Team
.class);
169 String oldTitleCache
= nvn
.getTitleCache();
170 System
.out
.println("Taxon Name Title : " + oldTitleCache
);
171 nvn
.setTitleCache(oldTitleCache
+ ":updated", true);
172 taxonService
.update(taxonNew
);
178 public void testCDMEntitySaveLazy() {
179 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
181 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
182 String oldTitleCache
= nvn
.getTitleCache();
183 System
.out
.println("Taxon Name Title : " + oldTitleCache
);
184 nvn
.setTitleCache(oldTitleCache
+ ":updated", true);
185 taxonService
.update(taxon
);
187 // Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
188 // NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class);
189 // System.out.println("New Taxon Name Title : " + nvnNew.getTitleCache());
191 // Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,nvnNew.getTitleCache());
193 // nvnNew.setTitleCache(oldTitleCache, true);
194 // taxonService.update(taxon);
196 // Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
197 // NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class);
198 // System.out.println("Old Taxon Name Title : " + nvnNew.getTitleCache());
200 // Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache());
204 public void testCDMEntitySaveLazyNew() {
205 Team combAuthor
= Team
.NewInstance();
206 combAuthor
.addTeamMember(Person
.NewTitledInstance("test member"));
207 BotanicalName name
= BotanicalName
.NewInstance(null, "Test1", null, null, null, null, null, null, null);
208 name
.setCombinationAuthorTeam(combAuthor
);
209 Taxon tax1
= Taxon
.NewInstance(name
, null);
210 UUID taxonUuid1
= taxonService
.save(tax1
);
212 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
214 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
215 String oldTitleCache
= nvn
.getTitleCache();
216 logger
.info("Taxon Name Title : " + oldTitleCache
);
217 nvn
.setTitleCache(oldTitleCache
+ ":updated",false);
218 taxonService
.update(taxon
);
220 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
221 NonViralName nvnNew
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
222 logger
.info("New Taxon Name Title : " + nvnNew
.getTitleCache());
224 Assert
.assertNotEquals("Title caches should not be equal",oldTitleCache
,nvnNew
.getTitleCache());
226 nvnNew
.setTitleCache(oldTitleCache
, true);
227 taxonService
.update(taxon
);
229 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
230 NonViralName nvnOld
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
231 logger
.info("Old Taxon Name Title : " + nvnNew
.getTitleCache());
233 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,nvnOld
.getTitleCache());
237 public void testCDMEntitySaveCollection() {
238 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
240 Set
<SynonymRelationship
> synRelations
= taxon
.getSynonymRelations();
241 Set
<String
> relToTitles
= new HashSet
<String
>();
242 Iterator
<SynonymRelationship
> srItr
= synRelations
.iterator();
243 while(srItr
.hasNext()) {
244 SynonymRelationship sr
= srItr
.next();
245 System
.out
.println("Synonym Title Cache : " + sr
.getSynonym().getTitleCache());
246 relToTitles
.add(sr
.getSynonym().getTitleCache());
247 sr
.getSynonym().setTitleCache(sr
.getSynonym().getTitleCache() + ":updated");
250 taxonService
.merge(taxon
);
252 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
253 Set
<SynonymRelationship
> synRelationsNew
= taxonNew
.getSynonymRelations();
255 Iterator
<SynonymRelationship
> srItrNew
= synRelationsNew
.iterator();
256 Iterator
<String
> relToTitlesItr
= relToTitles
.iterator();
257 while(srItrNew
.hasNext() && relToTitlesItr
.hasNext()) {
258 SynonymRelationship srNew
= srItrNew
.next();
259 String relToTitle
= relToTitlesItr
.next();
260 System
.out
.println("New Synonym Title Cache: " + srNew
.getSynonym().getTitleCache());
261 Assert
.assertNotEquals("Synonym Title caches should not be equal", srNew
.getSynonym().getTitleCache(), relToTitle
);
262 srNew
.getSynonym().setTitleCache(relToTitle
);
265 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
267 Set
<SynonymRelationship
> synRelationsOld
= taxonNew
.getSynonymRelations();
268 Iterator
<SynonymRelationship
> srItrOld
= synRelationsOld
.iterator();
269 relToTitlesItr
= relToTitles
.iterator();
270 while(srItrOld
.hasNext() && relToTitlesItr
.hasNext()) {
271 SynonymRelationship srOld
= srItrOld
.next();
272 String relToTitle
= relToTitlesItr
.next();
273 System
.out
.println("New Synonym Title Cache: " + srOld
.getSynonym().getTitleCache());
274 Assert
.assertEquals("Synonym Title caches should be equal", srOld
.getSynonym().getTitleCache(), relToTitle
);