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