1
|
package eu.etaxonomy.taxeditor.session;
|
2
|
|
3
|
import java.util.Iterator;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import org.junit.Assert;
|
8
|
import org.junit.Test;
|
9
|
import org.unitils.dbunit.annotation.DataSet;
|
10
|
|
11
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
12
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
13
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
14
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
15
|
import eu.etaxonomy.cdm.model.common.Language;
|
16
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
17
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
18
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
19
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
|
21
|
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
|
22
|
|
23
|
//FIXME:Remoting fix data issue : User#30
|
24
|
//@Ignore
|
25
|
@DataSet
|
26
|
public class CdmEntitySessionManagerTest extends RemotingSessionAwareTest {
|
27
|
|
28
|
IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
|
29
|
IPolytomousKeyNodeService polytomousKeyNodeService = getRemoteApplicationController().getPolytomousKeyNodeService();
|
30
|
|
31
|
private final UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
|
32
|
private final Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
33
|
|
34
|
@Test
|
35
|
public void manageNullSessionTest() {
|
36
|
|
37
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
38
|
cdmEntitySessionManager.bind(null);
|
39
|
Assert.assertSame(pKey, pKey);
|
40
|
Assert.assertNull(getActiveSession());
|
41
|
}
|
42
|
|
43
|
@Test
|
44
|
public void manageSessionWithObjectTest() {
|
45
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
46
|
|
47
|
Assert.assertNotNull(getActiveSession());
|
48
|
|
49
|
// FIXME:Remoting fix test of setting root entities
|
50
|
//Assert.assertEquals(rootEntities.size(),1);
|
51
|
//Assert.assertSame(rootEntities.get(0), pKey);
|
52
|
|
53
|
String upTitleCache = "Updated Title Cache";
|
54
|
String upStatement = "Updated Statement";
|
55
|
pKey.setTitleCache(upTitleCache, true);
|
56
|
|
57
|
PolytomousKeyNode node = pKey.getRoot().getChildAt(0);
|
58
|
node.getStatement().getLabel(english).setText(upStatement);
|
59
|
polytomousKeyService.merge(pKey, true);
|
60
|
|
61
|
pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
62
|
|
63
|
Assert.assertEquals(pKey.getTitleCache(), upTitleCache);
|
64
|
node = pKey.getRoot().getChildAt(0);
|
65
|
KeyStatement statement = node.getStatement();
|
66
|
LanguageString label = statement.getLabel(english);
|
67
|
Assert.assertEquals(label.getText(), upStatement);
|
68
|
}
|
69
|
|
70
|
@Test
|
71
|
public void manageSessionWithListTest() {
|
72
|
List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
|
73
|
Assert.assertNotNull(getActiveSession());
|
74
|
|
75
|
|
76
|
// FIXME:Remoting fix test of setting root entities
|
77
|
//Assert.assertEquals(rootEntities.size(),2);
|
78
|
//Assert.assertSame(rootEntities.get(0),pKeys.get(0));
|
79
|
//Assert.assertEquals(rootEntities.get(0).getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
|
80
|
//Assert.assertSame(rootEntities.get(1),pKeys.get(1));
|
81
|
//Assert.assertEquals(rootEntities.get(1).getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
|
82
|
|
83
|
String upTitleCache = "Updated Title Cache";
|
84
|
String upStatement = "Updated Statement";
|
85
|
pKeys.get(0).setTitleCache(upTitleCache, true);
|
86
|
polytomousKeyService.merge(pKeys.get(0));
|
87
|
PolytomousKey key = pKeys.get(1);
|
88
|
PolytomousKeyNode root = key.getRoot();
|
89
|
root = HibernateProxyHelper.deproxy(root, PolytomousKeyNode.class);
|
90
|
PolytomousKeyNode node = root.getChildAt(0);
|
91
|
List<PolytomousKeyNode> nodes = root.getChildren();
|
92
|
node.getStatement().getLabel(english).setText(upStatement);
|
93
|
|
94
|
MergeResult<PolytomousKey> result = polytomousKeyService.merge(key, true);
|
95
|
key = result.getMergedEntity();
|
96
|
pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
|
97
|
|
98
|
Assert.assertEquals(pKeys.get(0).getTitleCache(), upTitleCache);
|
99
|
key = pKeys.get(1);
|
100
|
root = key.getRoot();
|
101
|
nodes = root.getChildren();
|
102
|
Iterator<PolytomousKeyNode> it = nodes.iterator();
|
103
|
if (it.hasNext()){
|
104
|
node = it.next();
|
105
|
} else {
|
106
|
Assert.fail();
|
107
|
}
|
108
|
Assert.assertEquals(node.getStatement().getLabel(english).getText(), upStatement);
|
109
|
}
|
110
|
}
|