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
.Logger
;
20 import org
.junit
.Assert
;
21 import org
.junit
.BeforeClass
;
22 import org
.junit
.Ignore
;
23 import org
.junit
.Test
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
27 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
28 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
31 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
36 import eu
.etaxonomy
.taxeditor
.httpinvoker
.BaseRemotingTest
;
41 * Test class which tests remoting for persistent cdm entities.
43 * FIXME:Remoting saving tests are ignored until the merge development is underway
47 //FIXME:Remoting need to create a proper dataset for this test
48 //Could be combined with AbstractLazyInitializerTest
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() {
65 taxonService
= getRemoteApplicationController().getTaxonService();
67 classificationService
= getRemoteApplicationController().getClassificationService();
68 //List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
69 // Assert.assertFalse(classifications.isEmpty());
71 // Classification classification = classifications.get(0);
72 // Assert.assertNotNull(classification);
73 taxonNodes
= classificationService
.getAllNodes();
74 Assert
.assertFalse(taxonNodes
.isEmpty());
81 public void testCDMEntityGet() {
82 Iterator
<TaxonNode
> taxonNodeItr
= taxonNodes
.iterator();
85 while(taxonNodeItr
.hasNext() && count
<= maxcount
) {
86 TaxonNode taxonNode
= taxonNodeItr
.next();
87 Assert
.assertNotNull(taxonNode
);
89 Taxon taxon
= taxonNode
.getTaxon();
90 Assert
.assertNotNull(taxon
);
92 String taxonTitle
= taxon
.getTitleCache();
93 logger
.info("Taxon : " + taxonTitle
);
95 TaxonNameBase name
= taxon
.getName();
96 Assert
.assertNotNull(name
);
98 String nameTitle
= name
.getTitleCache();
99 logger
.info("Taxon Name : " + nameTitle
);
113 public void testCDMEntitySaveEager() {
114 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
115 String oldTitleCache
= taxon
.getTitleCache();
117 System
.out
.println("Taxon title : " + oldTitleCache
);
119 taxon
.setTitleCache(oldTitleCache
+ ":updated");
120 taxonService
.merge(taxon
);
122 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
123 System
.out
.println("New Taxon Title : " + taxonNew
.getTitleCache());
125 Assert
.assertTrue("Title caches should not be equal",oldTitleCache
.equals(taxonNew
.getTitleCache()));
127 taxonNew
.setTitleCache(oldTitleCache
);
128 taxonService
.merge(taxonNew
);
130 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
131 System
.out
.println("Old Taxon Title : " + taxonOld
.getTitleCache());
133 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,taxonOld
.getTitleCache());
139 public void testCDMEntityUpdate() {
141 Team combAuthor
= Team
.NewInstance();
142 combAuthor
.addTeamMember(Person
.NewTitledInstance("test member"));
143 BotanicalName name
= BotanicalName
.NewInstance(null, "Test1", null, null, null, null, null, null, null);
144 name
.setCombinationAuthorship(combAuthor
);
145 Taxon taxon
= Taxon
.NewInstance(name
, null);
146 UUID taxonUuid
= taxonService
.save(taxon
).getUuid();
148 // Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
149 // NonViralName nvn = CdmBase.deproxy(taxon.getName(),NonViralName.class);
150 // String oldTitleCache = nvn.getTitleCache();
151 // System.out.println("Taxon Name Title : " + oldTitleCache);
152 // nvn.setTitleCache(oldTitleCache + ":updated", true);
154 // taxon.setTitleCache(oldTitleCache + ":updated",true);
156 // taxonService.update(taxon);
157 // } catch (LazyInitializationException lie) {
158 // lie.printStackTrace();
161 List
<String
> TAXON_INIT_STRATEGY
= Arrays
.asList(new String
[] {
164 Taxon taxonNew
= (Taxon
)taxonService
.findTaxonByUuid(taxonUuid
,TAXON_INIT_STRATEGY
);
165 NonViralName nvn
= CdmBase
.deproxy(taxonNew
.getName(),NonViralName
.class);
166 Team team
= CdmBase
.deproxy(nvn
.getCombinationAuthorship(),Team
.class);
167 String oldTitleCache
= nvn
.getTitleCache();
168 System
.out
.println("Taxon Name Title : " + oldTitleCache
);
169 nvn
.setTitleCache(oldTitleCache
+ ":updated", true);
170 taxonService
.update(taxonNew
);
176 public void testCDMEntitySaveLazy() {
177 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
179 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
180 String oldTitleCache
= nvn
.getTitleCache();
181 System
.out
.println("Taxon Name Title : " + oldTitleCache
);
182 nvn
.setTitleCache(oldTitleCache
+ ":updated", true);
183 taxonService
.update(taxon
);
185 // Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
186 // NonViralName nvnNew = CdmBase.deproxy(taxon.getName(),NonViralName.class);
187 // System.out.println("New Taxon Name Title : " + nvnNew.getTitleCache());
189 // Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,nvnNew.getTitleCache());
191 // nvnNew.setTitleCache(oldTitleCache, true);
192 // taxonService.update(taxon);
194 // Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
195 // NonViralName nvnOld = CdmBase.deproxy(taxon.getName(),NonViralName.class);
196 // System.out.println("Old Taxon Name Title : " + nvnNew.getTitleCache());
198 // Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache());
202 public void testCDMEntitySaveLazyNew() {
203 Team combAuthor
= Team
.NewInstance();
204 combAuthor
.addTeamMember(Person
.NewTitledInstance("test member"));
205 BotanicalName name
= BotanicalName
.NewInstance(null, "Test1", null, null, null, null, null, null, null);
206 name
.setCombinationAuthorship(combAuthor
);
207 Taxon tax1
= Taxon
.NewInstance(name
, null);
208 UUID taxonUuid1
= taxonService
.save(tax1
).getUuid();
210 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
212 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
213 String oldTitleCache
= nvn
.getTitleCache();
214 logger
.info("Taxon Name Title : " + oldTitleCache
);
215 nvn
.setTitleCache(oldTitleCache
+ ":updated",false);
216 taxonService
.update(taxon
);
218 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
219 NonViralName nvnNew
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
220 logger
.info("New Taxon Name Title : " + nvnNew
.getTitleCache());
222 Assert
.assertTrue("Title caches should not be equal",oldTitleCache
.equals(nvnNew
.getTitleCache()));
224 nvnNew
.setTitleCache(oldTitleCache
, true);
225 taxonService
.update(taxon
);
227 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
228 NonViralName nvnOld
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
229 logger
.info("Old Taxon Name Title : " + nvnNew
.getTitleCache());
231 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,nvnOld
.getTitleCache());
235 public void testCDMEntitySaveCollection() {
236 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
238 Set
<SynonymRelationship
> synRelations
= taxon
.getSynonymRelations();
239 Set
<String
> relToTitles
= new HashSet
<String
>();
240 Iterator
<SynonymRelationship
> srItr
= synRelations
.iterator();
241 while(srItr
.hasNext()) {
242 SynonymRelationship sr
= srItr
.next();
243 System
.out
.println("Synonym Title Cache : " + sr
.getSynonym().getTitleCache());
244 relToTitles
.add(sr
.getSynonym().getTitleCache());
245 sr
.getSynonym().setTitleCache(sr
.getSynonym().getTitleCache() + ":updated");
248 taxonService
.merge(taxon
);
250 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
251 Set
<SynonymRelationship
> synRelationsNew
= taxonNew
.getSynonymRelations();
253 Iterator
<SynonymRelationship
> srItrNew
= synRelationsNew
.iterator();
254 Iterator
<String
> relToTitlesItr
= relToTitles
.iterator();
255 while(srItrNew
.hasNext() && relToTitlesItr
.hasNext()) {
256 SynonymRelationship srNew
= srItrNew
.next();
257 String relToTitle
= relToTitlesItr
.next();
258 System
.out
.println("New Synonym Title Cache: " + srNew
.getSynonym().getTitleCache());
259 Assert
.assertTrue("Synonym Title caches should not be equal", srNew
.getSynonym().getTitleCache().equals(relToTitle
));
260 srNew
.getSynonym().setTitleCache(relToTitle
);
263 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
265 Set
<SynonymRelationship
> synRelationsOld
= taxonNew
.getSynonymRelations();
266 Iterator
<SynonymRelationship
> srItrOld
= synRelationsOld
.iterator();
267 relToTitlesItr
= relToTitles
.iterator();
268 while(srItrOld
.hasNext() && relToTitlesItr
.hasNext()) {
269 SynonymRelationship srOld
= srItrOld
.next();
270 String relToTitle
= relToTitlesItr
.next();
271 System
.out
.println("New Synonym Title Cache: " + srOld
.getSynonym().getTitleCache());
272 Assert
.assertEquals("Synonym Title caches should be equal", srOld
.getSynonym().getTitleCache(), relToTitle
);