removed conversation prototype from 3.1 codebase

This commit is contained in:
Juergen Hoeller
2011-10-11 16:22:15 +00:00
parent 60fb3efc2b
commit 0d02ef5fe5
29 changed files with 0 additions and 2674 deletions

View File

@@ -1,142 +0,0 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.conversation;
import org.junit.Test;
import org.springframework.conversation.manager.DefaultConversationManager;
import org.springframework.conversation.manager.LocalTransientConversationRepository;
import org.springframework.conversation.manager.ThreadLocalConversationResolver;
import static org.junit.Assert.*;
/**
* @author Micha Kiener
*/
public class ConversationManagerTest {
@Test
public void testNewConversationCreation() {
ConversationManager manager = createConversationManager();
assertNotNull("manager must not be null", manager);
Conversation conversation = manager.getCurrentConversation();
assertNotNull("implicit creation of a current conversation must not return null", conversation);
Conversation conversation2 = manager.getCurrentConversation();
assertSame("subsequent invocation of current conversation must return the same object", conversation,
conversation2);
conversation2 = manager.getCurrentConversation(false);
assertSame("subsequent invocation of current conversation must return the same object", conversation,
conversation2);
conversation2 = manager.getCurrentConversation(true);
assertSame("subsequent invocation of current conversation must return the same object", conversation,
conversation2);
}
@Test
public void testNewConversationCreationAndRemoval() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
manager.endCurrentConversation(true);
Conversation conversation2 = manager.getCurrentConversation();
assertNotSame("an ended conversation must not be reused", conversation, conversation2);
manager.endCurrentConversation(true);
conversation = manager.getCurrentConversation(false);
assertNull("Requesting the current conversation without implicit creation must not create one", conversation);
}
@Test
public void testNewNestedConversation() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
Conversation childConversation = manager.beginConversation(ConversationType.NESTED);
assertNotSame("child conversation must be different from its parent", conversation, childConversation);
assertSame("child conversation must be linked to its parent", conversation, childConversation.getParent());
assertSame("child conversation must be the current one", childConversation, manager.getCurrentConversation());
assertTrue("child conversation must be nested", childConversation.isNested());
assertFalse("child conversation must not be isolated", childConversation.isIsolated());
}
@Test
public void testNewIsolatedConversation() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
Conversation childConversation = manager.beginConversation(ConversationType.ISOLATED);
assertNotSame("child conversation must be different from its parent", conversation, childConversation);
assertSame("child conversation must be linked to its parent", conversation, childConversation.getParent());
assertSame("child conversation must be the current one", childConversation, manager.getCurrentConversation());
assertTrue("child conversation must be nested", childConversation.isNested());
assertTrue("child conversation must be isolated", childConversation.isIsolated());
}
@Test
public void testAndEndNewNestedConversation() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
Conversation childConversation = manager.beginConversation(ConversationType.NESTED);
assertSame("child conversation must be the current one", childConversation, manager.getCurrentConversation());
manager.endCurrentConversation(false);
assertSame("after ending a child conversation, its parent has to be the current one", conversation,
manager.getCurrentConversation());
}
@Test
public void testAndRootEndNewNestedConversation() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
Conversation childConversation = manager.beginConversation(ConversationType.NESTED);
assertSame("child conversation must be the current one", childConversation, manager.getCurrentConversation());
manager.endCurrentConversation(true);
assertNull("ending a conversation with root mode, will end in having no current conversation",
manager.getCurrentConversation(false));
}
@Test
public void testImplicitEnding() {
ConversationManager manager = createConversationManager();
Conversation conversation = manager.getCurrentConversation();
Conversation newConversation = manager.beginConversation(ConversationType.NEW);
assertSame("new conversation must be the current one", newConversation, manager.getCurrentConversation());
manager.endCurrentConversation(true);
assertNull("implicit ending must not reactivate previous conversation", manager.getCurrentConversation(false));
}
protected ConversationManager createConversationManager() {
DefaultConversationManager manager = new DefaultConversationManager();
LocalTransientConversationRepository repository = new LocalTransientConversationRepository();
ThreadLocalConversationResolver resolver = new ThreadLocalConversationResolver();
manager.setConversationRepository(repository);
manager.setConversationResolver(resolver);
return manager;
}
}

View File

