Project

General

Profile

« Previous | Next » 

Revision bdde50e7

Added by Cherian Mathew almost 9 years ago

Move test classes to right packages

View differences:

eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/PolytomousKeyTest.java
1
// $Id$
2
/**
3
 * Copyright (C) 2014 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.cdm.model;
11

  
12
import java.util.Arrays;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

  
19
import org.apache.log4j.Logger;
20
import org.hibernate.collection.spi.PersistentCollection;
21
import org.junit.Assert;
22
import org.junit.BeforeClass;
23
import org.junit.Test;
24
import org.unitils.dbunit.annotation.DataSet;
25

  
26
import eu.etaxonomy.cdm.api.service.ICommonService;
27
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
28
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
29
import eu.etaxonomy.cdm.api.service.ITaxonService;
30
import eu.etaxonomy.cdm.model.agent.AgentBase;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.cdm.model.common.Credit;
33
import eu.etaxonomy.cdm.model.common.Extension;
34
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
35
import eu.etaxonomy.cdm.model.common.Language;
36
import eu.etaxonomy.cdm.model.common.LanguageString;
37
import eu.etaxonomy.cdm.model.description.KeyStatement;
38
import eu.etaxonomy.cdm.model.description.PolytomousKey;
39
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
40
import eu.etaxonomy.cdm.model.media.Rights;
41
import eu.etaxonomy.cdm.model.taxon.Taxon;
42
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
43
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
44
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
45
import eu.etaxonomy.taxeditor.session.MockSessionOwner;
46

  
47
/**
48
 * @author cmathew
49
 * @date 7 Oct 2014
50
 *
51
 */
52
@DataSet
53
public class PolytomousKeyTest extends RemotingSessionAwareTest {
54

  
55
    private static final Logger logger = Logger.getLogger(PolytomousKeyTest.class);
56

  
57
    UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
58
    UUID subKeyUuid = UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01");
59
    //UUID polytomousKeyUuid = UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
60
    UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
61

  
62

  
63
    IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
64
    IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
65
    ICommonService commonService = getRemoteApplicationController().getCommonService();
66
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
67

  
68
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
69

  
70

  
71

  
72
    @BeforeClass
73
    public static void initializePolytomousKeyTest() {
74
    }
75

  
76

  
77
    @Test
78
    public void readAllPolytomousKeys() {
79
        List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
80
        Iterator<PolytomousKey> pKeysItr = pKeys.iterator();
81
        Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
82
        Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
83
    }
84

  
85

  
86
    @Test
87
    //@DataSet("PolytomousKeyTest.readPolytmousKeyData.xml")
88
    public void readPolytmousKeyData() {
89
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
90
        Set<Taxon> taxonomicScope = pKey.getTaxonomicScope();
91
        Iterator<Taxon> tsItr = taxonomicScope.iterator();
92
        Taxon taxon = tsItr.next();
93

  
94
        Assert.assertEquals("Achillea sec. Cyprus", taxon.getTitleCache());
95
        Assert.assertEquals(tsItr.hasNext(), false);
96

  
97
        List<Credit> credits = pKey.getCredits();
98
        AgentBase agent = credits.get(0).getAgent();
99
        Assert.assertEquals(agent.getId(),4809);
100
        Assert.assertEquals(agent.getTitleCache(),"R. A. Graham");
101
        Assert.assertEquals(credits.get(0).getText(),"Credits Text Test");
102

  
103
        Set<Extension> exts = pKey.getExtensions();
104
        Iterator<Extension> extItr = exts.iterator();
105
        Extension ext = extItr.next();
106
        Assert.assertEquals(ext.getValue(), "http://test.com");
107

  
108
        Set<Rights> rights = pKey.getRights();
109
        Iterator<Rights> rightsItr = rights.iterator();
110
        Rights right = rightsItr.next();
111
        Assert.assertEquals(right.getText(),"Rights Text Test");
112

  
113
        Set<IdentifiableSource> sources = pKey.getSources();
114
        Iterator<IdentifiableSource> sourcesItr = sources.iterator();
115
        IdentifiableSource source = sourcesItr.next();
116
        Assert.assertEquals(source.getId(), 23710);
117
        source = sourcesItr.next();
118
        Assert.assertEquals(source.getId(), 23711);
119

  
120
        // TO DO : Added tests for Annotations , Markers
121
    }
122

  
123
    @Test
124
    public void readPolytomousKeyDataFromNodes() {
125
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
126
        PolytomousKeyNode rootNode = pKey.getRoot();
127

  
128

  
129
        Assert.assertEquals(rootNode.getId(), 2750);
130

  
131
        Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751);
132
        Assert.assertEquals(rootNode.getChildAt(0).getParent().getId(), rootNode.getId());
133
        Assert.assertEquals(rootNode.getKey().getId(), pKey.getId());
134
        Integer sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(0), "sortIndex");
135
        Assert.assertEquals(sortIndex, new Integer(0));
136
        String statement = "Capitula without ligulate ray-florets; leaves entire or subentire";
137
        Assert.assertEquals(rootNode.getChildAt(0).getStatement().getLabelText(english), statement);
138

  
139
        Assert.assertEquals(rootNode.getChildAt(1).getId(), 2753);
140
        Assert.assertEquals(rootNode.getChildAt(1).getParent().getId(), rootNode.getId());
141
        Assert.assertEquals(rootNode.getChildAt(1).getKey().getId(), pKey.getId());
142
        sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1), "sortIndex");
143
        Assert.assertEquals(sortIndex, new Integer(1));
144
        statement = "Capitula with ligulate ray-florets; leaves pinnatisect";
145
        Assert.assertEquals(rootNode.getChildAt(1).getStatement().getLabelText(english), statement);
146

  
147
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getId(), 2754);
148
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getParent().getId(), rootNode.getChildAt(1).getId());
149
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getKey().getId(), pKey.getId());
150
        sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1).getChildAt(0), "sortIndex");
151
        Assert.assertEquals(sortIndex, new Integer(0));
152
        statement = "Ray-florets yellow";
153
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getStatement().getLabelText(english), statement);
154
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getChildAt(0).getTaxon().getTitleCache(), "Achillea arabica Kotschy sec. Cyprus");
155
    }
156

  
157
    @Test
158
    public void savePolytomousKeyNodeData() {
159
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
160

  
161
        PolytomousKeyNode pkeynode = pkey.getRoot();
162
        String newQuestion = "New Question";
163
        String newStatement = "New Statement";
164

  
165
        Assert.assertEquals("Question 1",pkeynode.getQuestion().getLabel().get(english).getText());
166
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
167

  
168
            node.setQuestion(null);
169
            node.setStatement(null);
170
        }
171
        //FIXME:Remoting Add tests for feature after fixing problem
172

  
173
        //Feature feature = pkeynode.getFeature();
