polish
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<flow xmlns="http://www.springframework.org/schema/webflow"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
|
||||
|
||||
<input name="${foo}" value="${flowScope.foo}"/>
|
||||
<input name="${foo}" value="${flowScope.bar}"/>
|
||||
<input name="${number}" value="${flowScope.baz}" type="integer"/>
|
||||
<input name="${required}" value="${flowScope.boop}" required="true"/>
|
||||
|
||||
<end-state id="end">
|
||||
<output name="${foo}" value="${flowScope.foo}" />
|
||||
</end-state>
|
||||
|
||||
<end-state id="notReached">
|
||||
<output name="${notReached}" value="${flowScope.foo}"/>
|
||||
</end-state>
|
||||
|
||||
<output name="${differentName}" value="${flowScope.bar}"/>
|
||||
<output name="${number}" value="${flowScope.baz}" type="integer"/>
|
||||
<output name="${required}" value="${flowScope.baz}" type="integer" required="true"/>
|
||||
<output name="${literal}" value="a literal"/>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user