I found a way around this by stubbing a service called in the web flow to throw the exception GeneralException. This allowed me to test the exception flow:
public class ExceptionFlowTest extends AbstractXmlFlowExecutionTests {
private MyService myService;
protected void setUp() {
myService = new MyService() {
public ObjectDTO getObject() throws GeneralException {
throw new GeneralException();
}
};
}
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("WebContent/WEB-INF/flows/my-flow.xml");
}
@Override
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
builderContext.registerBean("myService", myService);
}
public void testMyFlow_Exception() {
MutableAttributeMap input = new LocalAttributeMap();
MockExternalContext context = new MockExternalContext();
startFlow(input, context);
assertCurrentStateEquals("exceptionViewState");
}
}
I didn't have to change my flow XML :
<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"
start-state="getObject">
<persistence-context />
<var name="object" class="com.xxx.model.ObjectDTO" />
<action-state id="getObject">
<evaluate expression="myService.getObject()" result="object" />
<transition to="nextView" />
</action-state>
...
<global-transitions>
<transition on-exception="com.xxx.exception.GeneralException" to="exceptionViewState"/>
</global-transitions>
</flow>