@@ -1,237 +0,0 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.conversation;
import java.util.List;
import org.junit.Test;
import org.springframework.conversation.manager.ConversationRepository;
import org.springframework.conversation.manager.LocalTransientConversationRepository;
import org.springframework.conversation.manager.MutableConversation;
import static org.junit.Assert.*;
/**
* @author Micha Kiener
*/
public class ConversationRepositoryTest {
@Test
public void testConversationCreation() {
ConversationRepository repository = createRepository();
assertNotNull("repository must not be null", repository);
MutableConversation conversation = repository.createNewConversation();
assertNotNull("conversation object must not be null", conversation);
assertNull("Id must not be set after creation", conversation.getId());
assertNotNull("List of children must never be null", conversation.getChildren());
assertEquals("Children list must be empty", 0, conversation.getChildren().size());
}
@Test
public void testConversationCreationAndStorage() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String conversationId = conversation.getId();
assertNotNull("ID must not be null after storage of a conversation", conversationId);
MutableConversation conversationRequested = repository.getConversation(conversationId);
assertNotNull("Conversation must be available after storage", conversationRequested);
assertSame("Conversation objects must be the same in a transient repository", conversation,
conversationRequested);
}
@Test
public void testConversationCreationStorageAndRemoval() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String conversationId = conversation.getId();
repository.removeConversation(conversationId, true);
MutableConversation conversationRequested = repository.getConversation(conversationId);
assertNull("Conversation must no longer be available after removal", conversationRequested);
}
@Test
public void testConversationHierarchyCreation() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String rootConversationId = conversation.getId();
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
assertNotNull("child conversation must not be null", childConversation);
assertNotNull("parent conversation must be available", childConversation.getParent());
assertSame("parent conversation and root conversation must be the same", conversation,
childConversation.getParent());
assertFalse("nested conversation must not be isolated", childConversation.isIsolated());
List<? extends Conversation> children = conversation.getChildren();
assertNotNull("children list must never be null", children);
assertEquals("children size must be one", 1, children.size());
assertSame("child conversation must be available through the children list of the root conversation",
childConversation, children.get(0));
repository.storeConversation(childConversation);
String childConversationId = childConversation.getId();
assertNotNull("child conversation id must be set after storage", childConversationId);
assertNotSame("root and child conversation id must be different", rootConversationId, childConversationId);
assertNotNull("root conversation must be retrievable through repository",
repository.getConversation(rootConversationId));
assertNotNull("child conversation must be retrievable through repository",
repository.getConversation(childConversationId));
assertSame("root conversation must be the same, if getRoot is invoked", conversation, conversation.getRoot());
assertSame("root conversation must be the same, if getRoot is invoked", conversation,
childConversation.getRoot());
}
@Test
public void testConversationHierarchyCreationAndSingleRemoval() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String rootConversationId = conversation.getId();
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
repository.storeConversation(childConversation);
String childConversationId = childConversation.getId();
repository.removeConversation(childConversationId, false);
assertNull("parent must not be available after removal", childConversation.getParent());
assertEquals("list of children must be empty after removal", 0, conversation.getChildren().size());
assertNull("child conversation must not be available through the repository after removal",
repository.getConversation(childConversationId));
assertNotNull("root conversation must still be available after removal of its child conversation",
repository.getConversation(rootConversationId));
}
@Test
public void testConversationHierarchyCreationAndRootThroughChildRemoval() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String rootConversationId = conversation.getId();
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
repository.storeConversation(childConversation);
String childConversationId = childConversation.getId();
repository.removeConversation(childConversationId, true);
assertNull("parent must not be available after removal", childConversation.getParent());
assertEquals("list of children must be empty after removal", 0, conversation.getChildren().size());
assertNull("child conversation must not be available through the repository after removal",
repository.getConversation(childConversationId));
assertNull("root conversation must not be available after root removal",
repository.getConversation(rootConversationId));
}
@Test
public void testConversationHierarchyCreationAndRootThroughParentRemoval() {
ConversationRepository repository = createRepository();
MutableConversation conversation = repository.createNewConversation();
repository.storeConversation(conversation);
String rootConversationId = conversation.getId();
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
repository.storeConversation(childConversation);
String childConversationId = childConversation.getId();
repository.removeConversation(rootConversationId, false);
assertNull("parent must not be available after removal", childConversation.getParent());
assertEquals("list of children must be empty after removal", 0, conversation.getChildren().size());
assertNull("child conversation must not be available through the repository after removal",
repository.getConversation(childConversationId));
assertNull("root conversation must not be available after root removal",
repository.getConversation(rootConversationId));
}
@Test
public void testRepositoryDefaultTimeout() {
LocalTransientConversationRepository repository = new LocalTransientConversationRepository();
repository.setDefaultConversationTimeout(100);
MutableConversation conversation = repository.createNewConversation();
assertEquals("default timeout of repository has to be set on newly created conversations", 100,
conversation.getTimeout());
MutableConversation conversation2 = repository.createNewConversation();
conversation2.setTimeout(50);
assertEquals("setting a timeout on a conversation must not change the default one", 100,
conversation.getTimeout());
}
@Test
public void testRepositoryTimeoutInheritance() {
LocalTransientConversationRepository repository = new LocalTransientConversationRepository();
repository.setDefaultConversationTimeout(100);
MutableConversation conversation = repository.createNewConversation();
conversation.setTimeout(50);
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
assertEquals("timeout of a child conversation must be inherited from its parent", 50,
childConversation.getTimeout());
}
@Test
public void testRepositoryCustomTimeoutChildParentPropagation() {
LocalTransientConversationRepository repository = new LocalTransientConversationRepository();
repository.setDefaultConversationTimeout(100);
MutableConversation conversation = repository.createNewConversation();
conversation.setTimeout(50);
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
childConversation.setTimeout(70);
assertEquals("the custom timeout being set on a child conversation must be propagated to its parent", 70,
conversation.getTimeout());
}
@Test
public void testRepositoryCustomTimeoutParentChildPropagation() {
LocalTransientConversationRepository repository = new LocalTransientConversationRepository();
repository.setDefaultConversationTimeout(100);
MutableConversation conversation = repository.createNewConversation();
MutableConversation childConversation = repository.createNewChildConversation(conversation, false);
conversation.setTimeout(50);
assertEquals("the custom timeout being set on a parent conversation must be propagated to its children", 50,
childConversation.getTimeout());
}
protected ConversationRepository createRepository() {
return new LocalTransientConversationRepository();
}
}

