Skip to content

Commit 8adb9a8

Browse files
author
Micha Kiener
committed
SPR-6416, adding basic conversation object tests, improving the access time of the conversation object
1 parent 3244e0a commit 8adb9a8

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

org.springframework.context/src/main/java/org/springframework/conversation/manager/DefaultConversation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public Object removeAttribute(String name) {
118118

119119
public void clear() {
120120
attributes.clear();
121+
touch();
121122
}
122123

123124
public void setId(String id) {
@@ -157,6 +158,8 @@ protected void setParentConversation(MutableConversation parentConversation, boo
157158

158159
public void addChildConversation(MutableConversation conversation, boolean isIsolated) {
159160
checkValidity();
161+
touch();
162+
160163
if (conversation instanceof DefaultConversation) {
161164
// set this conversation as the parent within the given child conversation
162165
((DefaultConversation)conversation).setParentConversation(this, isIsolated);
@@ -170,6 +173,7 @@ public void addChildConversation(MutableConversation conversation, boolean isIso
170173
}
171174

172175
public void removeChildConversation(MutableConversation conversation) {
176+
touch();
173177
if (children != null) {
174178
children.remove(conversation);
175179
if (children.size() == 0) {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2002-2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of 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,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.conversation;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.conversation.manager.DefaultConversation;
22+
import org.springframework.conversation.manager.MutableConversation;
23+
24+
import static org.junit.Assert.*;
25+
26+
/**
27+
* @author Micha Kiener
28+
*/
29+
public class DefaultConversationTest {
30+
31+
@Test
32+
public void testConversationAttribute() {
33+
Conversation conversation = new DefaultConversation();
34+
35+
String test = new String("Test");
36+
conversation.setAttribute("test", test);
37+
38+
assertSame("attribute must be accessible through conversation object", test, conversation.getAttribute("test"));
39+
}
40+
41+
@Test
42+
public void testConversationAttributeInheritance() {
43+
MutableConversation conversation = new DefaultConversation();
44+
45+
String test = new String("Test");
46+
conversation.setAttribute("test", test);
47+
48+
MutableConversation childConversation = new DefaultConversation();
49+
conversation.addChildConversation(childConversation, false);
50+
51+
assertSame("attribute must be accessible through child conversation object", test,
52+
childConversation.getAttribute("test"));
53+
}
54+
55+
@Test
56+
public void testConversationAttributeIsolation() {
57+
MutableConversation conversation = new DefaultConversation();
58+
59+
String test = new String("Test");
60+
conversation.setAttribute("test", test);
61+
62+
MutableConversation childConversation = new DefaultConversation();
63+
conversation.addChildConversation(childConversation, true);
64+
65+
assertNull("attribute must not be accessible from within an isolated conversation",
66+
childConversation.getAttribute("test"));
67+
}
68+
69+
@Test
70+
public void testNewConversationAttributeIsolation() {
71+
MutableConversation conversation = new DefaultConversation();
72+
73+
String test = new String("Test");
74+
conversation.setAttribute("test", test);
75+
76+
MutableConversation childConversation = new DefaultConversation();
77+
conversation.addChildConversation(childConversation, true);
78+
79+
String test2 = new String("Test2");
80+
childConversation.setAttribute("test2", test2);
81+
82+
assertNull("newly added attribute on isolated conversation must not be accessible within its parent",
83+
conversation.getAttribute("test2"));
84+
}
85+
86+
@Test
87+
public void testConversationAttributeRemoval() {
88+
Conversation conversation = new DefaultConversation();
89+
90+
String test = new String("Test");
91+
conversation.setAttribute("test", test);
92+
93+
String test2 = (String)conversation.removeAttribute("test");
94+
assertNotNull("removed attribute must be returned", test2);
95+
assertSame("removed attribute must be the same as being added", test, test2);
96+
97+
assertNull("removed attribute must not be accessible after removal", conversation.getAttribute("test"));
98+
}
99+
}

0 commit comments

Comments
 (0)