ee0c8f33488b8e1a83c24e8b3737d4ebb3117510
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / test / java / eu / etaxonomy / taxeditor / remoting / RemoteLazyLoadingTest.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.remoting;
11
12 import java.util.HashSet;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.Set;
16 import java.util.UUID;
17
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;
24
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;
35
36
37
38 /**
39 * Test class which tests remoting for persistent cdm entities.
40 *
41 * FIXME:Remoting saving tests are ignored until the merge development is underway
42 * @author c.mathew
43 *
44 */
45
46 public class RemoteLazyLoadingTest extends RemoteApplicationConfigurationTest {
47
48 private static final Logger logger = Logger.getLogger(RemoteLazyLoadingTest.class);
49
50 private static IClassificationService classificationService;
51 private static ITaxonService taxonService;
52
53 private static List<TaxonNode> taxonNodes;
54
55 private UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
56 private UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
57
58
59 @BeforeClass
60 public static void initializeServices() {
61
62
63 taxonService = applicationController.getTaxonService();
64
65 classificationService= applicationController.getClassificationService();
66 List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
67 Assert.assertFalse(classifications.isEmpty());
68
69 Classification classification = classifications.get(0);
70 Assert.assertNotNull(classification);
71 taxonNodes = classificationService.getAllNodes();
72 Assert.assertFalse(taxonNodes.isEmpty());
73
74 }
75
76
77
78 @Test
79 public void testCDMEntityGet() {
80 Iterator<TaxonNode> taxonNodeItr = taxonNodes.iterator();
81 int maxcount = 30;
82 int count = 0;
83 while(taxonNodeItr.hasNext() && count <= maxcount) {
84 TaxonNode taxonNode = taxonNodeItr.next();
85 Assert.assertNotNull(taxonNode);
86
87 Taxon taxon = taxonNode.getTaxon();
88 Assert.assertNotNull(taxon);
89
90 String taxonTitle = taxon.getTitleCache();
91 logger.info("Taxon : " + taxonTitle);
92
93 TaxonNameBase name = taxon.getName();
94 Assert.assertNotNull(name);
95
96 String nameTitle = name.getTitleCache();
97 logger.info("Taxon Name : " + nameTitle);
98
99 count++;
100 }
101
102
103 }
104
105
106 @Ignore
107 @Test
108 public void testCDMEntitySaveEager() {
109 Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
110 String oldTitleCache = taxon.getTitleCache();
111
112 System.out.println("Taxon title : " + oldTitleCache);
113
114 taxon.setTitleCache(oldTitleCache + ":updated");
115 taxonService.merge(taxon);
116
117 Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
118 System.out.println("New Taxon Title : " + taxonNew.getTitleCache());
119
120 Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,taxonNew.getTitleCache());
121
122 taxonNew.setTitleCache(oldTitleCache);
123 taxonService.merge(taxonNew);
124
125 Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
126 System.out.println("Old Taxon Title : " + taxonOld.getTitleCache());
127
128 Assert.assertEquals("Title caches should be equal",oldTitleCache,taxonOld.getTitleCache());
129
130 }
131
132 @Ignore
133 @Test
134 public void testCDMEntitySaveLazy() {
135 Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
136
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);
142
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());
146
147 Assert.assertNotEquals("Title caches should not be equal",oldTitleCache,nvnNew.getTitleCache());
148
149 nvnNew.setTitleCache(oldTitleCache);
150 taxonService.merge(taxon);
151
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());
155
156 Assert.assertEquals("Title caches should be equal",oldTitleCache,nvnOld.getTitleCache());
157 }
158
159 @Ignore
160 @Test
161 public void testCDMEntitySaveCollection() {
162 Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
163
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");
172
173 }
174 taxonService.merge(taxon);
175
176 Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
177 Set<SynonymRelationship> synRelationsNew = taxonNew.getSynonymRelations();
178
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);
187 }
188
189 Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
190
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);
199
200 }
201 }
202 }