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
.IBotanicalName
;
31 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
38 import eu
.etaxonomy
.taxeditor
.httpinvoker
.BaseRemotingTest
;
41 * Class to test the {@link CdmApplicationRemoteController}
43 // FIXME:Remoting need to create a proper dataset for this test
44 // Could be combined with RemotePersistentCollectionTest
47 public class AbstractLazyInitializerTest
extends BaseRemotingTest
{
48 private static final Logger logger
= Logger
.getLogger(AbstractLazyInitializerTest
.class);
50 private static IClassificationService classificationService
;
51 private static ITaxonService taxonService
;
53 private static List
<TaxonNode
> taxonNodes
;
55 private final UUID taxonUuid1
= UUID
.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
56 private final UUID taxonUuid2
= UUID
.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
60 public static void initializeRemoteLazyLoading() {
62 taxonService
= getRemoteApplicationController().getTaxonService();
63 classificationService
= getRemoteApplicationController().getClassificationService();
64 List
<Classification
> classifications
= classificationService
.listClassifications(1,0,null,null);
65 Assert
.assertFalse(classifications
.isEmpty());
67 Classification classification
= classifications
.get(0);
68 Assert
.assertNotNull(classification
);
69 taxonNodes
= classificationService
.getAllNodes();
70 Assert
.assertFalse(taxonNodes
.isEmpty());
77 public void testCDMEntityGet() {
78 //ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
79 Iterator
<TaxonNode
> taxonNodeItr
= taxonNodes
.iterator();
82 while(taxonNodeItr
.hasNext() && count
<= maxcount
) {
83 TaxonNode taxonNode
= taxonNodeItr
.next();
84 Assert
.assertNotNull(taxonNode
);
86 Taxon taxon
= taxonNode
.getTaxon();
87 Assert
.assertNotNull(taxon
);
89 String taxonTitle
= taxon
.getTitleCache();
90 logger
.info("Taxon : " + taxonTitle
);
92 TaxonName name
= taxon
.getName();
93 Assert
.assertNotNull(name
);
95 String nameTitle
= name
.getTitleCache();
96 logger
.info("Taxon Name : " + nameTitle
);
103 public void taxonReadTest() {
104 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
108 public void testCDMEntitySave() {
109 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
110 String oldTitleCache
= taxon
.getTitleCache();
112 System
.out
.println("Taxon title : " + oldTitleCache
);
114 taxon
.setTitleCache(oldTitleCache
+ ":updated", true);
115 taxonService
.merge(taxon
);
117 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
118 System
.out
.println("New Taxon Title : " + taxonNew
.getTitleCache());
120 Assert
.assertTrue("Title caches should not be equal",oldTitleCache
.equals(taxonNew
.getTitleCache()));
123 taxonNew
.setTitleCache(oldTitleCache
, true);
124 taxonService
.merge(taxonNew
);
126 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
127 System
.out
.println("Old Taxon Title : " + taxonOld
.getTitleCache());
129 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,taxonOld
.getTitleCache());
134 public void testCDMEntitySaveLazyNew() {
135 Team combAuthor
= Team
.NewInstance();
136 combAuthor
.addTeamMember(Person
.NewTitledInstance("test member"));
137 IBotanicalName name
= TaxonNameFactory
.NewBotanicalInstance(null, "Test1", null, null, null, null, null, null, null);
138 name
.setCombinationAuthorship(combAuthor
);
139 Taxon tax1
= Taxon
.NewInstance(name
, null);
140 UUID taxonUuid1
= taxonService
.save(tax1
).getUuid();
142 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
144 INonViralName nvn
= CdmBase
.deproxy(taxon
.getName());
145 String oldTitleCache
= nvn
.getTitleCache();
146 logger
.info("Taxon Name Title : " + oldTitleCache
);
147 nvn
.setTitleCache(oldTitleCache
+ ":updated",false);
148 taxonService
.update(taxon
);
150 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
151 INonViralName nvnNew
= CdmBase
.deproxy(taxon
.getName());
152 logger
.info("New Taxon Name Title : " + nvnNew
.getTitleCache());
154 Assert
.assertTrue("Title caches should not be equal",oldTitleCache
.equals(nvnNew
.getTitleCache()));
156 nvnNew
.setTitleCache(oldTitleCache
, true);
157 taxonService
.update(taxon
);
159 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
160 INonViralName nvnOld
= CdmBase
.deproxy(taxon
.getName());
161 logger
.info("Old Taxon Name Title : " + nvnNew
.getTitleCache());
163 Assert
.assertEquals("Title caches should be equal",oldTitleCache
, nvnOld
.getTitleCache());
168 public void testCdmEntitySaveCollection() {
169 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
171 Set
<TaxonRelationship
> taxRelations
= taxon
.getTaxonRelations();
172 Set
<String
> relToTitles
= new HashSet
<String
>();
173 Iterator
<TaxonRelationship
> trItr
= taxRelations
.iterator();
174 while(trItr
.hasNext()) {
175 TaxonRelationship tr
= trItr
.next();
176 System
.out
.println("Synonym Title Cache : " + tr
.getFromTaxon().getTitleCache());
177 relToTitles
.add(tr
.getFromTaxon().getTitleCache());
178 tr
.getFromTaxon().setTitleCache(tr
.getFromTaxon().getTitleCache() + ":updated");
181 taxonService
.merge(taxon
);
183 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
184 Set
<TaxonRelationship
> taxRelationsNew
= taxonNew
.getTaxonRelations();
186 Iterator
<TaxonRelationship
> trItrNew
= taxRelationsNew
.iterator();
187 Iterator
<String
> relToTitlesItr
= relToTitles
.iterator();
188 while(trItrNew
.hasNext() && relToTitlesItr
.hasNext()) {
189 TaxonRelationship trNew
= trItrNew
.next();
190 String relToTitle
= relToTitlesItr
.next();
191 System
.out
.println("New Synonym Title Cache: " + trNew
.getFromTaxon().getTitleCache());
192 Assert
.assertTrue("Synonym Title caches should not be equal", trNew
.getFromTaxon().getTitleCache().equals(relToTitle
));
193 trNew
.getFromTaxon().setTitleCache(relToTitle
);
196 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
198 Set
<TaxonRelationship
> taxRelationsOld
= taxonNew
.getTaxonRelations();
199 Iterator
<TaxonRelationship
> trItrOld
= taxRelationsOld
.iterator();
200 relToTitlesItr
= relToTitles
.iterator();
201 while(trItrOld
.hasNext() && relToTitlesItr
.hasNext()) {
202 TaxonRelationship trOld
= trItrOld
.next();
203 String relToTitle
= relToTitlesItr
.next();
204 System
.out
.println("New Synonym Title Cache: " + trOld
.getFromTaxon().getTitleCache());
205 Assert
.assertEquals("Synonym Title caches should be equal", trOld
.getFromTaxon().getTitleCache(), relToTitle
);