174
        //Assert.assertEquals(feature.getTitleCache(),"Systematics");
175
        //pkeynode.setFeature(null);
176

  
177
        Assert.assertEquals(pkeynode.getChildAt(0).getModifyingText().get(english).getText(),"Modifying Text 1a");
178
        String modifyingText = "Modifying Text 1a updated";
179

  
180
        //pkeynode.getChildAt(0).putModifyingText(english, modifyingText);
181

  
182
        Assert.assertEquals(pkeynode.getChildAt(0).getSubkey().getId(),751);
183
        Assert.assertEquals("Asphodeline", pkeynode.getChildAt(0).getSubkey().getTitleCache());
184
        Assert.assertNull(pkeynode.getChildAt(1).getTaxon());
185
        Taxon taxon = CdmBase.deproxy(taxonService.find(taxon1Uuid),Taxon.class);
186
        pkeynode.getChildAt(1).setTaxon(taxon);
187

  
188
        EntityCacherDebugResult debugResult = new EntityCacherDebugResult(cacher,  Arrays.asList(pkey));
189

  
190
        polytomousKeyService.merge(pkey);
191

  
192
        pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
193
        sessionOwner = new MockSessionOwner();
194

  
195

  
196
        pkeynode = pkey.getRoot();
197
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
198
            Assert.assertNull(node.getQuestion());
199
            node.setQuestion(KeyStatement.NewInstance(english,newQuestion));
200
            Assert.assertNull(node.getStatement());
201
            node.setStatement(KeyStatement.NewInstance(english,newStatement));
202
        }
203

  
204

  
205
        Assert.assertEquals(pkeynode.getChildAt(1).getTaxon(), taxon);
206

  
207
        polytomousKeyService.merge(pkey);
208

  
209
        pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
210
        sessionOwner = new MockSessionOwner();
211

  
212

  
213
        pkeynode = pkey.getRoot();
214
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
215
            Assert.assertNotNull(node.getQuestion());
216
            Map<Language, LanguageString> label = node.getQuestion().getLabel();
217
            Assert.assertEquals(newQuestion, label.get(english).getText());
218
            Assert.assertNotNull(node.getStatement());
219
            Assert.assertEquals(newStatement, node.getStatement().getLabel(english).getText());
220
        }
221
        //Assert.assertEquals(pkeynode.getFeature().getId(), feature.getId());
222

  
223
    }
224

  
225
    @Test
226
    public void savePolytomousKeyNodeDataWithSameSubKey() {
227

  
228
        ICdmEntitySessionEnabled sessionOwner = new MockSessionOwner();
229
        cdmEntitySessionManager.bind(sessionOwner);
230
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
231

  
232

  
233
        PolytomousKeyNode pkeynode = pkey.getRoot();
234

  
235
        PolytomousKey subkey1 = CdmBase.deproxy(pkeynode.getChildAt(0).getSubkey(), PolytomousKey.class);
236
        String subkey1title = subkey1.getTitleCache();
237
        subkey1.setTitleCache(subkey1title + "test", true);
238

  
239

  
240
        PolytomousKey subkey2 = CdmBase.deproxy(pkeynode.getChildAt(1).getChildAt(0).getSubkey(), PolytomousKey.class);
241
        String subkey2title = subkey2.getTitleCache();
242
        subkey2.setTitleCache(subkey2title + "test", true);
243

  
244
        Assert.assertSame(subkey1, subkey2);
245

  
246
        polytomousKeyService.merge(pkey);
247
    }
248

  
249
    @Test
250
    public void savePolytomousKeyNodeDataWithSameSubKeyUsingService() {
251

  
252
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
253

  
254

  
255
        PolytomousKeyNode pkeynode = pkey.getRoot();
256

  
257
        PersistentCollection children = (PersistentCollection) pkeynode.getChildren();
258
        PolytomousKeyNode childNode0 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 0);
259
        PolytomousKey subkey1 = CdmBase.deproxy(childNode0.getSubkey(),PolytomousKey.class);
260
        String subkey1title = subkey1.getTitleCache();
261
        subkey1.setTitleCache(subkey1title + "test", true);
262

  
263
        PolytomousKeyNode childNode1 = (PolytomousKeyNode)commonService.get(pkeynode.getUuid(), "children", 1);
264
        PolytomousKey subkey2 = CdmBase.deproxy(childNode1.getSubkey(),PolytomousKey.class);
265
        String subkey2title = subkey2.getTitleCache();
266
        subkey2.setTitleCache(subkey2title + "test", true);
267

  
268
        Assert.assertNotSame(childNode0, childNode1);
269

  
270
        Assert.assertSame(subkey1, subkey2);
271

  
272
        polytomousKeyService.merge(pkey);
273
    }
274

  
275

  
276
    @Test
277
    public void savePolytomousKeyNodeDataWithSameLanguageInLabel() {
278
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
279
        PolytomousKeyNode pkeynode = pkey.getRoot();
280

  
281
        Map<Language, LanguageString> label1 = pkeynode.getQuestion().getLabel();
282
        label1.size();
283

  
284

  
285
        Map<Language, LanguageString> label2 = pkeynode.getChildAt(0).getStatement().getLabel();
286
        label2.size();
287

  
288

  
289
        polytomousKeyService.merge(pkey);
290
    }
291

  
292
    @Test
293
    public void deleteSubKeyInPolytomousSubKeyWithoutInitializing() {
294
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
295

  
296

  
297
        PolytomousKeyNode rootNode = pKey.getRoot();
298
        PolytomousKeyNode child = rootNode.getChildAt(0);
299
        PolytomousKey subKey = child.getSubkey();
300

  
301
        polytomousKeyService.delete(subKey);
302

  
303
        // since subKey was not initialized before the delete, an attempt
304
        // to initialize it after will lead to an NPE
305
        try {
306
            PolytomousKeyNode subKeyRootNode = subKey.getRoot();
307
            Assert.fail("A NullPointerException indicating null root node should be thrown here");
308
        } catch(NullPointerException npe) {
309

  
310
        }
311
        // retrieving subkey shows its null
312
        subKey = CdmBase.deproxy(polytomousKeyService.find(subKeyUuid),PolytomousKey.class);
313
        Assert.assertNull(subKey);
314

  
315
        pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
316

  
317

  
318
        rootNode = pKey.getRoot();
319
        child = rootNode.getChildAt(0);
320
        subKey = child.getSubkey();
321
        // subkey will not be null, because the delete functionality of the subkey
322
        // does not currently delete it from a polytomous key node
323
        Assert.assertNotNull(subKey);
324
        // after reloading the object graph, accessing subKey should throw a null pointer exception
325
        try {
326
            PolytomousKeyNode subKeyRootNode = subKey.getRoot();
327
            Assert.fail("A NullPointerException indicating null root node should be thrown here");
328
        } catch(NullPointerException npe) {
329

  
330
        }
331

  
332
    }
