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
.lazyloading
;
11 import java
.util
.HashSet
;
12 import java
.util
.Iterator
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.junit
.Assert
;
19 import org
.junit
.BeforeClass
;
20 import org
.junit
.Ignore
;
21 import org
.junit
.Test
;
22 import org
.unitils
.dbunit
.annotation
.DataSet
;
24 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteController
;
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
.Classification
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.taxeditor
.httpinvoker
.BaseRemotingTest
;
43 * Class to test the {@link CdmApplicationRemoteController}
46 // FIXME:Remoting need to create a proper dataset for this test
47 // Could be combined with RemotePersistentCollectionTest
50 public class AbstractLazyInitializerTest
extends BaseRemotingTest
{
51 private static final Logger logger
= Logger
.getLogger(AbstractLazyInitializerTest
.class);
53 private static IClassificationService classificationService
;
54 private static ITaxonService taxonService
;
56 private static List
<TaxonNode
> taxonNodes
;
58 private final UUID taxonUuid1
= UUID
.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
59 private final UUID taxonUuid2
= UUID
.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
63 public static void initializeRemoteLazyLoading() {
65 taxonService
= getRemoteApplicationController().getTaxonService();
66 classificationService
= getRemoteApplicationController().getClassificationService();
67 List
<Classification
> classifications
= classificationService
.listClassifications(1,0,null,null);
68 Assert
.assertFalse(classifications
.isEmpty());
70 Classification classification
= classifications
.get(0);
71 Assert
.assertNotNull(classification
);
72 taxonNodes
= classificationService
.getAllNodes();
73 Assert
.assertFalse(taxonNodes
.isEmpty());
80 public void testCDMEntityGet() {
81 //ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
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
);
106 public void taxonReadTest() {
107 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
113 public void testCDMEntitySave() {
114 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
115 String oldTitleCache
= taxon
.getTitleCache();
117 System
.out
.println("Taxon title : " + oldTitleCache
);
119 taxon
.setTitleCache(oldTitleCache
+ ":updated", true);
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()));
128 taxonNew
.setTitleCache(oldTitleCache
, true);
129 taxonService
.merge(taxonNew
);
131 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
132 System
.out
.println("Old Taxon Title : " + taxonOld
.getTitleCache());
134 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,taxonOld
.getTitleCache());
140 public void testCDMEntitySaveLazyNew() {
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 tax1
= Taxon
.NewInstance(name
, null);
146 UUID taxonUuid1
= taxonService
.save(tax1
).getUuid();
148 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
150 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
151 String oldTitleCache
= nvn
.getTitleCache();
152 logger
.info("Taxon Name Title : " + oldTitleCache
);
153 nvn
.setTitleCache(oldTitleCache
+ ":updated",false);
154 taxonService
.update(taxon
);
156 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
157 NonViralName nvnNew
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
158 logger
.info("New Taxon Name Title : " + nvnNew
.getTitleCache());
160 Assert
.assertTrue("Title caches should not be equal",oldTitleCache
.equals(nvnNew
.getTitleCache()));
162 nvnNew
.setTitleCache(oldTitleCache
, true);
163 taxonService
.update(taxon
);
165 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
166 NonViralName nvnOld
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
167 logger
.info("Old Taxon Name Title : " + nvnNew
.getTitleCache());
169 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,nvnOld
.getTitleCache());
174 public void testCDMEntitySaveCollection() {
175 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
177 Set
<SynonymRelationship
> synRelations
= taxon
.getSynonymRelations();
178 Set
<String
> relToTitles
= new HashSet
<String
>();
179 Iterator
<SynonymRelationship
> srItr
= synRelations
.iterator();
180 while(srItr
.hasNext()) {
181 SynonymRelationship sr
= srItr
.next();
182 System
.out
.println("Synonym Title Cache : " + sr
.getSynonym().getTitleCache());
183 relToTitles
.add(sr
.getSynonym().getTitleCache());
184 sr
.getSynonym().setTitleCache(sr
.getSynonym().getTitleCache() + ":updated");
187 taxonService
.merge(taxon
);
189 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
190 Set
<SynonymRelationship
> synRelationsNew
= taxonNew
.getSynonymRelations();
192 Iterator
<SynonymRelationship
> srItrNew
= synRelationsNew
.iterator();
193 Iterator
<String
> relToTitlesItr
= relToTitles
.iterator();
194 while(srItrNew
.hasNext() && relToTitlesItr
.hasNext()) {
195 SynonymRelationship srNew
= srItrNew
.next();
196 String relToTitle
= relToTitlesItr
.next();
197 System
.out
.println("New Synonym Title Cache: " + srNew
.getSynonym().getTitleCache());
198 Assert
.assertTrue("Synonym Title caches should not be equal", srNew
.getSynonym().getTitleCache().equals(relToTitle
));
199 srNew
.getSynonym().setTitleCache(relToTitle
);
202 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
204 Set
<SynonymRelationship
> synRelationsOld
= taxonNew
.getSynonymRelations();
205 Iterator
<SynonymRelationship
> srItrOld
= synRelationsOld
.iterator();
206 relToTitlesItr
= relToTitles
.iterator();
207 while(srItrOld
.hasNext() && relToTitlesItr
.hasNext()) {
208 SynonymRelationship srOld
= srItrOld
.next();
209 String relToTitle
= relToTitlesItr
.next();
210 System
.out
.println("New Synonym Title Cache: " + srOld
.getSynonym().getTitleCache());
211 Assert
.assertEquals("Synonym Title caches should be equal", srOld
.getSynonym().getTitleCache(), relToTitle
);