diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java index 9615f76c..fa1e26c4 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilder.java @@ -291,7 +291,7 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde } private void initLocalFlowContext(Element flowElement) { - List importElements = DomUtils.getChildElementsByTagName(flowElement, "import"); + List importElements = DomUtils.getChildElementsByTagName(flowElement, "bean-import"); Resource[] resources = new Resource[importElements.size()]; for (int i = 0; i < importElements.size(); i++) { Element importElement = (Element) importElements.get(i); @@ -391,7 +391,7 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde if (element.hasAttribute("value")) { value = element.getAttribute("value"); } else { - value = element.getAttribute(name); + value = name; } Expression source = parser.parseExpression(name, new ParserContextImpl().eval(MutableAttributeMap.class)); Expression target = parser.parseExpression(value, new ParserContextImpl().eval(RequestContext.class)); @@ -417,10 +417,10 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde if (element.hasAttribute("value")) { value = element.getAttribute("value"); } else { - value = element.getAttribute(name); + value = name; } - Expression source = parser.parseExpression(name, new ParserContextImpl().eval(RequestContext.class)); - Expression target = parser.parseExpression(value, new ParserContextImpl().eval(MutableAttributeMap.class)); + Expression source = parser.parseExpression(value, new ParserContextImpl().eval(RequestContext.class)); + Expression target = parser.parseExpression(name, new ParserContextImpl().eval(MutableAttributeMap.class)); return new Mapping(source, target, parseMappingConversionExecutor(element), parseMappingRequired(element)); } @@ -830,7 +830,7 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde if (element.hasAttribute("value")) { value = element.getAttribute("value"); } else { - value = element.getAttribute(name); + value = name; } Expression source = parser.parseExpression(value, new ParserContextImpl().eval(RequestContext.class)); Expression target = parser.parseExpression(name, new ParserContextImpl().eval(MutableAttributeMap.class)); @@ -856,7 +856,7 @@ public class XmlFlowBuilder extends AbstractFlowBuilder implements ResourceHolde if (element.hasAttribute("value")) { value = element.getAttribute("value"); } else { - value = element.getAttribute(name); + value = name; } Expression source = parser.parseExpression(name, new ParserContextImpl().eval(MutableAttributeMap.class)); Expression target = parser.parseExpression(value, new ParserContextImpl().eval(RequestContext.class)); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilderTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilderTests.java index bda5ac8a..84497653 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilderTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/XmlFlowBuilderTests.java @@ -3,16 +3,24 @@ package org.springframework.webflow.engine.builder.xml; import junit.framework.TestCase; import org.springframework.beans.factory.support.StaticListableBeanFactory; +import org.springframework.binding.mapping.RequiredMappingException; import org.springframework.core.io.ClassPathResource; import org.springframework.webflow.action.ExternalRedirectAction; import org.springframework.webflow.action.FlowDefinitionRedirectAction; +import org.springframework.webflow.core.collection.LocalAttributeMap; +import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.Flow; import org.springframework.webflow.engine.ViewState; import org.springframework.webflow.engine.builder.FlowAssembler; import org.springframework.webflow.engine.builder.FlowBuilderException; import org.springframework.webflow.engine.builder.support.ActionExecutingViewFactory; +import org.springframework.webflow.engine.impl.FlowExecutionImplFactory; +import org.springframework.webflow.execution.Event; +import org.springframework.webflow.execution.FlowExecution; +import org.springframework.webflow.execution.FlowExecutionException; import org.springframework.webflow.execution.ViewFactory; import org.springframework.webflow.security.SecurityRule; +import org.springframework.webflow.test.MockExternalContext; import org.springframework.webflow.test.MockFlowBuilderContext; public class XmlFlowBuilderTests extends TestCase { @@ -31,7 +39,6 @@ public class XmlFlowBuilderTests extends TestCase { assembler.assembleFlow(); fail("Should have failed"); } catch (FlowBuilderException e) { - } } @@ -80,6 +87,64 @@ public class XmlFlowBuilderTests extends TestCase { assertTrue(((Boolean) flow.getAttributes().get("persistenceContext")).booleanValue()); } + public void testFlowInputOutputMapping() { + ClassPathResource resource = new ClassPathResource("flow-inputoutput.xml", getClass()); + builder = new XmlFlowBuilder(resource); + FlowAssembler assembler = new FlowAssembler(builder, new MockFlowBuilderContext("flow")); + Flow flow = assembler.assembleFlow(); + FlowExecutionImplFactory factory = new FlowExecutionImplFactory(); + FlowExecution execution = factory.createFlowExecution(flow); + MockExternalContext context = new MockExternalContext(); + MutableAttributeMap input = new LocalAttributeMap(); + input.put("foo", "bar"); + input.put("number", "3"); + input.put("required", "9"); + execution.start(input, context); + Event outcome = execution.getOutcome(); + assertEquals("end", outcome.getId()); + assertEquals("bar", outcome.getAttributes().get("foo")); + assertEquals("bar", outcome.getAttributes().get("differentName")); + assertEquals(new Integer(3), outcome.getAttributes().get("number")); + assertEquals(new Integer(3), outcome.getAttributes().get("required")); + assertEquals("a literal", outcome.getAttributes().get("literal")); + assertNull(outcome.getAttributes().get("notReached")); + } + + public void testFlowRequiredInputMapping() { + ClassPathResource resource = new ClassPathResource("flow-inputoutput.xml", getClass()); + builder = new XmlFlowBuilder(resource); + FlowAssembler assembler = new FlowAssembler(builder, new MockFlowBuilderContext("flow")); + Flow flow = assembler.assembleFlow(); + FlowExecutionImplFactory factory = new FlowExecutionImplFactory(); + FlowExecution execution = factory.createFlowExecution(flow); + MockExternalContext context = new MockExternalContext(); + MutableAttributeMap input = new LocalAttributeMap(); + try { + execution.start(input, context); + fail("Should have failed"); + } catch (FlowExecutionException e) { + RequiredMappingException me = (RequiredMappingException) e.getRootCause(); + } + } + + public void testFlowRequiredOutputMapping() { + ClassPathResource resource = new ClassPathResource("flow-inputoutput.xml", getClass()); + builder = new XmlFlowBuilder(resource); + FlowAssembler assembler = new FlowAssembler(builder, new MockFlowBuilderContext("flow")); + Flow flow = assembler.assembleFlow(); + FlowExecutionImplFactory factory = new FlowExecutionImplFactory(); + FlowExecution execution = factory.createFlowExecution(flow); + MockExternalContext context = new MockExternalContext(); + MutableAttributeMap input = new LocalAttributeMap(); + input.put("required", "yo"); + try { + execution.start(input, context); + fail("Should have failed"); + } catch (FlowExecutionException e) { + RequiredMappingException me = (RequiredMappingException) e.getRootCause(); + } + } + public void testFlowSecured() { ClassPathResource resource = new ClassPathResource("flow-secured.xml", getClass()); builder = new XmlFlowBuilder(resource); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/flow-inputoutput.xml b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/flow-inputoutput.xml new file mode 100644 index 00000000..312c6c9d --- /dev/null +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/xml/flow-inputoutput.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file