333

  
334
    @Test
335
    public void deleteSubKeyInPolytomousNode() {
336
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
337

  
338

  
339
        PolytomousKeyNode rootNode = pKey.getRoot();
340
        List<PolytomousKeyNode> children = rootNode.getChildren();
341
        PolytomousKeyNode child = rootNode.getChildAt(0);
342
        polytomousKeyNodeService.delete(child.getUuid(), true);
343

  
344
        pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
345

  
346
        rootNode = pKey.getRoot();
347
        children = rootNode.getChildren();
348
        Assert.assertFalse(children.contains(child));
349
    }
350

  
351
    @Test
352
    public void deleteSubKeyInPolytomousSubKeyAfterInitializing() {
353
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
354

  
355

  
356
        PolytomousKeyNode rootNode = pKey.getRoot();
357
        PolytomousKeyNode child = rootNode.getChildAt(0);
358
        PolytomousKey subKey = child.getSubkey();
359
        // this call initializes the subkey
360
        subKey.getRoot();
361

  
362
        polytomousKeyService.delete(subKey);
363

  
364
        // since subKey was initialized before the delete, it will be
365
        // accesible even after the delete. This behaviour is similar
366
        // to hibernate session delete where the deleted object is
367
        // made transient, but not deleted from the object graph
368

  
369
        PolytomousKeyNode subKeyRootNode = subKey.getRoot();
370
        Assert.assertNotNull(subKey);
371

  
372
    }
373

  
374

  
375
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNameEditorTest.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.model;
11

  
12
import java.util.ArrayList;
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.Logger;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.junit.Assert;
21
import org.junit.Test;
22
import org.unitils.dbunit.annotation.DataSet;
23

  
24
import eu.etaxonomy.cdm.api.service.IClassificationService;
25
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
26
import eu.etaxonomy.cdm.api.service.ITaxonService;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.name.BotanicalName;
29
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
30
import eu.etaxonomy.cdm.model.name.NonViralName;
31
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
32
import eu.etaxonomy.cdm.model.taxon.Synonym;
33
import eu.etaxonomy.cdm.model.taxon.Taxon;
34
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
35
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
36
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
37

  
38
/**
39
 * @author cmathew
40
 * @date 3 Feb 2015
41
 *
42
 */
43

  
44
@DataSet
45
public class TaxonNameEditorTest extends BaseOperationTest {
46

  
47
    private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
48

  
49
    ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
50
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
51
    IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
52

  
53
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
54

  
55

  
56
    @Test
57
    public void testAddHomotypicSynonym() throws ExecutionException {
58
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
59

  
60
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
61
        Taxon taxon = taxonNode.getTaxon();
62
        HomotypicalGroup group = taxon.getHomotypicGroup();
63
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
64
        newSynonymName.setTitleCache("New Synonym", true);
65
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
66
                undoContext, taxon, group, newSynonymName, postOperation);
67

  
68
        operation.execute(monitor, info);
69
        taxonNodeService.merge(taxonNode);
70
        Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
71
        Assert.assertEquals(taxon.getSynonyms().size(), 1);
72
        Iterator<Synonym> synonymItr = taxon.getSynonyms().iterator();
73
        Synonym synonym = synonymItr.next();
74
        Assert.assertTrue(taxon.getHomotypicGroup().getTypifiedNames().contains(synonym.getName()));
75
    }
76

  
77
    @Test
78
    public void addHeterotypicSynonym() throws ExecutionException {
79
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
80

  
81
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
82
        Taxon taxon = taxonNode.getTaxon();
83
        HomotypicalGroup group = taxon.getHomotypicGroup();
84
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
85
        newSynonymName.setTitleCache("New Synonym", true);
86
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
87
                undoContext, taxon, group, newSynonymName, postOperation);
88

  
89
        operation.execute(monitor, info);
90
        taxonNodeService.merge(taxonNode);
91

  
92

  
93
    }
94

  
95
    @Test
96
    public void addDeleteAddHomotypicSynonym() throws ExecutionException {
97
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
98

  
99
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
100
        Taxon taxon = taxonNode.getTaxon();
101
        HomotypicalGroup group = taxon.getHomotypicGroup();
102
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
103
        newSynonymName.setTitleCache("New Synonym", true);
104
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
105
                undoContext, taxon, group, newSynonymName, postOperation);
106

  
107
        operation.execute(monitor, info);
108
        taxonNodeService.merge(taxonNode);
109
        Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
110

  
111
        Set<Synonym> synonyms = taxon.getSynonyms();
112
        for(Synonym synonym : synonyms) {
113
            taxonService.deleteSynonym(synonym.getUuid(), taxon.getUuid(), null);
114
        }
115

  
116
        taxonNodeService.merge(taxonNode);
117

  
118
        newSynonymName = BotanicalName.NewInstance(null);
119
        newSynonymName.setTitleCache("Another New Synonym", true);
120
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
121
                undoContext, taxon, group, newSynonymName, postOperation);
122

  
123
        operation.execute(monitor, info);
124
        taxonNodeService.merge(taxonNode);
125
    }
126

  
127
    @Test
128
    public void swapSynonymWithAcceptedTaxon() throws ExecutionException {
129
        List<TaxonNode> rootEntities = new ArrayList<TaxonNode>();
130
        UUID taxonNodeUuid = UUID.fromString("d425a971-1abe-4895-9e1f-1e5c8ff1c84c");
131
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
132
        rootEntities.add(taxonNode);
133

  
134
        cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
135

  
136
        UUID taxonUuid = UUID.fromString("9763e5f0-6cd4-4d96-b8a4-4420854f7727");
137
        Taxon taxon = (Taxon)taxonService.load(taxonUuid);
138
        TaxonNameBase taxonName = taxon.getName();
139

  
140
        UUID synonymUuid = UUID.fromString("1eb173bd-b174-4162-8ff5-5136d8f1e746");
141
        Synonym synonym = (Synonym)taxonService.load(synonymUuid);
142
        TaxonNameBase synonymName = synonym.getName();
143

  
144
        taxonService.swapSynonymAndAcceptedTaxon(synonym.getUuid(), taxon.getUuid());
145

  
146
        Assert.assertEquals(taxonName, synonym.getName());
147
        Assert.assertEquals(synonymName, taxon.getName());
148
    }
149

  
150
    @Test
151
    public void addTaxon() {
152
        NonViralName taxonName = NonViralName.NewInstance(null);
153
        Taxon taxon = Taxon.NewInstance(taxonName, null);
154
        taxonService.merge(taxon);
155
    }
