23
23
import org .springframework .context .support .GenericXmlApplicationContext ;
24
24
import org .springframework .conversation .manager .ConversationManager ;
25
25
import org .springframework .conversation .manager .ConversationStore ;
26
+ import org .springframework .conversation .manager .MutableConversation ;
26
27
import org .springframework .conversation .scope .ConversationResolver ;
27
28
28
29
/**
@@ -130,6 +131,8 @@ public void testNestedConversation() {
130
131
assertNotNull (conversation );
131
132
assertFalse (conversation .isTemporary ());
132
133
assertSame (conversation , manager .getCurrentConversation ());
134
+ assertFalse (conversation .isNested ());
135
+ assertFalse (((MutableConversation ) conversation ).isParent ());
133
136
134
137
ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
135
138
assertNotNull (bean );
@@ -138,6 +141,8 @@ public void testNestedConversation() {
138
141
assertNotNull (nestedConversation );
139
142
assertSame (nestedConversation , manager .getCurrentConversation ());
140
143
assertNotSame (conversation , nestedConversation );
144
+ assertTrue (nestedConversation .isNested ());
145
+ assertTrue (((MutableConversation ) conversation ).isParent ());
141
146
142
147
assertSame (bean , context .getBean ("testBean" ));
143
148
@@ -157,10 +162,14 @@ public void testNestedConversationEndingFailure() {
157
162
assertNotNull (conversation );
158
163
assertFalse (conversation .isTemporary ());
159
164
assertSame (conversation , manager .getCurrentConversation ());
165
+ assertFalse (conversation .isNested ());
166
+ assertFalse (((MutableConversation ) conversation ).isParent ());
160
167
161
168
Conversation nestedConversation = manager .beginConversation (false , JoinMode .NESTED );
162
169
assertNotNull (nestedConversation );
163
170
assertNotSame (conversation , nestedConversation );
171
+ assertTrue (nestedConversation .isNested ());
172
+ assertTrue (((MutableConversation ) conversation ).isParent ());
164
173
165
174
try {
166
175
conversation .end (ConversationEndingType .SUCCESS );
@@ -179,6 +188,131 @@ public void testNestedConversationEndingFailure() {
179
188
assertNull (manager .getCurrentConversation ());
180
189
}
181
190
191
+ @ Test
192
+ public void testIsolatedConversation () {
193
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
194
+ assertNotNull (conversation );
195
+ assertFalse (conversation .isTemporary ());
196
+ assertSame (conversation , manager .getCurrentConversation ());
197
+ assertFalse (conversation .isNested ());
198
+ assertFalse (((MutableConversation ) conversation ).isParent ());
199
+
200
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
201
+ assertNotNull (bean );
202
+
203
+ Conversation nestedConversation = manager .beginConversation (false , JoinMode .ISOLATED );
204
+ assertNotNull (nestedConversation );
205
+ assertSame (nestedConversation , manager .getCurrentConversation ());
206
+ assertNotSame (conversation , nestedConversation );
207
+ assertTrue (nestedConversation .isNested ());
208
+ assertTrue (((MutableConversation ) conversation ).isParent ());
209
+
210
+ assertNotSame (bean , context .getBean ("testBean" ));
211
+
212
+ nestedConversation .end (ConversationEndingType .SUCCESS );
213
+ assertSame (conversation , manager .getCurrentConversation ());
214
+
215
+ assertSame (bean , context .getBean ("testBean" ));
216
+
217
+ conversation .end (ConversationEndingType .SUCCESS );
218
+ assertTrue (conversation .isEnded ());
219
+ assertTrue (nestedConversation .isEnded ());
220
+ assertNull (resolver .getCurrentConversationId ());
221
+ assertNull (manager .getCurrentConversation ());
222
+ }
223
+
224
+ @ Test
225
+ public void testJoinedConversation () {
226
+ Conversation conversation = manager .beginConversation (false , JoinMode .ROOT );
227
+ assertNotNull (conversation );
228
+ assertFalse (conversation .isTemporary ());
229
+ assertSame (conversation , manager .getCurrentConversation ());
230
+ assertFalse (conversation .isNested ());
231
+ assertFalse (((MutableConversation ) conversation ).isParent ());
232
+
233
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
234
+ assertNotNull (bean );
235
+
236
+ Conversation joinedConversation = manager .beginConversation (false , JoinMode .JOINED );
237
+ assertNotNull (joinedConversation );
238
+ assertSame (joinedConversation , manager .getCurrentConversation ());
239
+ assertSame (conversation , joinedConversation );
240
+ assertFalse (joinedConversation .isNested ());
241
+ assertFalse (((MutableConversation ) joinedConversation ).isParent ());
242
+
243
+ assertSame (bean , context .getBean ("testBean" ));
244
+
245
+ joinedConversation .end (ConversationEndingType .SUCCESS );
246
+ assertSame (conversation , manager .getCurrentConversation ());
247
+
248
+ assertSame (bean , context .getBean ("testBean" ));
249
+
250
+ conversation .end (ConversationEndingType .SUCCESS );
251
+ assertTrue (conversation .isEnded ());
252
+ assertTrue (joinedConversation .isEnded ());
253
+ assertNull (resolver .getCurrentConversationId ());
254
+ assertNull (manager .getCurrentConversation ());
255
+ }
256
+
257
+ @ Test
258
+ public void testSwitchedConversation () {
259
+ Conversation conversation = manager .beginConversation (false , JoinMode .SWITCHED );
260
+ assertNotNull (conversation );
261
+ assertFalse (conversation .isTemporary ());
262
+ assertSame (conversation , manager .getCurrentConversation ());
263
+ assertFalse (conversation .isNested ());
264
+ assertFalse (((MutableConversation ) conversation ).isParent ());
265
+
266
+ ConversationalBean bean = (ConversationalBean ) context .getBean ("testBean" );
267
+ assertNotNull (bean );
268
+
269
+ Conversation switchedConversation = manager .beginConversation (false , JoinMode .SWITCHED );
270
+ assertNotNull (switchedConversation );
271
+ assertSame (switchedConversation , manager .getCurrentConversation ());
272
+ assertNotSame (conversation , switchedConversation );
273
+ assertFalse (switchedConversation .isNested ());
274
+ assertFalse (((MutableConversation ) switchedConversation ).isParent ());
275
+
276
+ ConversationalBean bean2 = (ConversationalBean ) context .getBean ("testBean" );
277
+ assertNotSame (bean , bean2 );
278
+
279
+ manager .switchConversation (conversation .getId ());
280
+ assertSame (bean , context .getBean ("testBean" ));
281
+
282
+ manager .switchConversation (switchedConversation .getId ());
283
+ assertSame (bean2 , context .getBean ("testBean" ));
284
+
285
+ switchedConversation .end (ConversationEndingType .SUCCESS );
286
+ conversation .end (ConversationEndingType .SUCCESS );
287
+ assertTrue (conversation .isEnded ());
288
+ assertTrue (switchedConversation .isEnded ());
289
+ assertNull (resolver .getCurrentConversationId ());
290
+ assertNull (manager .getCurrentConversation ());
291
+ }
292
+
293
+ @ Test
294
+ public void testSwitchedConversationEnding () {
295
+ Conversation conversation = manager .beginConversation (false , JoinMode .SWITCHED );
296
+ assertNotNull (conversation );
297
+ assertSame (conversation , manager .getCurrentConversation ());
298
+
299
+ Conversation switchedConversation = manager .beginConversation (false , JoinMode .SWITCHED );
300
+ assertNotNull (switchedConversation );
301
+ assertSame (switchedConversation , manager .getCurrentConversation ());
302
+ assertNotSame (conversation , switchedConversation );
303
+
304
+ manager .switchConversation (conversation .getId ());
305
+ manager .switchConversation (switchedConversation .getId ());
306
+
307
+ switchedConversation .end (ConversationEndingType .SUCCESS );
308
+ conversation .end (ConversationEndingType .SUCCESS );
309
+
310
+ assertTrue (conversation .isEnded ());
311
+ assertTrue (switchedConversation .isEnded ());
312
+ assertNull (resolver .getCurrentConversationId ());
313
+ assertNull (manager .getCurrentConversation ());
314
+ }
315
+
182
316
protected static String getContextLocation () {
183
317
return "org/springframework/conversation/conversationTestContext.xml" ;
184
318
}
0 commit comments