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
.remoting
;
12 import java
.util
.HashSet
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Level
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.junit
.Assert
;
21 import org
.junit
.BeforeClass
;
22 import org
.junit
.Test
;
23 import org
.junit
.Ignore
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
39 * Test class which tests remoting for persistent cdm entities.
41 * FIXME:Remoting saving tests are ignored until the merge development is underway
46 public class RemoteLazyLoadingTest
extends RemoteApplicationConfigurationTest
{
48 private static final Logger logger
= Logger
.getLogger(RemoteLazyLoadingTest
.class);
50 private static IClassificationService classificationService
;
51 private static ITaxonService taxonService
;
53 private static List
<TaxonNode
> taxonNodes
;
55 private UUID taxonUuid1
= UUID
.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
56 private UUID taxonUuid2
= UUID
.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
60 public static void initializeServices() {
63 taxonService
= applicationController
.getTaxonService();
65 classificationService
= applicationController
.getClassificationService();
66 List
<Classification
> classifications
= classificationService
.listClassifications(1,0,null,null);
67 Assert
.assertFalse(classifications
.isEmpty());
69 Classification classification
= classifications
.get(0);
70 Assert
.assertNotNull(classification
);
71 taxonNodes
= classificationService
.getAllNodes();
72 Assert
.assertFalse(taxonNodes
.isEmpty());
79 public void testCDMEntityGet() {
80 Iterator
<TaxonNode
> taxonNodeItr
= taxonNodes
.iterator();
83 while(taxonNodeItr
.hasNext() && count
<= maxcount
) {
84 TaxonNode taxonNode
= taxonNodeItr
.next();
85 Assert
.assertNotNull(taxonNode
);
87 Taxon taxon
= taxonNode
.getTaxon();
88 Assert
.assertNotNull(taxon
);
90 String taxonTitle
= taxon
.getTitleCache();
91 logger
.info("Taxon : " + taxonTitle
);
93 TaxonNameBase name
= taxon
.getName();
94 Assert
.assertNotNull(name
);
96 String nameTitle
= name
.getTitleCache();
97 logger
.info("Taxon Name : " + nameTitle
);
108 public void testCDMEntitySaveEager() {
109 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
110 String oldTitleCache
= taxon
.getTitleCache();
112 System
.out
.println("Taxon title : " + oldTitleCache
);
114 taxon
.setTitleCache(oldTitleCache
+ ":updated");
115 taxonService
.merge(taxon
);
117 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
118 System
.out
.println("New Taxon Title : " + taxonNew
.getTitleCache());
120 Assert
.assertNotEquals("Title caches should not be equal",oldTitleCache
,taxonNew
.getTitleCache());
122 taxonNew
.setTitleCache(oldTitleCache
);
123 taxonService
.merge(taxonNew
);
125 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
126 System
.out
.println("Old Taxon Title : " + taxonOld
.getTitleCache());
128 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,taxonOld
.getTitleCache());
134 public void testCDMEntitySaveLazy() {
135 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
137 NonViralName nvn
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
138 String oldTitleCache
= nvn
.getTitleCache();
139 System
.out
.println("Taxon Name Title : " + oldTitleCache
);
140 nvn
.setTitleCache(oldTitleCache
+ ":updated");
141 taxonService
.merge(taxon
);
143 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
144 NonViralName nvnNew
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
145 System
.out
.println("New Taxon Name Title : " + nvnNew
.getTitleCache());
147 Assert
.assertNotEquals("Title caches should not be equal",oldTitleCache
,nvnNew
.getTitleCache());
149 nvnNew
.setTitleCache(oldTitleCache
);
150 taxonService
.merge(taxon
);
152 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
153 NonViralName nvnOld
= CdmBase
.deproxy(taxon
.getName(),NonViralName
.class);
154 System
.out
.println("Old Taxon Name Title : " + nvnNew
.getTitleCache());
156 Assert
.assertEquals("Title caches should be equal",oldTitleCache
,nvnOld
.getTitleCache());
161 public void testCDMEntitySaveCollection() {
162 Taxon taxon
= (Taxon
)taxonService
.find(taxonUuid1
);
164 Set
<SynonymRelationship
> synRelations
= taxon
.getSynonymRelations();
165 Set
<String
> relToTitles
= new HashSet
<String
>();
166 Iterator
<SynonymRelationship
> srItr
= synRelations
.iterator();
167 while(srItr
.hasNext()) {
168 SynonymRelationship sr
= srItr
.next();
169 System
.out
.println("Synonym Title Cache : " + sr
.getSynonym().getTitleCache());
170 relToTitles
.add(sr
.getSynonym().getTitleCache());
171 sr
.getSynonym().setTitleCache(sr
.getSynonym().getTitleCache() + ":updated");
174 taxonService
.merge(taxon
);
176 Taxon taxonNew
= (Taxon
)taxonService
.find(taxonUuid1
);
177 Set
<SynonymRelationship
> synRelationsNew
= taxonNew
.getSynonymRelations();
179 Iterator
<SynonymRelationship
> srItrNew
= synRelationsNew
.iterator();
180 Iterator
<String
> relToTitlesItr
= relToTitles
.iterator();
181 while(srItrNew
.hasNext() && relToTitlesItr
.hasNext()) {
182 SynonymRelationship srNew
= srItrNew
.next();
183 String relToTitle
= relToTitlesItr
.next();
184 System
.out
.println("New Synonym Title Cache: " + srNew
.getSynonym().getTitleCache());
185 Assert
.assertNotEquals("Synonym Title caches should not be equal", srNew
.getSynonym().getTitleCache(), relToTitle
);
186 srNew
.getSynonym().setTitleCache(relToTitle
);
189 Taxon taxonOld
= (Taxon
)taxonService
.find(taxonUuid1
);
191 Set
<SynonymRelationship
> synRelationsOld
= taxonNew
.getSynonymRelations();
192 Iterator
<SynonymRelationship
> srItrOld
= synRelationsOld
.iterator();
193 relToTitlesItr
= relToTitles
.iterator();
194 while(srItrOld
.hasNext() && relToTitlesItr
.hasNext()) {
195 SynonymRelationship srOld
= srItrOld
.next();
196 String relToTitle
= relToTitlesItr
.next();
197 System
.out
.println("New Synonym Title Cache: " + srOld
.getSynonym().getTitleCache());
198 Assert
.assertEquals("Synonym Title caches should be equal", srOld
.getSynonym().getTitleCache(), relToTitle
);