View File

@@ -1,99 +0,0 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.conversation;
import org.junit.Test;
import org.springframework.conversation.manager.DefaultConversation;
import org.springframework.conversation.manager.MutableConversation;
import static org.junit.Assert.*;
/**
* @author Micha Kiener
*/
public class DefaultConversationTest {
@Test
public void testConversationAttribute() {
Conversation conversation = new DefaultConversation();
String test = new String("Test");
conversation.setAttribute("test", test);
assertSame("attribute must be accessible through conversation object", test, conversation.getAttribute("test"));
}
@Test
public void testConversationAttributeInheritance() {
MutableConversation conversation = new DefaultConversation();
String test = new String("Test");
conversation.setAttribute("test", test);
MutableConversation childConversation = new DefaultConversation();
conversation.addChildConversation(childConversation, false);
assertSame("attribute must be accessible through child conversation object", test,
childConversation.getAttribute("test"));
}
@Test
public void testConversationAttributeIsolation() {
MutableConversation conversation = new DefaultConversation();
String test = new String("Test");
conversation.setAttribute("test", test);
MutableConversation childConversation = new DefaultConversation();
conversation.addChildConversation(childConversation, true);
assertNull("attribute must not be accessible from within an isolated conversation",
childConversation.getAttribute("test"));
}
@Test
public void testNewConversationAttributeIsolation() {
MutableConversation conversation = new DefaultConversation();
String test = new String("Test");
conversation.setAttribute("test", test);
MutableConversation childConversation = new DefaultConversation();
conversation.addChildConversation(childConversation, true);
String test2 = new String("Test2");
childConversation.setAttribute("test2", test2);
assertNull("newly added attribute on isolated conversation must not be accessible within its parent",
conversation.getAttribute("test2"));
}
@Test
public void testConversationAttributeRemoval() {
Conversation conversation = new DefaultConversation();
String test = new String("Test");
conversation.setAttribute("test", test);
String test2 = (String)conversation.removeAttribute("test");
assertNotNull("removed attribute must be returned", test2);
assertSame("removed attribute must be the same as being added", test, test2);
assertNull("removed attribute must not be accessible after removal", conversation.getAttribute("test"));
}
}