Spring Web Flow - How can I set up unit test with values already in conversationScope?

扶醉桌前 提交于 2019-12-03 09:12:46

It's not obvious, but I came up with this:

public void testFoo() {
    FlowExecution flowExecution = getFlowExecutionFactory().createFlowExecution(getFlowDefinition());
    updateFlowExecution(flowExecution);
    flowExecution.getConversationScope().put("fooBar", "goo");
    flowExecution.start(null, new MockExternalContext());        
    assertCurrentStateEquals("fooView");
}

I had to dig into the underlying AbstractXmlFlowExecutionTests.startFlow() to see how it was instantiating the FlowExecution, and copy and paste some of that into the unit test.

Here's the test web flow.

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <action-state id="decideFoo">
        <evaluate expression="conversationScope.fooBar" />
        <transition on="goo" to="fooView" />
        <transition on="gar" to="barView" />
    </action-state>

    <view-state id="fooView" />

    <view-state id="barView" />

</flow>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!