Announcement Announcement Module
Collapse
No announcement yet.
Test web flow - AJAX with exception handler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Test web flow - AJAX with exception handler

    Hello all

    I have written quite a few unit tests extending AbstractXmlFlowExecutionTests as described in the documents. After reading source code, searching the forums, etc, I have what I think is pretty good coverage for the app. This includes coverage of what happens in the middle of our custom exception handler (implements FlowExecutionExceptionHandler) during a normal transition.

    The one part that remains untested is what happens during an AJAX transition, like this, when an exception happens in "instance.method()"

    Code:
    		
    <transition	on="aTransition" validate="false">
    	<evaluate expression="instance.method()" />
    	<render fragments="sample-exclusion" />
    </transition>
    So there is no "to" attribute but rather we expect a fragment to be rendered.

    I have special handling in the custom exception handler for an ajax request so that the fragment is still rendered, but also ensures that a message (keyed by the FQN of the exception ) is created. The solution to this problem was found on this forum and works well.

    Here is part of the solution .... when running the app, you can see that the exception handler can find out the fragment, and go on to render it. (The rest of the solution mainly involves looking up a message)

    Code:
    String fragment = (String) requestControlContext.getCurrentEvent().getAttributes().get("fragments");
    Expression[] fragments = {new LiteralExpression(fragment)};
    Action action = new RenderAction(fragments);
    action.execute(context);
    Object currentState = context.getCurrentState();
    ViewState viewState = (ViewState) currentState;
    viewState.getViewFactory().getView(context).render();
    Unfortunately, when running the flow through my unit test, this line returns a null string.

    Code:
    String fragment = (String) requestControlContext.getCurrentEvent().getAttributes().get("fragments");
    This feels like a problem with the way that Spring Web Flow builds the flow for test. Why hasn't is got the fragments set up for this transition ?

    Does anyone out there have a good solution ? I began to write a test that just exercises the overridden "handle" method in the ExceptionHandler but I'd sooner test the flow properly.

    Thanks

    Chris
Working...
X