156

  
157
}
158

  
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNavigatorTest.java
1
// $Id$
2
/**
3
 * Copyright (C) 2015 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.cdm.model;
11

  
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import org.apache.log4j.Logger;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.junit.Assert;
21
import org.junit.Ignore;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24

  
25
import eu.etaxonomy.cdm.api.service.IClassificationService;
26
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
27
import eu.etaxonomy.cdm.api.service.ITaxonService;
28
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
29
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
30
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator.ChildHandling;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.cdm.model.common.Language;
33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35
import eu.etaxonomy.cdm.model.taxon.Classification;
36
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
37
import eu.etaxonomy.cdm.model.taxon.Taxon;
38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
40
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation;
41
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
42
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
43
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
44

  
45
/**
46
 * @author cmathew
47
 * @date 9 Mar 2015
48
 *
49
 */
50
@DataSet
51
public class TaxonNavigatorTest extends BaseOperationTest {
52

  
53
    private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
54

  
55
    ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
56
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
57
    IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
58

  
59
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
60

  
61

  
62

  
63
    @Test
64
    public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
65

  
66

  
67
        UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
68
        UUID newAcceptedTaxonNodeUuid = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
69

  
70
        TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
71
        TaxonNameBase name = oldTaxonNode.getTaxon().getName();
72

  
73

  
74
        TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
75
        int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
76
        sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
77
        sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
78

  
79
        operation =  new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
80
                false,
81
                oldTaxonNode.getUuid(),
82
                newAcceptedTaxonNode.getUuid());
83
        operation.execute(monitor, info);
84
        newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
85
        oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
86
        Assert.assertNull(oldTaxonNode);
87
        Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
88
        Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
89

  
90

  
91
    }
92

  
93
    @Test
94
    public void testMoveTaxon() throws ExecutionException {
95

  
96
        UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
97
        UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
98
        boolean moveToParentNode = true;
99

  
100
        TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
101
        TaxonNode oldParent = taxonNodeToMove.getParent();
102
        sessionOwner.addExpectedUpdatedObject(oldParent);
103
        int childCount = oldParent.getCountChildren();
104
        TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
105
        sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
106
        operation = new RemotingMoveTaxonOperation(sessionOwner,
107
                false,
108
                taxonNodeToMove.getUuid(),
109
                newParentTreeNode.getUuid(),
110
                moveToParentNode);
111
        operation.execute(monitor, info);
112
        Assert.assertEquals(childCount-1, oldParent.getCountChildren());
113
        Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
114
        Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
115
    }
116

  
117
    @Test
118
    public void testMoveFactualData() throws ExecutionException {
119
        UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
120
        UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
121

  
122
        Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
123
        Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
124
        sessionOwner.addExpectedUpdatedObject(sourceTaxon);
125

  
126
        Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
127
        int countTargetDescriptions = targetTaxon.getDescriptions().size();
128
        sessionOwner.addExpectedUpdatedObject(targetTaxon);
129

  
130
        operation = new RemotingMoveFactualDataOperation(sessionOwner,
131
                false,
132
                sourceTaxonUuid,
133
                targetTaxonUuid);
134
        operation.execute(monitor, info);
135
        Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
136
        Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
137
        Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
138
    }
139

  
140
    @Test
141
    public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException {
142
        UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
143
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
144
        List<TaxonNode> childNodes = taxonNode.getChildNodes();
145
        List<UUID> childNodeUuids = new ArrayList<UUID>();
146
        for(TaxonNode childNode : childNodes) {
147
            childNodeUuids.add(childNode.getUuid());
148
        }
149
        Assert.assertTrue(taxonNode.getCountChildren() > 0);
150

  
151
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
152
        nodes.add(taxonNode);
153

  
154
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
155
        configNodes.setChildHandling(ChildHandling.DELETE);
156
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
157
        config.setTaxonNodeConfig(configNodes);
158

  
159
        sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
160

  
161
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
162
                false,
163
                nodes,
164
                config);
165
        operation.execute(monitor, info);
166
        TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
167
        Assert.assertNull(reloadedNode);
168
        for(UUID childNodeUuid : childNodeUuids) {
169
            TaxonNode reloadedChildNode = taxonNodeService.load(childNodeUuid);
170
            Assert.assertNull(reloadedChildNode);
171
        }
172
    }
173

  
174
    @Ignore // waiting for #5019 to be fixed
175
    @Test
176
    public void testDeleteTaxonNodes() throws ExecutionException {
177
        UUID taxonNode1Uuid = UUID.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
178
        UUID taxonNode2Uuid = UUID.fromString("91698cec-615f-4472-9002-feda1a6acded");
179
        UUID taxonNode3Uuid = UUID.fromString("4fe03763-b966-4361-8334-352f6f777588");
180

  
181
        TaxonNode taxonNode1 = taxonNodeService.load(taxonNode1Uuid);
182
        TaxonNode taxonNode2 = taxonNodeService.load(taxonNode2Uuid);
183
        TaxonNode taxonNode3 = taxonNodeService.load(taxonNode3Uuid);
184

  
185
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
186
        nodes.add(taxonNode1);
187
        nodes.add(taxonNode2);
188
        nodes.add(taxonNode3);
189

  
190
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
191

  
192

  
193
        sessionOwner.addExpectedUpdatedObject(taxonNode1.getParent());
194
        sessionOwner.addExpectedUpdatedObject(taxonNode2.getParent());
195
        sessionOwner.addExpectedUpdatedObject(taxonNode3.getParent());
196
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
197
                false,
198
                nodes,
199
                config);
200
        operation.execute(monitor, info);
201
        TaxonNode reloadedNode1 = taxonNodeService.load(taxonNode1.getUuid());
202
        TaxonNode reloadedNode2 = taxonNodeService.load(taxonNode2.getUuid());
203
        TaxonNode reloadedNode3 = taxonNodeService.load(taxonNode3.getUuid());
204
        Assert.assertNull(reloadedNode1);
205
        Assert.assertNull(reloadedNode2);
206
        Assert.assertNull(reloadedNode3);
207

  
208
    }
209

  
210
    @Test
211
    public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException {
212
        UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
213
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
214
        TaxonNode parentTaxonNode = taxonNode.getParent();
215
        List<TaxonNode> childNodes = taxonNode.getChildNodes();
216
        List<UUID> childNodeUuids = new ArrayList<UUID>();
217
        for(TaxonNode childNode : childNodes) {
218
            childNodeUuids.add(childNode.getUuid());
219
        }
220
        Assert.assertTrue(taxonNode.getCountChildren() > 0);
221

  
222
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
223
        nodes.add(taxonNode);
224

  
225
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
226
        configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
227
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
228
        config.setTaxonNodeConfig(configNodes);
229

  
230
        sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
231
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
232
                false,
233
                nodes,
234
                config);
235
        operation.execute(monitor, info);
236
        TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
237
        Assert.assertNull(reloadedNode);
238
        List<TaxonNode> parentChildNodes = parentTaxonNode.getChildNodes();
239
        List<UUID> parentChildNodeUuids = new ArrayList<UUID>();
