@@ -72,6 +72,113 @@ public void testTemporaryConversation() {
72
72
assertNull (resolver .getCurrentConversationId ());
73
73
}
74
74
75
+ @ Test
76
+ public void testNewConversation () {
77
+ Conversation conversation = manager .beginConversation (false , JoinMode .NEW );
78
+ assertNotNull (conversation );
79
+ assertFalse (conversation .isTemporary ());
80
+ assertSame (conversation , manager .getCurrentConversation ());
81
+
82
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
83
+ assertNotNull (bean );
84
+
85
+ conversation .end (ConversationEndingType .SUCCESS );
86
+ assertTrue (conversation .isEnded ());
87
+ assertNull (resolver .getCurrentConversationId ());
88
+ assertNull (manager .getCurrentConversation ());
89
+ }
90
+
91
+ @ Test
92
+ public void testRootConversation () {
93
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
94
+ assertNotNull (conversation );
95
+ assertFalse (conversation .isTemporary ());
96
+ assertSame (conversation , manager .getCurrentConversation ());
97
+
98
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
99
+ assertNotNull (bean );
100
+
101
+ conversation .end (ConversationEndingType .SUCCESS );
102
+ assertTrue (conversation .isEnded ());
103
+ assertNull (resolver .getCurrentConversationId ());
104
+ assertNull (manager .getCurrentConversation ());
105
+ }
106
+
107
+ @ Test
108
+ public void testRootConversationFailure () {
109
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
110
+ assertNotNull (conversation );
111
+ assertFalse (conversation .isTemporary ());
112
+ assertSame (conversation , manager .getCurrentConversation ());
113
+
114
+ try {
115
+ manager .beginConversation (false , JoinMode .ROOT );
116
+ fail ("IllegalStateException must be thrown as there is a current conversation in place already." );
117
+ } catch (IllegalStateException e ) {
118
+ // must happen!
119
+ }
120
+
121
+ conversation .end (ConversationEndingType .SUCCESS );
122
+ assertTrue (conversation .isEnded ());
123
+ assertNull (resolver .getCurrentConversationId ());
124
+ assertNull (manager .getCurrentConversation ());
125
+ }
126
+
127
+ @ Test
128
+ public void testNestedConversation () {
129
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
130
+ assertNotNull (conversation );
131
+ assertFalse (conversation .isTemporary ());
132
+ assertSame (conversation , manager .getCurrentConversation ());
133
+
134
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
135
+ assertNotNull (bean );
136
+
137
+ Conversation nestedConversation = manager .beginConversation (false , JoinMode .NESTED );
138
+ assertNotNull (nestedConversation );
139
+ assertSame (nestedConversation , manager .getCurrentConversation ());
140
+ assertNotSame (conversation , nestedConversation );
141
+
142
+ assertSame (bean , context .getBean ("testBean" ));
143
+
144
+ nestedConversation .end (ConversationEndingType .SUCCESS );
145
+ assertSame (conversation , manager .getCurrentConversation ());
146
+
147
+ conversation .end (ConversationEndingType .SUCCESS );
148
+ assertTrue (conversation .isEnded ());
149
+ assertTrue (nestedConversation .isEnded ());
150
+ assertNull (resolver .getCurrentConversationId ());
151
+ assertNull (manager .getCurrentConversation ());
152
+ }
153
+
154
+ @ Test
155
+ public void testNestedConversationEndingFailure () {
156
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
157
+ assertNotNull (conversation );
158
+ assertFalse (conversation .isTemporary ());
159
+ assertSame (conversation , manager .getCurrentConversation ());
160
+
161
+ Conversation nestedConversation = manager .beginConversation (false , JoinMode .NESTED );
162
+ assertNotNull (nestedConversation );
163
+ assertNotSame (conversation , nestedConversation );
164
+
165
+ try {
166
+ conversation .end (ConversationEndingType .SUCCESS );
167
+ fail ("There must be an IllegalStateException as trying to end a parent conversation without having its nested conversation ended first" );
168
+ } catch (IllegalStateException e ) {
169
+ // must happen
170
+ }
171
+
172
+ nestedConversation .end (ConversationEndingType .SUCCESS );
173
+ assertSame (conversation , manager .getCurrentConversation ());
174
+
175
+ conversation .end (ConversationEndingType .SUCCESS );
176
+ assertTrue (conversation .isEnded ());
177
+ assertTrue (nestedConversation .isEnded ());
178
+ assertNull (resolver .getCurrentConversationId ());
179
+ assertNull (manager .getCurrentConversation ());
180
+ }
181
+
75
182
protected static String getContextLocation () {
76
183
return "org/springframework/conversation/conversationTestContext.xml" ;
77
184
}
0 commit comments