1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.conversation;
20
21 import org.apache.myfaces.orchestra.conversation.basic.LogConversationMessager;
22 import org.apache.myfaces.orchestra.conversation.model.UserData;
23 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
24 import org.apache.myfaces.orchestra.frameworkAdapter.local.LocalFrameworkAdapter;
25 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
26
27
28
29
30 public class TestConversationPersistence extends AbstractDependencyInjectionSpringContextTests
31 {
32 protected String[] getConfigLocations()
33 {
34 return new String[]
35 {
36 "classpath:testApplicationContext.xml"
37 };
38 }
39
40 protected void onSetUp() throws Exception
41 {
42 super.onSetUp();
43
44 LocalFrameworkAdapter frameworkAdapter = new LocalFrameworkAdapter();
45 frameworkAdapter.setApplicationContext(applicationContext);
46 frameworkAdapter.setConversationMessager(new LogConversationMessager());
47 FrameworkAdapter.setCurrentInstance(frameworkAdapter);
48 }
49
50 public void testPersistence()
51 {
52 final String BEAN_NAME = "persistentBackingBean";
53
54 PersistentBackingBean conv = (PersistentBackingBean) applicationContext.getBean(BEAN_NAME);
55
56
57 UserData user = conv.createUser();
58 UserData user2 = conv.readUser(user.getId());
59
60 assertSame("has to be the same user",user , user2);
61
62 conv.invalidateConversation();
63
64
65 UserData user3 = conv.readUser(user.getId());
66
67 assertNotSame("should not be the same user", user ,user3);
68 }
69
70 public void testRestartConversation()
71 {
72 final String BEAN_NAME = "persistentBackingBean";
73
74 PersistentBackingBean bean = (PersistentBackingBean) applicationContext.getBean(BEAN_NAME);
75
76 UserData user = bean.createUser();
77
78 bean.invalidateAndRestartConversation();
79
80
81 UserData restartedUser = bean.getRestartedUser();
82
83 assertNotNull("should have got a user", restartedUser);
84 assertNotSame("should not be the same user", user, restartedUser);
85 assertEquals("has to be the same user id", user.getId(), restartedUser.getId());
86
87
88 ConversationManager.getInstance().clearCurrentConversationContext();
89
90 bean.updateUser(user.getId(), "test2");
91
92
93 bean.invalidateConversation();
94
95 UserData user4 = bean.readUser(user.getId());
96
97 assertNotNull(user4);
98 assertEquals(user.getId(), user4.getId());
99 assertEquals("test", user4.getUsername());
100 }
101 }