240
        for(TaxonNode parentChildNode : parentChildNodes) {
241
            parentChildNodeUuids.add(parentChildNode.getUuid());
242
        }
243
        parentChildNodeUuids.containsAll(childNodeUuids);
244

  
245
    }
246

  
247
    @Test
248
    @DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
249
    public void testDeleteClassificationWithDeleteChildren() throws ExecutionException {
250
        UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
251
        Classification classification = classificationService.load(classificationUuid);
252
        TaxonNode rootNode = classification.getRootNode();
253
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
254
        nodes.add(classification);
255

  
256
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
257
        configNodes.setChildHandling(ChildHandling.DELETE);
258
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
259
        config.setTaxonNodeConfig(configNodes);
260

  
261
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
262
                false,
263
                nodes,
264
                config);
265
        operation.execute(monitor, info);
266

  
267
        Classification reloadedClassification = classificationService.load(classification.getUuid());
268
        Assert.assertNull(reloadedClassification);
269
        TaxonNode reloadedRootNode = taxonNodeService.load(rootNode.getUuid());
270
        Assert.assertNull(reloadedRootNode);
271

  
272
    }
273

  
274

  
275
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/operation/TaxonNameEditorTest.java
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.operation;
11

  
12
import java.util.ArrayList;
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.Logger;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.junit.Assert;
21
import org.junit.Test;
22
import org.unitils.dbunit.annotation.DataSet;
23

  
24
import eu.etaxonomy.cdm.api.service.IClassificationService;
25
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
26
import eu.etaxonomy.cdm.api.service.ITaxonService;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.name.BotanicalName;
29
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
30
import eu.etaxonomy.cdm.model.name.NonViralName;
31
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
32
import eu.etaxonomy.cdm.model.taxon.Synonym;
33
import eu.etaxonomy.cdm.model.taxon.Taxon;
34
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
35
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
36
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
37

  
38
/**
39
 * @author cmathew
40
 * @date 3 Feb 2015
41
 *
42
 */
43

  
44
@DataSet
45
public class TaxonNameEditorTest extends BaseOperationTest {
46

  
47
    private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
48

  
49
    ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
50
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
51
    IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
52

  
53
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
54

  
55

  
56
    @Test
57
    public void testAddHomotypicSynonym() throws ExecutionException {
58
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
59

  
60
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
61
        Taxon taxon = taxonNode.getTaxon();
62
        HomotypicalGroup group = taxon.getHomotypicGroup();
63
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
64
        newSynonymName.setTitleCache("New Synonym", true);
65
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
66
                undoContext, taxon, group, newSynonymName, postOperation);
67

  
68
        operation.execute(monitor, info);
69
        taxonNodeService.merge(taxonNode);
70
        Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
71
        Assert.assertEquals(taxon.getSynonyms().size(), 1);
72
        Iterator<Synonym> synonymItr = taxon.getSynonyms().iterator();
73
        Synonym synonym = synonymItr.next();
74
        Assert.assertTrue(taxon.getHomotypicGroup().getTypifiedNames().contains(synonym.getName()));
75
    }
76

  
77
    @Test
78
    public void addHeterotypicSynonym() throws ExecutionException {
79
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
80

  
81
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
82
        Taxon taxon = taxonNode.getTaxon();
83
        HomotypicalGroup group = taxon.getHomotypicGroup();
84
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
85
        newSynonymName.setTitleCache("New Synonym", true);
86
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
87
                undoContext, taxon, group, newSynonymName, postOperation);
88

  
89
        operation.execute(monitor, info);
90
        taxonNodeService.merge(taxonNode);
91

  
92

  
93
    }
94

  
95
    @Test
96
    public void addDeleteAddHomotypicSynonym() throws ExecutionException {
97
        UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
98

  
99
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
100
        Taxon taxon = taxonNode.getTaxon();
101
        HomotypicalGroup group = taxon.getHomotypicGroup();
102
        BotanicalName newSynonymName = BotanicalName.NewInstance(null);
103
        newSynonymName.setTitleCache("New Synonym", true);
104
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
105
                undoContext, taxon, group, newSynonymName, postOperation);
106

  
107
        operation.execute(monitor, info);
108
        taxonNodeService.merge(taxonNode);
109
        Assert.assertEquals(taxon.getHomotypicGroup().getTypifiedNames().size(), 2);
110

  
111
        Set<Synonym> synonyms = taxon.getSynonyms();
112
        for(Synonym synonym : synonyms) {
113
            taxonService.deleteSynonym(synonym.getUuid(), taxon.getUuid(), null);
114
        }
115

  
116
        taxonNodeService.merge(taxonNode);
117

  
118
        newSynonymName = BotanicalName.NewInstance(null);
119
        newSynonymName.setTitleCache("Another New Synonym", true);
120
        operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
121
                undoContext, taxon, group, newSynonymName, postOperation);
122

  
123
        operation.execute(monitor, info);
124
        taxonNodeService.merge(taxonNode);
125
    }
126

  
127
    @Test
128
    public void swapSynonymWithAcceptedTaxon() throws ExecutionException {
129
        List<TaxonNode> rootEntities = new ArrayList<TaxonNode>();
130
        UUID taxonNodeUuid = UUID.fromString("d425a971-1abe-4895-9e1f-1e5c8ff1c84c");
131
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
132
        rootEntities.add(taxonNode);
133

  
134
        cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
135

  
136
        UUID taxonUuid = UUID.fromString("9763e5f0-6cd4-4d96-b8a4-4420854f7727");
137
        Taxon taxon = (Taxon)taxonService.load(taxonUuid);
138
        TaxonNameBase taxonName = taxon.getName();
139

  
140
        UUID synonymUuid = UUID.fromString("1eb173bd-b174-4162-8ff5-5136d8f1e746");
141
        Synonym synonym = (Synonym)taxonService.load(synonymUuid);
142
        TaxonNameBase synonymName = synonym.getName();
143

  
144
        taxonService.swapSynonymAndAcceptedTaxon(synonym.getUuid(), taxon.getUuid());
145

  
146
        Assert.assertEquals(taxonName, synonym.getName());
147
        Assert.assertEquals(synonymName, taxon.getName());
148
    }
149

  
150
    @Test
151
    public void addTaxon() {
152
        NonViralName taxonName = NonViralName.NewInstance(null);
153
        Taxon taxon = Taxon.NewInstance(taxonName, null);
154
        taxonService.merge(taxon);
155
    }
