问题
I have this very annoying problem I cannot figure out.
This is the main structure of my webflow project:
- WEB-INF/flows/basic/basic-flow.xml
- WEB-INF/flows/error/error-flow.xml
The error flow contains common exception handling and is abstract. Basic flow has the error flow as parent.
When I try to write a JUnit test I get into a problem where it is not able to load the error flow. I have tested basic by itself (just removing the parent attribute) and it works just fine. Any advice to what I could be doing wrong?
Here are the important parts of the test code:
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("src/main/webapp/WEB-INF/flows/basic/basic-flow.xml");
}
@Override
protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
FlowDefinitionResource flowDefinitionResource = resourceFactory
.createFileResource("src/main/webapp/WEB-INF/flows/error/error-flow.xml");
return new FlowDefinitionResource[] { flowDefinitionResource };
}
public void testStartBasicFlow() {
MockExternalContext context = new MockExternalContext();
startFlow(context);
}
The exception I get is this:
Caused by: org.springframework.webflow.engine.model.registry.NoSuchFlowModelException: No flow model 'error' found
回答1:
For Your error
flow You should probably explicitelly pass a flowId
:
FlowDefinitionResource flowDefinitionResource = resourceFactory.createResource(
"src/main/webapp/WEB-INF/flows/error/error-flow.xml", null, "error");
When using FlowDefinitionResource.createFileResource(..)
the flowId
is the result of the FlowDefinitionResource.getFlowId(..)
, wich may not evaluate to error
in Your case.
来源:https://stackoverflow.com/questions/6422748/webflow-testing-unable-to-find-flow-model