[英]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. 我正在尝试找到在Spring WebFlow上下文中对测试决策状态进行单元测试的最佳方法。
<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. 注意someClass和someClassDao不在FlowScope或ConversationScope之内。
I want to test, via Mockito, that the decision-state expressions are being called and then verify the correct state outcomes. 我想通过Mockito测试是否正在调用决策状态表达式,然后验证正确的状态结果。
Normally, one can simply 通常情况下,
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 1.模拟你的电话
2. begin your flow & (now this is the crux) 2.开始你的流程&(现在这才是关键)
3. based on the decision outcomes set by your mocked calls, assert your expected outcome state (which will be some view), 3.根据您的模拟呼叫设置的决策结果,声明您的预期结果状态(将是某些视图),
- 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. 注意:如果您的预期结果是“ currentState”,则可以验证是否进行了模拟(dao)调用(因为流程将不再处于活动状态),因此您无法进行此类验证:已经达到您预期的最终状态本身就是验证。
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. 在这个确切的示例中,您可以通过setCurrentState()在特定视图状态下启动-您可以使用startFlow-这将启动流程。 You can then test which view state you end up at, due to the results of your decision states.
然后,由于决策状态的结果,您可以测试最终到达的视图状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.