156

  
157
}
158

  
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/operation/TaxonNavigatorTest.java
1
// $Id$
2
/**
3
 * Copyright (C) 2015 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.taxeditor.operation;
11

  
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import org.apache.log4j.Logger;
19
import org.eclipse.core.commands.ExecutionException;
20
import org.junit.Assert;
21
import org.junit.Ignore;
22
import org.junit.Test;
23
import org.unitils.dbunit.annotation.DataSet;
24

  
25
import eu.etaxonomy.cdm.api.service.IClassificationService;
26
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
27
import eu.etaxonomy.cdm.api.service.ITaxonService;
28
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
29
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
30
import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator.ChildHandling;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.cdm.model.common.Language;
33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35
import eu.etaxonomy.cdm.model.taxon.Classification;
36
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
37
import eu.etaxonomy.cdm.model.taxon.Taxon;
38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation;
40
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingDeleteTaxonNodeOperation;
41
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
42
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
43
import eu.etaxonomy.taxeditor.operations.BaseOperationTest;
44

  
45
/**
46
 * @author cmathew
47
 * @date 9 Mar 2015
48
 *
49
 */
50
@DataSet
51
public class TaxonNavigatorTest extends BaseOperationTest {
52

  
53
    private static final Logger logger = Logger.getLogger(TaxonNameEditorTest.class);
54

  
55
    ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
56
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
57
    IClassificationService classificationService = getRemoteApplicationController().getClassificationService();
58

  
59
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
60

  
61

  
62

  
63
    @Test
64
    public void testChangeAcceptedTaxonToSynonym() throws ExecutionException {
65

  
66

  
67
        UUID oldTaxonNodeNodeUuid = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
68
        UUID newAcceptedTaxonNodeUuid = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
69

  
70
        TaxonNode oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
71
        TaxonNameBase name = oldTaxonNode.getTaxon().getName();
72

  
73

  
74
        TaxonNode newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
75
        int countTargetSynonyms = newAcceptedTaxonNode.getTaxon().getSynonyms().size();
76
        sessionOwner.addExpectedUpdatedObject(oldTaxonNode.getParent());
77
        sessionOwner.addExpectedUpdatedObject(newAcceptedTaxonNode);
78

  
79
        operation =  new RemotingChangeAcceptedTaxonToSynonymOperation(sessionOwner,
80
                false,
81
                oldTaxonNode.getUuid(),
82
                newAcceptedTaxonNode.getUuid());
83
        operation.execute(monitor, info);
84
        newAcceptedTaxonNode = taxonNodeService.load(newAcceptedTaxonNodeUuid);
85
        oldTaxonNode = taxonNodeService.load(oldTaxonNodeNodeUuid);
86
        Assert.assertNull(oldTaxonNode);
87
        Assert.assertEquals(countTargetSynonyms + 1,newAcceptedTaxonNode.getTaxon().getSynonyms().size());
88
        Assert.assertEquals(name, newAcceptedTaxonNode.getTaxon().getSynonyms().iterator().next().getName());
89

  
90

  
91
    }
92

  
93
    @Test
94
    public void testMoveTaxon() throws ExecutionException {
95

  
96
        UUID taxonNodeToMoveUuid = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
97
        UUID newParentTreeNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
98
        boolean moveToParentNode = true;
99

  
100
        TaxonNode taxonNodeToMove = taxonNodeService.load(taxonNodeToMoveUuid);
101
        TaxonNode oldParent = taxonNodeToMove.getParent();
102
        sessionOwner.addExpectedUpdatedObject(oldParent);
103
        int childCount = oldParent.getCountChildren();
104
        TaxonNode newParentTreeNode = taxonNodeService.load(newParentTreeNodeUuid);
105
        sessionOwner.addExpectedUpdatedObject(newParentTreeNode);
106
        operation = new RemotingMoveTaxonOperation(sessionOwner,
107
                false,
108
                taxonNodeToMove.getUuid(),
109
                newParentTreeNode.getUuid(),
110
                moveToParentNode);
111
        operation.execute(monitor, info);
112
        Assert.assertEquals(childCount-1, oldParent.getCountChildren());
113
        Assert.assertTrue(!oldParent.getChildNodes().contains(taxonNodeToMove));
114
        Assert.assertTrue(newParentTreeNode.getChildNodes().contains(taxonNodeToMove));
115
    }
116

  
117
    @Test
118
    public void testMoveFactualData() throws ExecutionException {
119
        UUID sourceTaxonUuid = UUID.fromString("e40854d7-143f-4054-b229-6ed4cedb4bff");
120
        UUID targetTaxonUuid = UUID.fromString("b8402dc4-5050-4882-a147-01b71e0e47d6");
121

  
122
        Taxon sourceTaxon = CdmBase.deproxy(taxonService.load(sourceTaxonUuid), Taxon.class);
123
        Set<TaxonDescription> sourceDescriptions = new HashSet(sourceTaxon.getDescriptions());
124
        sessionOwner.addExpectedUpdatedObject(sourceTaxon);
125

  
126
        Taxon targetTaxon = CdmBase.deproxy(taxonService.load(targetTaxonUuid), Taxon.class);
127
        int countTargetDescriptions = targetTaxon.getDescriptions().size();
128
        sessionOwner.addExpectedUpdatedObject(targetTaxon);
129

  
130
        operation = new RemotingMoveFactualDataOperation(sessionOwner,
131
                false,
132
                sourceTaxonUuid,
133
                targetTaxonUuid);
134
        operation.execute(monitor, info);
135
        Assert.assertEquals(0, sourceTaxon.getDescriptions().size());
136
        Assert.assertEquals(sourceDescriptions.size() + countTargetDescriptions, targetTaxon.getDescriptions().size());
137
        Assert.assertTrue(targetTaxon.getDescriptions().containsAll(sourceDescriptions));
138
    }
139

  
140
    @Test
141
    public void testDeleteTaxonNodeWithDeleteChildren() throws ExecutionException {
142
        UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
143
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
144
        List<TaxonNode> childNodes = taxonNode.getChildNodes();
145
        List<UUID> childNodeUuids = new ArrayList<UUID>();
146
        for(TaxonNode childNode : childNodes) {
147
            childNodeUuids.add(childNode.getUuid());
148
        }
149
        Assert.assertTrue(taxonNode.getCountChildren() > 0);
150

  
151
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
152
        nodes.add(taxonNode);
153

  
154
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
155
        configNodes.setChildHandling(ChildHandling.DELETE);
156
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
157
        config.setTaxonNodeConfig(configNodes);
158

  
159
        sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
160

  
161
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
162
                false,
163
                nodes,
164
                config);
165
        operation.execute(monitor, info);
166
        TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
167
        Assert.assertNull(reloadedNode);
168
        for(UUID childNodeUuid : childNodeUuids) {
169
            TaxonNode reloadedChildNode = taxonNodeService.load(childNodeUuid);
170
            Assert.assertNull(reloadedChildNode);
171
        }
172
    }
173

  
174
    @Ignore // waiting for #5019 to be fixed
175
    @Test
