0
votes

I have a problem testing my Spring webflows with JUnit.

As suggested in the docs I wrote a Test Class which extends AbstractXmlFlowExecutionTests.

public class MyFlowTest extends AbstractXmlFlowExecutionTests {
    MockExternalContext context = new MockExternalContext();

    String workingDirectory = null;

    @Override
    protected FlowDefinitionResource        getResource(FlowDefinitionResourceFactory resourceFactory) {
        return resourceFactory.createFileResource("WebContent/flows/myflow-flow.xml");
    }

The webflow under Test inherits from an abstract parent webflow which defines some global transitions. So I try to override getModelResources to provide this parent webflow. But this is not working at all.

@Override
protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory) {
    FlowDefinitionResource[] flowDefResources = new FlowDefinitionResource[1];

    see below...

    return flowDefResources;
}

My specific problem is:

When I use resourceFactory.createFileResource for the parent flow the name is not correct so I get a exception wih the message Unable to find flow 'main/parentflow' to inherit from.

When I use resourceFactory.createResource(String path, null, "main/parentflow" the .xml defining the flow is never found. The Exception prints the Path and says FileNotFound but the path does exist for sure (copy and paste this path to an Editor - File - Open works.

What am I doing wrong here?

Many thanks in advance.

I am using spring-webflow-2.3.2 and jUnit 4

1

1 Answers

0
votes

So I found the problem by having a look at the source of AbstractXmlFlowExecutionTests: FlowDefinitionResourceFactory.createFileResource works differently than resourceFactory.createResource(String path, AttributeMap attributes, String flowID). The second one is using a class loader instead of a simple file loader. So the solution is to provide the XML-File within the classpath so it can be found. The class loader doesn't seem to be allowed to open just any file on the local machine.

I think I will add a step to my maven build to copy all flow definitions to the target/WEB_INF directory just for the testing purpose.

To me this seems to be ugly and I don't understand why createResource is using this approach.

Maybe someone can suggest a better solution?