1

This is similar to Spring Web Flow - How can I set up unit test with values already in conversationScope?

I've used the solution listed in that question to solve a conversationScope issue, but have been hitting a wall trying to do the same for FlowScope. For some reason, FlowExecution does not have a getFlowScope() method.

Any helps or general pointing in the right direction will be very much appreciated. Thanks!

Update:

To give more context, this is the line in the webflow I'm trying to test:

<evaluate expression="serviceFactory.getInstance(flowScope.config.country).startTransaction(flowScope.SomeList.get(0), 0)" />

and the relavant test statement is:

EasyMock.expect(serviceObjectMock.startTransaction(someObjectMock, 0)).andReturn(true);

and it fails silently. When I walk through the code in the debugger, I see that there was an IndexOutOfBoundsException on this call, which led to my assumption that I have to have the list somehow in flowScope.

Community
  • 1
  • 1
shaunlim
  • 4,384
  • 6
  • 33
  • 38

2 Answers2

0

in FlowExecution, you can use getActiveSession().getScope()
that will give you the FlowScope where you can then put your attributes (after the flow started)

What you are trying to do doesn't really make sense because Flow scoped attributes exist for the life of the active flow session. You cannot set them before the flow starts.

rptmat57
  • 3,643
  • 1
  • 27
  • 38
  • Hi, thanks for your reply. I want to populate a flowScope attribute before starting the flow since the attribute will be used before the first view-state so I can't pause the flow using setCurrentState, set the attribute, then resume the flow. Do you have any ides how I can do that? Thanks! – shaunlim Sep 27 '12 at 15:30
  • This is the error I get: java.lang.IllegalStateException: No active FlowSession to access; this FlowExecution has not been started at org.springframework.webflow.engine.impl.FlowExecutionImpl.getActiveSession(FlowExecutionImpl.java:188) – shaunlim Sep 27 '12 at 15:54
  • oh I see. you can only get the active session once the flow has started already. my bad. – rptmat57 Sep 27 '12 at 17:32
  • you could put attributes in the sessionMap of the MockExternalContext – rptmat57 Sep 27 '12 at 18:06
  • sorry, can you clarify a little? i did this context.getSessionMap().put("test", testObject); startFlow(input, context); and it didn't work. do i have to explicitly put it in the flowScope somehow? thanks for your help btw! – shaunlim Sep 27 '12 at 18:24
  • you can try to put your attribute as an input but I am pretty sure that's not what you want to do. – rptmat57 Sep 27 '12 at 18:52
  • last thing I am thinking about would be to create a MockFlowSession with "new MockFlowSession(Flow flow, AttributeMap input)" where you put your attribute then create a "new MockFlowExecutionContext(FlowSession flowSession)" and then start it – rptmat57 Sep 27 '12 at 18:56
0

For anybody who's interested, I learnt that I did not have to explicitly set the attribute in the flowScope, as EasyMock handles that while it goes through the list of "expects".

My problem was that "flowScope.SomeList.get(0)" refers to an attribute that was set in the previous line, and I used "new ArrayList()" as a return value in the "expect" statement for that line.

And also, the "failing silently" part was due to me not enabling DEBUG level info in the test profile for Spring.

This in the test log4j.xml file solved the problem:

    <logger name="org.springframework">
    <level value="DEBUG" />
</logger>
shaunlim
  • 4,384
  • 6
  • 33
  • 38
  • I am wirting junit for spring webflow and i kind of stuck for sometime can you please look in this post and provide any suggestion http://stackoverflow.com/questions/39010531/not-able-to-get-the-flow-scope-variable-from-one-state-transition-to-another-sta thanks – henrycharles Aug 18 '16 at 06:22