Testing Spring Webflow 2 with inheritance

This blog entry shows how to test a flow with inheritance in Spring Webflow 2. The flow to be tested consists of a simple navigation which starts with a view state and ends getting to another view state that will depend on the result of the execution of a controller. This flow extends another flow which basically contains a redirection to a common page in case of error.

Introduction

The test flow (main.xml) is as follows:

 

And the parent flow (parent.xml):


 

When executing tests, Spring provides us with a quite useful class: AbstractXmlFlowExecutionTests, in the org.springframework.webflow.test.execution package. This class has a variety of methods that will help us test the flow. The most interesting:

 

Here, we specify where the flow which we want to test is located.


 

If the flow uses inheritance, we define the parent flow here.

Lets us customize the builder context. I use it for registering the beans that will use in the test as this is the way it’s indicated at the class javadoc.

Allows registering the beans that will be used by the flow to be tested. For example:

 

Testing the flow

I’ve divided it in two classes in order to separate configuration from tests cases:

 

You could simply delete configureFlowBuilderContext method and use registerMockFlowBeans method instead if you don’t want/need to start your own test context.

Related posts

Share it:

Leave a Reply

Your email address will not be published. Required fields are marked *