Skip to content

Commit 0fda041

Browse files
author
Micha Kiener
committed
SPR-6416, tests
1 parent 2a45182 commit 0fda041

File tree

4 files changed

+134
-1
lines changed

4 files changed

+134
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,28 @@ public void testImplicitConversationEnding() {
344344
assertNull(manager.getCurrentConversation());
345345
}
346346

347+
@Test
348+
public void testConversationAnnotation() {
349+
ConversationalServiceBean serviceBean = context.getBean(ConversationalServiceBean.class);
350+
assertNotNull(serviceBean);
351+
352+
assertNull(serviceBean.getStartingConversation());
353+
assertNull(serviceBean.getEndingConversation());
354+
assertNull(serviceBean.getConversationalConversation());
355+
356+
serviceBean.startConversation();
357+
Conversation conversation1 = serviceBean.getStartingConversation();
358+
assertNotNull(conversation1);
359+
assertNull(serviceBean.getEndingConversation());
360+
assertNull(serviceBean.getConversationalConversation());
361+
362+
serviceBean.endConversation();
363+
Conversation conversation2 = serviceBean.getEndingConversation();
364+
assertNotNull(conversation2);
365+
assertSame(conversation1, conversation2);
366+
assertNull(serviceBean.getConversationalConversation());
367+
}
368+
347369
protected static String getContextLocation() {
348370
return "org/springframework/conversation/conversationTestContext.xml";
349371
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2002-2008 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.springframework.conversation;
17+
18+
19+
/**
20+
* @author Micha Kiener
21+
* @since 3.1
22+
*/
23+
public interface ConversationalServiceBean {
24+
25+
public void startConversation();
26+
27+
public void endConversation();
28+
29+
public void doInConversation();
30+
31+
public Conversation getStartingConversation();
32+
33+
public Conversation getEndingConversation();
34+
35+
public Conversation getConversationalConversation();
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2002-2008 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.springframework.conversation;
17+
18+
import org.springframework.conversation.annotation.BeginConversation;
19+
import org.springframework.conversation.annotation.Conversational;
20+
import org.springframework.conversation.annotation.EndConversation;
21+
import org.springframework.conversation.manager.ConversationManager;
22+
23+
/**
24+
* A test service bean using the different conversation annotations.
25+
*
26+
* @author Micha Kiener
27+
* @since 3.1
28+
*/
29+
public class ConversationalServiceBeanImpl implements ConversationalServiceBean {
30+
private ConversationManager manager;
31+
32+
private Conversation startingConversation;
33+
private Conversation endingConversation;
34+
private Conversation conversationalConversation;
35+
36+
@BeginConversation
37+
public void startConversation() {
38+
startingConversation = manager.getCurrentConversation();
39+
}
40+
41+
@EndConversation
42+
public void endConversation() {
43+
endingConversation = manager.getCurrentConversation();
44+
}
45+
46+
@Conversational
47+
public void doInConversation() {
48+
conversationalConversation = manager.getCurrentConversation();
49+
}
50+
51+
public Conversation getStartingConversation() {
52+
return startingConversation;
53+
}
54+
55+
public Conversation getEndingConversation() {
56+
return endingConversation;
57+
}
58+
59+
public Conversation getConversationalConversation() {
60+
return conversationalConversation;
61+
}
62+
63+
public void setConversationManager(ConversationManager manager) {
64+
this.manager = manager;
65+
}
66+
}

org.springframework.context/src/test/java/org/springframework/conversation/conversationTestContext.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
99
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
1010

11-
<context:annotation-config />
11+
<aop:aspectj-autoproxy/>
12+
<context:annotation-config/>
1213

1314
<bean id="conversationManager" class="org.springframework.conversation.manager.ConversationManagerImpl">
1415
<property name="defaultConversationTimeout" value="0"/>
1516
<property name="conversationStore" ref="conversationStore"/>
1617
<property name="conversationResolver" ref="conversationResolver"/>
1718
</bean>
19+
20+
<bean id="conversationAnnotationAdvice" class="org.springframework.conversation.annotation.ConversationAdvice">
21+
<property name="conversationManager" ref="conversationManager"/>
22+
</bean>
1823

1924
<bean id="conversationStore" class="org.springframework.conversation.SingletonConversationStore">
2025
<property name="useFallbackMap" value="false"/>
@@ -29,4 +34,8 @@
2934
</bean>
3035

3136
<bean id="testBean" class="org.springframework.conversation.ConversationalBean" scope="conversation"/>
37+
38+
<bean id="testService" class="org.springframework.conversation.ConversationalServiceBeanImpl">
39+
<property name="conversationManager" ref="conversationManager"/>
40+
</bean>
3241
</beans>

0 commit comments

Comments
 (0)