Results 1 to 6 of 6

Thread: Testing output mappings using FlowExecutionListenerAdapter

  1. #1
    Join Date
    Jun 2006
    Location
    Oxford UK
    Posts
    15

    Default Testing output mappings using FlowExecutionListenerAdapter

    Hi there,

    I am currently trying to test on of my sub flows and want to make sure that the values I return as output mappers are indeed what I think they should be.

    Searching the forums brought up this post (quoted below)

    Quote Originally Posted by Keith Donald View Post
    What you want to test here are that any flow output attributes are returned correctly by your end state. You can do this by attaching a custom FlowExecutionListener for your end-state test scenario and verifying the sessionOutput in the sessionEnded callback has the right stuff. You can also get a hold of the FlowSession directly in that callback as well.

    Besides that I'd test what is put in the returned ViewSelection is accurate. I don't think it is correct to test the internals of a flow after the flow has ended--as the internals no longer exist!
    Keith
    From what I can see you are supposed to set up a FlowExecutionListenerAdapter on starting the flow, then check the values of the sessionOutput in the sessionEnded callback.

    The problem I am having is that I have no idea how to do this code wise, and was wondering whether anyone who has done this could post a simple code example of how they went about this, both the initial setting up then the testing of output mappings at the end.

    I have searched the samples, and also scoured existing posts on the forums to no avail, but no examples of this seem to exist.

    Many thanks!
    Al

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    What you want to do is override the createFlowExecutionFactory() method defined by the AbstractFlowExecutionTests and setup a FlowExecutionFactory that registers some listeners when the FlowExecution is created. Like so:

    Code:
    public class SearchFlowExecutionTests extends AbstractXmlFlowExecutionTests {
    	
    	protected FlowExecutionFactory createFlowExecutionFactory() {
    		FlowExecutionImplFactory factory = new FlowExecutionImplFactory();
    		FlowExecutionListener testListener = new FlowExecutionListenerAdapter() {
    			public void sessionEnded(RequestContext context, FlowSession session, AttributeMap output) {
    				// verify output here
    				System.out.println(output);
    			}
    		};
    		factory.setExecutionListenerLoader(new StaticFlowExecutionListenerLoader(testListener));
    		return factory;
    	}
    	...
    Erwin

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    It should be easier than that---take a look at the set* methods on AbstractXmlFlowExecutionTest hierarchy and I believe there is a setFlowExectionListener...

    Keith
    Keith Donald
    Core Spring Development Team

  4. #4
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    It doesn't exist in SWF 1.0.1 but it would probably make sense to add something like that.

    Erwin

  5. #5
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Mmm,

    There is a setFlowExecutionListener on AbstractExternalizedFlowExecutionTests...
    It would probably have made more sense to have that method on the AbstractFlowExecutionTests.

    Erwin
    Last edited by klr8; Jan 15th, 2007 at 10:09 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    Oxford UK
    Posts
    15

    Thumbs up

    Thanks to both Erwin and Keith for their responses - Erwin's code sample worked perfectly.

    Al

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •