java - Testing Spring Web Flow exception event -


i have following setup in flow xml (my-flow.xml):

<view-state id="exceptionviewstate" view="general_error" model="oneobjet"/> ... <view-state id="previousviewstate" view="previous_view" model="oneobjet">     <transition on="actionconfirmed" to="endstate" /> </view-state> ... <global-transitions>     <transition on-exception="com.xxx.exception.generalexception" to="exceptionviewstate"/> </global-transitions> 

and trying test flow xml extending abstractxmlflowexecutiontests

public void testmyflow_exception() {     setcurrentstate("previousviewstate");      mockexternalcontext context = new mockexternalcontext();     context.seteventid("com.xxx.exception.generalexception");     resumeflow(context);      assertcurrentstateequals("exceptionviewstate");     assertresponsewrittenequals("general_error", context); } 

when run test following error:

org.springframework.webflow.engine.nomatchingtransitionexception: no transition found on occurence of event 'com.xxx.exception.generalexception' in state 'previousviewstate' of flow 'my-flow' -- valid transitional criteria array<transitioncriteria>[actionconfirmed] -- programmer error, check set of transitioncriteria state 

at first glance seems issue caused using mockexternalcontext#seteventid() method (which think doesn't apply exceptions) try , emulate exception being thrown. couldn't think of way this. ideas on how can achieved?

i found way around stubbing service called in web flow throw exception generalexception. allowed me test exception flow:

public class exceptionflowtest extends abstractxmlflowexecutiontests {      private myservice myservice;      protected void setup() {         myservice = new myservice() {              public objectdto getobject() throws generalexception {                 throw new generalexception();             }          };     }      @override     protected flowdefinitionresource getresource(flowdefinitionresourcefactory resourcefactory) {         return resourcefactory.createfileresource("webcontent/web-inf/flows/my-flow.xml");     }      @override     protected void configureflowbuildercontext(mockflowbuildercontext buildercontext) {         buildercontext.registerbean("myservice", myservice);     }      public void testmyflow_exception() {          mutableattributemap input = new localattributemap();         mockexternalcontext context = new mockexternalcontext();          startflow(input, context);          assertcurrentstateequals("exceptionviewstate");     }  } 

i didn't have change flow xml :

<flow xmlns="http://www.springframework.org/schema/webflow"       xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"       xsi:schemalocation="http://www.springframework.org/schema/webflow                           http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"       start-state="getobject">      <persistence-context />        <var name="object" class="com.xxx.model.objectdto" />       <action-state id="getobject">         <evaluate expression="myservice.getobject()" result="object" />         <transition to="nextview" />      </action-state> ...     <global-transitions>         <transition on-exception="com.xxx.exception.generalexception" to="exceptionviewstate"/>     </global-transitions>  </flow>  

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -