1 |
46d0131b
|
Cherian Mathew
|
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.Before;
|
9 |
|
|
import org.junit.BeforeClass;
|
10 |
|
|
import org.junit.Test;
|
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.BaseRemotingTest;
|
17 |
|
|
|
18 |
|
|
public class CdmEntitySessionManagerTest extends BaseRemotingTest {
|
19 |
|
|
|
20 |
|
|
private static final Logger logger = Logger.getLogger(CdmEntitySessionManagerTest.class);
|
21 |
5c6184af
|
Cherian Mathew
|
|
22 |
5528bb74
|
Cherian Mathew
|
private ICdmEntitySessionEnabled sessionOwner;
|
23 |
5c6184af
|
Cherian Mathew
|
private final ICdmEntitySessionManager cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
|
24 |
46d0131b
|
Cherian Mathew
|
IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
|
25 |
|
|
|
26 |
5c6184af
|
Cherian Mathew
|
private final UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
|
27 |
|
|
private final Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
|
28 |
|
|
|
29 |
|
|
private ICdmEntitySession cdmEntitySession;
|
30 |
46d0131b
|
Cherian Mathew
|
|
31 |
|
|
@BeforeClass
|
32 |
5c6184af
|
Cherian Mathew
|
public static void initializeCdmEntitySessionManagerTest() {
|
33 |
46d0131b
|
Cherian Mathew
|
}
|
34 |
|
|
|
35 |
|
|
@Before
|
36 |
|
|
public void initializeSession() {
|
37 |
5c6184af
|
Cherian Mathew
|
sessionOwner = new MockSessionOwner();
|
38 |
|
|
cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
|
39 |
46d0131b
|
Cherian Mathew
|
}
|
40 |
|
|
|
41 |
|
|
@Test
|
42 |
|
|
public void manageNullSessionTest() {
|
43 |
5c6184af
|
Cherian Mathew
|
|
44 |
46d0131b
|
Cherian Mathew
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
45 |
|
|
cdmEntitySessionManager.bind(null);
|
46 |
f399aa02
|
Cherian Mathew
|
Assert.assertSame(pKey, pKey);
|
47 |
48a32bd3
|
Cherian Mathew
|
Assert.assertNull(getActiveSession());
|
48 |
46d0131b
|
Cherian Mathew
|
}
|
49 |
5c6184af
|
Cherian Mathew
|
|
50 |
46d0131b
|
Cherian Mathew
|
@Test
|
51 |
|
|
public void manageSessionWithObjectTest() {
|
52 |
|
|
PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
53 |
f399aa02
|
Cherian Mathew
|
|
54 |
48a32bd3
|
Cherian Mathew
|
Assert.assertNotNull(getActiveSession());
|
55 |
|
|
List<CdmBase> rootEntities = (List<CdmBase>)getFieldValueViaReflection(getActiveSession(), "rootEntities");
|
56 |
46d0131b
|
Cherian Mathew
|
|
57 |
|
|
Assert.assertEquals(rootEntities.size(),1);
|
58 |
|
|
Assert.assertSame(rootEntities.get(0), pKey);
|
59 |
|
|
|
60 |
|
|
String upTitleCache = "Updated Title Cache";
|
61 |
|
|
String upStatement = "Updated Statement";
|
62 |
|
|
pKey.setTitleCache(upTitleCache, true);
|
63 |
|
|
|
64 |
|
|
pKey.getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
|
65 |
|
|
polytomousKeyService.merge(pKey);
|
66 |
|
|
|
67 |
5c6184af
|
Cherian Mathew
|
sessionOwner = new MockSessionOwner();
|
68 |
46d0131b
|
Cherian Mathew
|
pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
|
69 |
f399aa02
|
Cherian Mathew
|
|
70 |
5c6184af
|
Cherian Mathew
|
|
71 |
46d0131b
|
Cherian Mathew
|
Assert.assertEquals(pKey.getTitleCache(), upTitleCache);
|
72 |
|
|
Assert.assertEquals(pKey.getRoot().getChildAt(0).getStatement().getLabel(english).getText(), upStatement);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
@Test
|
76 |
|
|
public void manageSessionWithListTest() {
|
77 |
|
|
List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
|
78 |
48a32bd3
|
Cherian Mathew
|
Assert.assertNotNull(getActiveSession());
|
79 |
|
|
List<CdmBase> rootEntities = (List<CdmBase>)getFieldValueViaReflection(getActiveSession(), "rootEntities");
|
80 |
46d0131b
|
Cherian Mathew
|
|
81 |
|
|
Assert.assertEquals(rootEntities.size(),2);
|
82 |
|
|
Assert.assertSame(rootEntities.get(0),pKeys.get(0));
|
83 |
|
|
Assert.assertEquals(rootEntities.get(0).getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
|
84 |
|
|
|
85 |
|
|
Assert.assertSame(rootEntities.get(1),pKeys.get(1));
|
86 |
|
|
Assert.assertEquals(rootEntities.get(1).getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
|
87 |
|
|
|
88 |
|
|
String upTitleCache = "Updated Title Cache";
|
89 |
|
|
String upStatement = "Updated Statement";
|
90 |
|
|
pKeys.get(0).setTitleCache(upTitleCache, true);
|
91 |
|
|
polytomousKeyService.merge(pKeys.get(0));
|
92 |
|
|
pKeys.get(1).getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
|
93 |
|
|
polytomousKeyService.merge(pKeys.get(1));
|
94 |
|
|
|
95 |
5c6184af
|
Cherian Mathew
|
sessionOwner = new MockSessionOwner();
|
96 |
46d0131b
|
Cherian Mathew
|
pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
|
97 |
f399aa02
|
Cherian Mathew
|
|
98 |
46d0131b
|
Cherian Mathew
|
Assert.assertEquals(pKeys.get(0).getTitleCache(), upTitleCache);
|
99 |
|
|
Assert.assertEquals(pKeys.get(1).getRoot().getChildAt(0).getStatement().getLabel(english).getText(), upStatement);
|
100 |
|
|
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
}
|