176
    public void testDeleteTaxonNodes() throws ExecutionException {
177
        UUID taxonNode1Uuid = UUID.fromString("99f03b56-67cd-4e01-9ceb-2362d48f9d07");
178
        UUID taxonNode2Uuid = UUID.fromString("91698cec-615f-4472-9002-feda1a6acded");
179
        UUID taxonNode3Uuid = UUID.fromString("4fe03763-b966-4361-8334-352f6f777588");
180

  
181
        TaxonNode taxonNode1 = taxonNodeService.load(taxonNode1Uuid);
182
        TaxonNode taxonNode2 = taxonNodeService.load(taxonNode2Uuid);
183
        TaxonNode taxonNode3 = taxonNodeService.load(taxonNode3Uuid);
184

  
185
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
186
        nodes.add(taxonNode1);
187
        nodes.add(taxonNode2);
188
        nodes.add(taxonNode3);
189

  
190
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
191

  
192

  
193
        sessionOwner.addExpectedUpdatedObject(taxonNode1.getParent());
194
        sessionOwner.addExpectedUpdatedObject(taxonNode2.getParent());
195
        sessionOwner.addExpectedUpdatedObject(taxonNode3.getParent());
196
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
197
                false,
198
                nodes,
199
                config);
200
        operation.execute(monitor, info);
201
        TaxonNode reloadedNode1 = taxonNodeService.load(taxonNode1.getUuid());
202
        TaxonNode reloadedNode2 = taxonNodeService.load(taxonNode2.getUuid());
203
        TaxonNode reloadedNode3 = taxonNodeService.load(taxonNode3.getUuid());
204
        Assert.assertNull(reloadedNode1);
205
        Assert.assertNull(reloadedNode2);
206
        Assert.assertNull(reloadedNode3);
207

  
208
    }
209

  
210
    @Test
211
    public void testDeleteTaxonNodeWithMovingChildrenToParentNode() throws ExecutionException {
212
        UUID taxonNodeUuid = UUID.fromString("2f05d429-632d-4230-b9cb-70299360b470");
213
        TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
214
        TaxonNode parentTaxonNode = taxonNode.getParent();
215
        List<TaxonNode> childNodes = taxonNode.getChildNodes();
216
        List<UUID> childNodeUuids = new ArrayList<UUID>();
217
        for(TaxonNode childNode : childNodes) {
218
            childNodeUuids.add(childNode.getUuid());
219
        }
220
        Assert.assertTrue(taxonNode.getCountChildren() > 0);
221

  
222
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
223
        nodes.add(taxonNode);
224

  
225
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
226
        configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
227
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
228
        config.setTaxonNodeConfig(configNodes);
229

  
230
        sessionOwner.addExpectedUpdatedObject(taxonNode.getParent());
231
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
232
                false,
233
                nodes,
234
                config);
235
        operation.execute(monitor, info);
236
        TaxonNode reloadedNode = taxonNodeService.load(taxonNode.getUuid());
237
        Assert.assertNull(reloadedNode);
238
        List<TaxonNode> parentChildNodes = parentTaxonNode.getChildNodes();
239
        List<UUID> parentChildNodeUuids = new ArrayList<UUID>();
240
        for(TaxonNode parentChildNode : parentChildNodes) {
241
            parentChildNodeUuids.add(parentChildNode.getUuid());
242
        }
243
        parentChildNodeUuids.containsAll(childNodeUuids);
244

  
245
    }
246

  
247
    @Test
248
    @DataSet("TaxonNavigatorTest.testDeleteClassificationWithDeleteChildren.xml")
249
    public void testDeleteClassificationWithDeleteChildren() throws ExecutionException {
250
        UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");
251
        Classification classification = classificationService.load(classificationUuid);
252
        TaxonNode rootNode = classification.getRootNode();
253
        Set<ITaxonTreeNode> nodes = new HashSet<ITaxonTreeNode>();
254
        nodes.add(classification);
255

  
256
        TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
257
        configNodes.setChildHandling(ChildHandling.DELETE);
258
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
259
        config.setTaxonNodeConfig(configNodes);
260

  
261
        operation = new RemotingDeleteTaxonNodeOperation(sessionOwner,
262
                false,
263
                nodes,
264
                config);
265
        operation.execute(monitor, info);
266

  
267
        Classification reloadedClassification = classificationService.load(classification.getUuid());
268
        Assert.assertNull(reloadedClassification);
269
        TaxonNode reloadedRootNode = taxonNodeService.load(rootNode.getUuid());
270
        Assert.assertNull(reloadedRootNode);
271

  
272
    }
273

  
274

  
275
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java
1
// $Id$
2
/**
3
 * Copyright (C) 2014 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.taxeditor.session;
11

  
12
import java.util.Arrays;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

  
19
import org.apache.log4j.Logger;
20
import org.hibernate.collection.spi.PersistentCollection;
21
import org.junit.Assert;
22
import org.junit.BeforeClass;
23
import org.junit.Test;
24
import org.unitils.dbunit.annotation.DataSet;
25

  
26
import eu.etaxonomy.cdm.api.service.ICommonService;
27
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
28
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
29
import eu.etaxonomy.cdm.api.service.ITaxonService;
30
import eu.etaxonomy.cdm.model.agent.AgentBase;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.cdm.model.common.Credit;
33
import eu.etaxonomy.cdm.model.common.Extension;
34
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
35
import eu.etaxonomy.cdm.model.common.Language;
36
import eu.etaxonomy.cdm.model.common.LanguageString;
37
import eu.etaxonomy.cdm.model.description.KeyStatement;
38
import eu.etaxonomy.cdm.model.description.PolytomousKey;
39
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
40
import eu.etaxonomy.cdm.model.media.Rights;
41
import eu.etaxonomy.cdm.model.taxon.Taxon;
42
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
43
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
44
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
45

  
46
/**
47
 * @author cmathew
48
 * @date 7 Oct 2014
49
 *
50
 */
51
@DataSet
52
public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
53

  
54
    private static final Logger logger = Logger.getLogger(CdmEntitySessionAwareTest.class);
55

  
56
    UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
57
    UUID subKeyUuid = UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01");
58
    //UUID polytomousKeyUuid = UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
59
    UUID taxon1Uuid = UUID.fromString("2b336df7-29e8-4f79-985f-66502739d22f");
60

  
61

  
62
    IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
63
    IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
64
    ICommonService commonService = getRemoteApplicationController().getCommonService();
65
    ITaxonService taxonService = getRemoteApplicationController().getTaxonService();
66

  
67
    Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
68

  
69

  
70

  
71
    @BeforeClass
72
    public static void initializePolytomousKeyTest() {
73
    }
74

  
75

  
76
    @Test
