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
|
package eu.etaxonomy.taxeditor.lazyloading;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Iterator;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
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;
|
23
|
|
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;
|
39
|
|
40
|
|
41
|
|
42
|
|
43
|
/**
|
44
|
* Class to test the {@link CdmApplicationRemoteController}
|
45
|
*
|
46
|
*/
|
47
|
// FIXME:Remoting need to create a proper dataset for this test
|
48
|
// Could be combined with RemotePersistentCollectionTest
|
49
|
@Ignore
|
50
|
@DataSet
|
51
|
public class AbstractLazyInitializerTest extends BaseRemotingTest {
|
52
|
private static final Logger logger = Logger.getLogger(AbstractLazyInitializerTest.class);
|
53
|
|
54
|
private static IClassificationService classificationService;
|
55
|
private static ITaxonService taxonService;
|
56
|
|
57
|
private static List<TaxonNode> taxonNodes;
|
58
|
|
59
|
private final UUID taxonUuid1 = UUID.fromString("8217ef77-2ab1-4318-bd67-ccd0cdef07c4");
|
60
|
private final UUID taxonUuid2 = UUID.fromString("ef96fafa-7750-4141-b31b-1ad1daab3e76");
|
61
|
|
62
|
|
63
|
@BeforeClass
|
64
|
public static void initializeRemoteLazyLoading() {
|
65
|
|
66
|
taxonService = getRemoteApplicationController().getTaxonService();
|
67
|
classificationService= getRemoteApplicationController().getClassificationService();
|
68
|
List<Classification> classifications = classificationService.listClassifications(1,0,null,null);
|
69
|
Assert.assertFalse(classifications.isEmpty());
|
70
|
|
71
|
Classification classification = classifications.get(0);
|
72
|
Assert.assertNotNull(classification);
|
73
|
taxonNodes = classificationService.getAllNodes();
|
74
|
Assert.assertFalse(taxonNodes.isEmpty());
|
75
|
|
76
|
}
|
77
|
|
78
|
|
79
|
|
80
|
@Test
|
81
|
public void testCDMEntityGet() {
|
82
|
//ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
|
83
|
Iterator<TaxonNode> taxonNodeItr = taxonNodes.iterator();
|
84
|
int maxcount = 30;
|
85
|
int count = 0;
|
86
|
while(taxonNodeItr.hasNext() && count <= maxcount) {
|
87
|
TaxonNode taxonNode = taxonNodeItr.next();
|
88
|
Assert.assertNotNull(taxonNode);
|
89
|
|
90
|
Taxon taxon = taxonNode.getTaxon();
|
91
|
Assert.assertNotNull(taxon);
|
92
|
|
93
|
String taxonTitle = taxon.getTitleCache();
|
94
|
logger.info("Taxon : " + taxonTitle);
|
95
|
|
96
|
TaxonName name = taxon.getName();
|
97
|
Assert.assertNotNull(name);
|
98
|
|
99
|
String nameTitle = name.getTitleCache();
|
100
|
logger.info("Taxon Name : " + nameTitle);
|
101
|
|
102
|
count++;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
@Test
|
107
|
public void taxonReadTest() {
|
108
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
109
|
|
110
|
}
|
111
|
|
112
|
|
113
|
@Test
|
114
|
public void testCDMEntitySave() {
|
115
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
116
|
String oldTitleCache = taxon.getTitleCache();
|
117
|
|
118
|
System.out.println("Taxon title : " + oldTitleCache);
|
119
|
|
120
|
taxon.setTitleCache(oldTitleCache + ":updated", true);
|
121
|
taxonService.merge(taxon);
|
122
|
|
123
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
124
|
System.out.println("New Taxon Title : " + taxonNew.getTitleCache());
|
125
|
|
126
|
Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(taxonNew.getTitleCache()));
|
127
|
|
128
|
|
129
|
taxonNew.setTitleCache(oldTitleCache, true);
|
130
|
taxonService.merge(taxonNew);
|
131
|
|
132
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
133
|
System.out.println("Old Taxon Title : " + taxonOld.getTitleCache());
|
134
|
|
135
|
Assert.assertEquals("Title caches should be equal",oldTitleCache,taxonOld.getTitleCache());
|
136
|
|
137
|
}
|
138
|
|
139
|
|
140
|
@Test
|
141
|
public void testCDMEntitySaveLazyNew() {
|
142
|
Team combAuthor = Team.NewInstance();
|
143
|
combAuthor.addTeamMember(Person.NewTitledInstance("test member"));
|
144
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null, "Test1", null, null, null, null, null, null, null);
|
145
|
name.setCombinationAuthorship(combAuthor);
|
146
|
Taxon tax1 = Taxon.NewInstance(name, null);
|
147
|
UUID taxonUuid1 = taxonService.save(tax1).getUuid();
|
148
|
|
149
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
150
|
|
151
|
INonViralName nvn = CdmBase.deproxy(taxon.getName());
|
152
|
String oldTitleCache = nvn.getTitleCache();
|
153
|
logger.info("Taxon Name Title : " + oldTitleCache);
|
154
|
nvn.setTitleCache(oldTitleCache + ":updated",false);
|
155
|
taxonService.update(taxon);
|
156
|
|
157
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
158
|
INonViralName nvnNew = CdmBase.deproxy(taxon.getName());
|
159
|
logger.info("New Taxon Name Title : " + nvnNew.getTitleCache());
|
160
|
|
161
|
Assert.assertTrue("Title caches should not be equal",oldTitleCache.equals(nvnNew.getTitleCache()));
|
162
|
|
163
|
nvnNew.setTitleCache(oldTitleCache, true);
|
164
|
taxonService.update(taxon);
|
165
|
|
166
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
167
|
INonViralName nvnOld = CdmBase.deproxy(taxon.getName());
|
168
|
logger.info("Old Taxon Name Title : " + nvnNew.getTitleCache());
|
169
|
|
170
|
Assert.assertEquals("Title caches should be equal",oldTitleCache, nvnOld.getTitleCache());
|
171
|
}
|
172
|
|
173
|
@Ignore
|
174
|
@Test
|
175
|
public void testCdmEntitySaveCollection() {
|
176
|
Taxon taxon = (Taxon)taxonService.find(taxonUuid1);
|
177
|
|
178
|
Set<TaxonRelationship> taxRelations = taxon.getTaxonRelations();
|
179
|
Set<String> relToTitles = new HashSet<String>();
|
180
|
Iterator<TaxonRelationship> trItr = taxRelations.iterator();
|
181
|
while(trItr.hasNext()) {
|
182
|
TaxonRelationship tr = trItr.next();
|
183
|
System.out.println("Synonym Title Cache : " + tr.getFromTaxon().getTitleCache());
|
184
|
relToTitles.add(tr.getFromTaxon().getTitleCache());
|
185
|
tr.getFromTaxon().setTitleCache(tr.getFromTaxon().getTitleCache() + ":updated");
|
186
|
|
187
|
}
|
188
|
taxonService.merge(taxon);
|
189
|
|
190
|
Taxon taxonNew = (Taxon)taxonService.find(taxonUuid1);
|
191
|
Set<TaxonRelationship> taxRelationsNew = taxonNew.getTaxonRelations();
|
192
|
|
193
|
Iterator<TaxonRelationship> trItrNew = taxRelationsNew.iterator();
|
194
|
Iterator<String> relToTitlesItr = relToTitles.iterator();
|
195
|
while(trItrNew.hasNext() && relToTitlesItr.hasNext()) {
|
196
|
TaxonRelationship trNew = trItrNew.next();
|
197
|
String relToTitle = relToTitlesItr.next();
|
198
|
System.out.println("New Synonym Title Cache: " + trNew.getFromTaxon().getTitleCache());
|
199
|
Assert.assertTrue("Synonym Title caches should not be equal", trNew.getFromTaxon().getTitleCache().equals(relToTitle));
|
200
|
trNew.getFromTaxon().setTitleCache(relToTitle);
|
201
|
}
|
202
|
|
203
|
Taxon taxonOld = (Taxon)taxonService.find(taxonUuid1);
|
204
|
|
205
|
Set<TaxonRelationship> taxRelationsOld = taxonNew.getTaxonRelations();
|
206
|
Iterator<TaxonRelationship> trItrOld = taxRelationsOld.iterator();
|
207
|
relToTitlesItr = relToTitles.iterator();
|
208
|
while(trItrOld.hasNext() && relToTitlesItr.hasNext()) {
|
209
|
TaxonRelationship trOld = trItrOld.next();
|
210
|
String relToTitle = relToTitlesItr.next();
|
211
|
System.out.println("New Synonym Title Cache: " + trOld.getFromTaxon().getTitleCache());
|
212
|
Assert.assertEquals("Synonym Title caches should be equal", trOld.getFromTaxon().getTitleCache(), relToTitle);
|
213
|
|
214
|
}
|
215
|
}
|
216
|
}
|