Project

General

Profile

Download (4.08 KB) Statistics
| Branch: | Tag: | Revision:
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.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
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
18

    
19
public class CdmEntitySessionManagerTest extends BaseRemotingTest {
20

    
21
	private static final Logger logger = Logger.getLogger(CdmEntitySessionManagerTest.class);
22

    
23
	private ICdmEntitySessionEnabled sessionOwner;
24
	private final ICdmEntitySessionManager cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
25
	IPolytomousKeyService polytomousKeyService = getRemoteApplicationController().getPolytomousKeyService();
26

    
27
	private final UUID polytomousKeyUuid = UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66");
28
	private final Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
29

    
30
	private ICdmEntitySession cdmEntitySession;
31

    
32
	@BeforeClass
33
	public static void initializeCdmEntitySessionManagerTest() {
34
		CDMServer.getInstance().setKeepServerRunning(true);
35
		//initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
36
	}
37

    
38
	@Before
39
	public void initializeSession() {
40
		sessionOwner = new MockSessionOwner();
41
		cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
42
	}
43

    
44
	@Test
45
	public void manageNullSessionTest() {
46

    
47
		PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
48
		cdmEntitySessionManager.bind(null);
49
		Assert.assertSame(pKey, pKey);
50
		Assert.assertNull(getActiveSession());
51
	}
52

    
53
	@Test
54
	public void manageSessionWithObjectTest() {
55
		PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
56

    
57
		Assert.assertNotNull(getActiveSession());
58
		List<CdmBase> rootEntities = (List<CdmBase>)getFieldValueViaReflection(getActiveSession(), "rootEntities");
59

    
60
		Assert.assertEquals(rootEntities.size(),1);
61
		Assert.assertSame(rootEntities.get(0), pKey);
62

    
63
		String upTitleCache = "Updated Title Cache";
64
		String upStatement = "Updated Statement";
65
		pKey.setTitleCache(upTitleCache, true);
66

    
67
		pKey.getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
68
		polytomousKeyService.merge(pKey);
69

    
70
		sessionOwner = new MockSessionOwner();
71
		pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
72

    
73

    
74
		Assert.assertEquals(pKey.getTitleCache(), upTitleCache);
75
		Assert.assertEquals(pKey.getRoot().getChildAt(0).getStatement().getLabel(english).getText(), upStatement);
76
	}
77

    
78
	@Test
79
	public void manageSessionWithListTest() {
80
		List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
81
		Assert.assertNotNull(getActiveSession());
82
		List<CdmBase> rootEntities = (List<CdmBase>)getFieldValueViaReflection(getActiveSession(), "rootEntities");
83

    
84
		Assert.assertEquals(rootEntities.size(),2);
85
		Assert.assertSame(rootEntities.get(0),pKeys.get(0));
86
		Assert.assertEquals(rootEntities.get(0).getUuid(),UUID.fromString("9d8bf4f6-a70a-4b80-8556-2ccfb436ff01"));
87

    
88
		Assert.assertSame(rootEntities.get(1),pKeys.get(1));
89
		Assert.assertEquals(rootEntities.get(1).getUuid(),UUID.fromString("0d53ba20-7de4-4baa-bd8a-401048447d66"));
90

    
91
		String upTitleCache = "Updated Title Cache";
92
		String upStatement = "Updated Statement";
93
		pKeys.get(0).setTitleCache(upTitleCache, true);
94
		polytomousKeyService.merge(pKeys.get(0));
95
		pKeys.get(1).getRoot().getChildAt(0).getStatement().getLabel(english).setText(upStatement);
96
		polytomousKeyService.merge(pKeys.get(1));
97

    
98
		sessionOwner = new MockSessionOwner();
99
		pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
100

    
101
		Assert.assertEquals(pKeys.get(0).getTitleCache(), upTitleCache);
102
		Assert.assertEquals(pKeys.get(1).getRoot().getChildAt(0).getStatement().getLabel(english).getText(), upStatement);
103

    
104
	}
105

    
106
}
(1-1/2)