77
    public void readAllPolytomousKeys() {
78
        List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
79
        Iterator<PolytomousKey> pKeysItr = pKeys.iterator();
80
        Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
81
        Assert.assertEquals(pKeysItr.next().getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
82
    }
83

  
84

  
85
    @Test
86
    //@DataSet("PolytomousKeyTest.readPolytmousKeyData.xml")
87
    public void readPolytmousKeyData() {
88
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
89
        Set<Taxon> taxonomicScope = pKey.getTaxonomicScope();
90
        Iterator<Taxon> tsItr = taxonomicScope.iterator();
91
        Taxon taxon = tsItr.next();
92

  
93
        Assert.assertEquals("Achillea sec. Cyprus", taxon.getTitleCache());
94
        Assert.assertEquals(tsItr.hasNext(), false);
95

  
96
        List<Credit> credits = pKey.getCredits();
97
        AgentBase agent = credits.get(0).getAgent();
98
        Assert.assertEquals(agent.getId(),4809);
99
        Assert.assertEquals(agent.getTitleCache(),"R. A. Graham");
100
        Assert.assertEquals(credits.get(0).getText(),"Credits Text Test");
101

  
102
        Set<Extension> exts = pKey.getExtensions();
103
        Iterator<Extension> extItr = exts.iterator();
104
        Extension ext = extItr.next();
105
        Assert.assertEquals(ext.getValue(), "http://test.com");
106

  
107
        Set<Rights> rights = pKey.getRights();
108
        Iterator<Rights> rightsItr = rights.iterator();
109
        Rights right = rightsItr.next();
110
        Assert.assertEquals(right.getText(),"Rights Text Test");
111

  
112
        Set<IdentifiableSource> sources = pKey.getSources();
113
        Iterator<IdentifiableSource> sourcesItr = sources.iterator();
114
        IdentifiableSource source = sourcesItr.next();
115
        Assert.assertEquals(source.getId(), 23710);
116
        source = sourcesItr.next();
117
        Assert.assertEquals(source.getId(), 23711);
118

  
119
        // TO DO : Added tests for Annotations , Markers
120
    }
121

  
122
    @Test
123
    public void readPolytomousKeyDataFromNodes() {
124
        PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
125
        PolytomousKeyNode rootNode = pKey.getRoot();
126

  
127

  
128
        Assert.assertEquals(rootNode.getId(), 2750);
129

  
130
        Assert.assertEquals(rootNode.getChildAt(0).getId(), 2751);
131
        Assert.assertEquals(rootNode.getChildAt(0).getParent().getId(), rootNode.getId());
132
        Assert.assertEquals(rootNode.getKey().getId(), pKey.getId());
133
        Integer sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(0), "sortIndex");
134
        Assert.assertEquals(sortIndex, new Integer(0));
135
        String statement = "Capitula without ligulate ray-florets; leaves entire or subentire";
136
        Assert.assertEquals(rootNode.getChildAt(0).getStatement().getLabelText(english), statement);
137

  
138
        Assert.assertEquals(rootNode.getChildAt(1).getId(), 2753);
139
        Assert.assertEquals(rootNode.getChildAt(1).getParent().getId(), rootNode.getId());
140
        Assert.assertEquals(rootNode.getChildAt(1).getKey().getId(), pKey.getId());
141
        sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1), "sortIndex");
142
        Assert.assertEquals(sortIndex, new Integer(1));
143
        statement = "Capitula with ligulate ray-florets; leaves pinnatisect";
144
        Assert.assertEquals(rootNode.getChildAt(1).getStatement().getLabelText(english), statement);
145

  
146
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getId(), 2754);
147
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getParent().getId(), rootNode.getChildAt(1).getId());
148
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getKey().getId(), pKey.getId());
149
        sortIndex = (Integer)getFieldValueViaReflection(rootNode.getChildAt(1).getChildAt(0), "sortIndex");
150
        Assert.assertEquals(sortIndex, new Integer(0));
151
        statement = "Ray-florets yellow";
152
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getStatement().getLabelText(english), statement);
153
        Assert.assertEquals(rootNode.getChildAt(1).getChildAt(0).getChildAt(0).getTaxon().getTitleCache(), "Achillea arabica Kotschy sec. Cyprus");
154
    }
155

  
156
    @Test
157
    public void savePolytomousKeyNodeData() {
158
        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
159

  
160
        PolytomousKeyNode pkeynode = pkey.getRoot();
161
        String newQuestion = "New Question";
162
        String newStatement = "New Statement";
163

  
164
        Assert.assertEquals("Question 1",pkeynode.getQuestion().getLabel().get(english).getText());
165
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
166

  
167
            node.setQuestion(null);
168
            node.setStatement(null);
169
        }
170
        //FIXME:Remoting Add tests for feature after fixing problem
171

  
172
        //Feature feature = pkeynode.getFeature();
173
        //Assert.assertEquals(feature.getTitleCache(),"Systematics");
174
        //pkeynode.setFeature(null);
175

  
176
        Assert.assertEquals(pkeynode.getChildAt(0).getModifyingText().get(english).getText(),"Modifying Text 1a");
177
        String modifyingText = "Modifying Text 1a updated";
178

  
179
        //pkeynode.getChildAt(0).putModifyingText(english, modifyingText);
180

  
181
        Assert.assertEquals(pkeynode.getChildAt(0).getSubkey().getId(),751);
182
        Assert.assertEquals("Asphodeline", pkeynode.getChildAt(0).getSubkey().getTitleCache());
183
        Assert.assertNull(pkeynode.getChildAt(1).getTaxon());
184
        Taxon taxon = CdmBase.deproxy(taxonService.find(taxon1Uuid),Taxon.class);
185
        pkeynode.getChildAt(1).setTaxon(taxon);
186

  
187
        EntityCacherDebugResult debugResult = new EntityCacherDebugResult(cacher,  Arrays.asList(pkey));
188

  
189
        polytomousKeyService.merge(pkey);
190

  
191
        pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
192
        sessionOwner = new MockSessionOwner();
193

  
194

  
195
        pkeynode = pkey.getRoot();
196
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
197
            Assert.assertNull(node.getQuestion());
198
            node.setQuestion(KeyStatement.NewInstance(english,newQuestion));
199
            Assert.assertNull(node.getStatement());
200
            node.setStatement(KeyStatement.NewInstance(english,newStatement));
201
        }
202

  
203

  
204
        Assert.assertEquals(pkeynode.getChildAt(1).getTaxon(), taxon);
205

  
206
        polytomousKeyService.merge(pkey);
207

  
208
        pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
209
        sessionOwner = new MockSessionOwner();
210

  
211

  
212
        pkeynode = pkey.getRoot();
213
        for(PolytomousKeyNode node : pkeynode.getChildren()) {
214
            Assert.assertNotNull(node.getQuestion());
215
            Map<Language, LanguageString> label = node.getQuestion().getLabel();
216
            Assert.assertEquals(newQuestion, label.get(english).getText());
217
            Assert.assertNotNull(node.getStatement());
218
            Assert.assertEquals(newStatement, node.getStatement().getLabel(english).getText());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff