From d985cfb9c07c01aeb90c8db8304825828336f79e Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Mon, 15 Jan 2007 21:41:46 +0000 Subject: [PATCH] A fix for SWF-239. Look to the proper attribute name (type instead of repository-type) and compare based on string value rather than resolving against the enumeration. --- .../config/ExecutorBeanDefinitionParser.java | 5 +- .../WebFlowConfigNamespaceHandlerTests.java | 66 ++++++++++++++----- .../config/webflow-config-namespace.xml | 30 ++++++++- 3 files changed, 80 insertions(+), 21 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/ExecutorBeanDefinitionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/config/ExecutorBeanDefinitionParser.java index 4b0fd1ca..5d7651e9 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/ExecutorBeanDefinitionParser.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/ExecutorBeanDefinitionParser.java @@ -20,7 +20,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.core.enums.StaticLabeledEnumResolver; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; @@ -109,11 +108,9 @@ class ExecutorBeanDefinitionParser extends AbstractBeanDefinitionParser { * @param definitionBuilder the builder */ private void configureContinuations(Element repositoryElement, BeanDefinitionBuilder definitionBuilder) { - RepositoryType repositoryType = (RepositoryType)StaticLabeledEnumResolver.instance().getLabeledEnumByLabel( - RepositoryType.class, getRepositoryType(repositoryElement)); String maxContinuations = getMaxContinuations(repositoryElement); if (StringUtils.hasText(maxContinuations)) { - if (repositoryType != RepositoryType.CONTINUATION) { + if (!getType(repositoryElement).equals("CONTINUATION")) { throw new IllegalArgumentException( "The 'max-continuations' attribute of the 'repository' element must not " + "have a value if the 'type' attribute is not 'continuation'"); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandlerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandlerTests.java index 81e089d1..f90a7691 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandlerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/WebFlowConfigNamespaceHandlerTests.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.ClassPathResource; +import org.springframework.webflow.conversation.ConversationManager; import org.springframework.webflow.core.collection.AttributeMap; import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; import org.springframework.webflow.engine.Flow; @@ -30,6 +31,7 @@ import org.springframework.webflow.execution.factory.ConditionalFlowExecutionLis import org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader; import org.springframework.webflow.execution.repository.continuation.ClientContinuationFlowExecutionRepository; import org.springframework.webflow.execution.repository.continuation.ContinuationFlowExecutionRepository; +import org.springframework.webflow.execution.repository.support.AbstractConversationFlowExecutionRepository; import org.springframework.webflow.execution.repository.support.SimpleFlowExecutionRepository; import org.springframework.webflow.executor.FlowExecutorImpl; @@ -73,7 +75,7 @@ public class WebFlowConfigNamespaceHandlerTests extends TestCase { assertEquals(1, attribs.size()); // defaults have been applied assertEquals(new Boolean(true), attribs.get(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE)); } - + public void testSimpleExecutor() { FlowExecutorImpl flowExecutor = (FlowExecutorImpl)this.beanFactory.getBean("simpleExecutor"); assertSame(this.beanFactory.getBean("withPathWithWildcards"), flowExecutor.getDefinitionLocator()); @@ -87,7 +89,7 @@ public class WebFlowConfigNamespaceHandlerTests extends TestCase { assertSame(StaticFlowExecutionListenerLoader.EMPTY_INSTANCE, ((FlowExecutionImplFactory)flowExecutor.getExecutionFactory()).getExecutionListenerLoader()); } - + public void testContinuationExecutor() { FlowExecutorImpl flowExecutor = (FlowExecutorImpl)this.beanFactory.getBean("continuationExecutor"); assertSame(this.beanFactory.getBean("withPathWithWildcards"), flowExecutor.getDefinitionLocator()); @@ -99,8 +101,8 @@ public class WebFlowConfigNamespaceHandlerTests extends TestCase { ((FlowExecutionImplFactory)flowExecutor.getExecutionFactory()).getExecutionListenerLoader(); assertEquals(1, ll.getListeners(new Flow("test")).length); assertSame(this.beanFactory.getBean("listener1"), ll.getListeners(new Flow("test"))[0]); - } - + } + public void testClientExecutor() { FlowExecutorImpl flowExecutor = (FlowExecutorImpl)this.beanFactory.getBean("clientExecutor"); assertSame(this.beanFactory.getBean("withPathWithWildcards"), flowExecutor.getDefinitionLocator()); @@ -117,8 +119,8 @@ public class WebFlowConfigNamespaceHandlerTests extends TestCase { assertSame(this.beanFactory.getBean("listener2"), ll.getListeners(new Flow("flow2"))[0]); assertEquals(1, ll.getListeners(new Flow("flow3")).length); assertSame(this.beanFactory.getBean("listener2"), ll.getListeners(new Flow("flow3"))[0]); - } - + } + public void testSingleKeyExecutor() { FlowExecutorImpl flowExecutor = (FlowExecutorImpl)this.beanFactory.getBean("singleKeyExecutor"); assertSame(this.beanFactory.getBean("withPathWithWildcards"), flowExecutor.getDefinitionLocator()); @@ -130,32 +132,66 @@ public class WebFlowConfigNamespaceHandlerTests extends TestCase { assertSame(StaticFlowExecutionListenerLoader.EMPTY_INSTANCE, ((FlowExecutionImplFactory)flowExecutor.getExecutionFactory()).getExecutionListenerLoader()); } - + public void testDuplicateRepositoryType() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - try { + try { reader.loadBeanDefinitions(new ClassPathResource("org/springframework/webflow/config/namespace-error-1.xml")); fail("Should have thrown an BeanDefinitionStoreException exception"); - } catch (BeanDefinitionStoreException e) {} + } catch (BeanDefinitionStoreException e) { + assertTrue("The nested exception should be an IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); + } } - + public void testConversationManagerRef() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - try { + try { reader.loadBeanDefinitions(new ClassPathResource("org/springframework/webflow/config/namespace-error-2.xml")); fail("Should have thrown a BeanDefinitionStoreException exception"); - } catch (BeanDefinitionStoreException e) {} + } catch (BeanDefinitionStoreException e) { + assertTrue("The nested exception should be an IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); + } } - + public void testMaxContinuation() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - try { + try { reader.loadBeanDefinitions(new ClassPathResource("org/springframework/webflow/config/namespace-error-3.xml")); fail("Should have thrown a BeanDefinitionStoreException exception"); - } catch (BeanDefinitionStoreException e) {} + } catch (BeanDefinitionStoreException e) { + assertTrue("The nested exception should be an IllegalArgumentException", e.getCause() instanceof IllegalArgumentException); + } + } + + public void testContinuationExtended() { + FlowExecutorImpl flowExecutor = (FlowExecutorImpl) this.beanFactory.getBean("continuationExtended"); + assertTrue("Repository type should be ContinuationFlowExecutionRepository", flowExecutor.getExecutionRepository() instanceof ContinuationFlowExecutionRepository); + } + + public void testClientExtended() { + FlowExecutorImpl flowExecutor = (FlowExecutorImpl) this.beanFactory.getBean("clientExtended"); + assertTrue("Repository type should be ClientContinuationFlowExecutionRepository", flowExecutor.getExecutionRepository() instanceof ClientContinuationFlowExecutionRepository); + } + + public void testSimpleExtended() { + FlowExecutorImpl flowExecutor = (FlowExecutorImpl) this.beanFactory.getBean("simpleExtended"); + assertTrue("Repository type should be SimpleFlowExecutionRepository", flowExecutor.getExecutionRepository() instanceof SimpleFlowExecutionRepository); + } + + public void testSinglekeyExtended() { + FlowExecutorImpl flowExecutor = (FlowExecutorImpl) this.beanFactory.getBean("singlekeyExtended"); + assertTrue("Repository type should be SimpleFlowExecutionRepository", flowExecutor.getExecutionRepository() instanceof SimpleFlowExecutionRepository); + } + + public void testConversationManagerExtended() { + FlowExecutorImpl flowExecutor = (FlowExecutorImpl) this.beanFactory.getBean("conversationManagerExtended"); + assertTrue("Repository type should be SimpleFlowExecutionRepository", flowExecutor.getExecutionRepository() instanceof SimpleFlowExecutionRepository); + AbstractConversationFlowExecutionRepository repository = (AbstractConversationFlowExecutionRepository) flowExecutor.getExecutionRepository(); + ConversationManager conversationManager = (ConversationManager) this.beanFactory.getBean("conversationManager"); + assertSame("The conversation manager in the repository should be the one explicitly wired", conversationManager, repository.getConversationManager()); } } \ No newline at end of file diff --git a/spring-webflow/src/test/java/org/springframework/webflow/config/webflow-config-namespace.xml b/spring-webflow/src/test/java/org/springframework/webflow/config/webflow-config-namespace.xml index 05b8024d..26565671 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/config/webflow-config-namespace.xml +++ b/spring-webflow/src/test/java/org/springframework/webflow/config/webflow-config-namespace.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/webflow-config - http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd"> + http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd"> @@ -46,7 +46,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + +