简体   繁体   中英

How to go about testing decision-state in Spring WebFlow

I'm trying to find the best way to unit test decision-states within a Spring WebFlow context.

<var name="registration" class="*some class path*.Registration"/>

<decision-state id="checkSignedIn">
    <if test="*someClass*.isSignedOn(registration)"
        then="checkHas*Said*Service"
        else="registrationChoice"/>
</decision-state>

<decision-state id="checkHasTCloudService">
    <if test="*someClass*Dao.isUserRegisteredFor*saidSvc*(registration)"
        then="*svc*Activated"
        else="registrationChoice"/>
</decision-state>

<view-state id="registrationChoice" model="registration" view="view.xhtml" >

    <on-entry>...

NB the someClass and the someClassDao are not within the FlowScope or ConversationScope.

I want to test, via Mockito, that the decision-state expressions are being called and then verify the correct state outcomes.

Normally, one can simply

  1. setCurrentState(someViewState: where you want slot test in within a transitional flow)
  2. define input
  3. mock an ExternalContext
  4. setEvent within that context
  5. resumeFlow(with given context)
  6. verify mocked method calls & finally
  7. assertCurrentState(someViewState: where you would expect to be at, after given input has influenced the decision-state to fork to, within the flow)

It seems decision-states don't operate as a view-state (fair enough: they aren't a given state of view within a flow) so how are we to mock/test?

Thanks in aniticiptation of responses.

Well, I've been put in the right direction by a colleague (the venerable Murray MacPherson) who reminded me that the process is:
1. mock your dao calls
2. begin your flow & (now this is the crux)
3. based on the decision outcomes set by your mocked calls, assert your expected outcome state (which will be some view),
- whether an end state (in which case you would also be expecting an end to your flow) or
- (interim) current state. If it has arrived at exp[ected point, then you know the decisions have been exercised.


NB if your expected outcome is a 'currentState', then you can verify the mocked (dao) call/s has/have been made otherwise (as the flow would no longer be active) you cannot make such verifications: the simple fact you've arrived at your expected end state is verification in itself.

In this exact example, you have an alternative to starting at a particular view state via setCurrentState() - you can use startFlow - which will... start the flow. You can then test which view state you end up at, due to the results of your decision states.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM