Skip to content

Commit 5811d9e

Browse files
author
Micha Kiener
committed
SPR-6416, tests
1 parent e192f60 commit 5811d9e

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

org.springframework.context/src/test/java/org/springframework/conversation/BasicConversationTests.java

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.context.support.GenericXmlApplicationContext;
2424
import org.springframework.conversation.manager.ConversationManager;
2525
import org.springframework.conversation.manager.ConversationStore;
26+
import org.springframework.conversation.manager.MutableConversation;
2627
import org.springframework.conversation.scope.ConversationResolver;
2728

2829
/**
@@ -130,6 +131,8 @@ public void testNestedConversation() {
130131
assertNotNull(conversation);
131132
assertFalse(conversation.isTemporary());
132133
assertSame(conversation, manager.getCurrentConversation());
134+
assertFalse(conversation.isNested());
135+
assertFalse(((MutableConversation) conversation).isParent());
133136

134137
ConversationalBean bean = (ConversationalBean) context.getBean("testBean");
135138
assertNotNull(bean);
@@ -138,6 +141,8 @@ public void testNestedConversation() {
138141
assertNotNull(nestedConversation);
139142
assertSame(nestedConversation, manager.getCurrentConversation());
140143
assertNotSame(conversation, nestedConversation);
144+
assertTrue(nestedConversation.isNested());
145+
assertTrue(((MutableConversation) conversation).isParent());
141146

142147
assertSame(bean, context.getBean("testBean"));
143148

@@ -157,10 +162,14 @@ public void testNestedConversationEndingFailure() {
157162
assertNotNull(conversation);
158163
assertFalse(conversation.isTemporary());
159164
assertSame(conversation, manager.getCurrentConversation());
165+
assertFalse(conversation.isNested());
166+
assertFalse(((MutableConversation) conversation).isParent());
160167

161168
Conversation nestedConversation = manager.beginConversation(false, JoinMode.NESTED);
162169
assertNotNull(nestedConversation);
163170
assertNotSame(conversation, nestedConversation);
171+
assertTrue(nestedConversation.isNested());
172+
assertTrue(((MutableConversation) conversation).isParent());
164173

165174
try {
166175
conversation.end(ConversationEndingType.SUCCESS);
@@ -179,6 +188,131 @@ public void testNestedConversationEndingFailure() {
179188
assertNull(manager.getCurrentConversation());
180189
}
181190

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+
182316
protected static String getContextLocation() {
183317
return "org/springframework/conversation/conversationTestContext.xml";
184318
}

0 commit comments

Comments
 (0)