Spring Web Stream. How can I set up unit test with values ​​already in talk time?

I am working on a project using Spring Web Flow 2.0.

I am trying to unit test a thread that starts with a decision state. The status of the solution checks the value of the object located on the conversationScope . I cannot figure out how to insert a value in conversationScope for unit test.

I tried:

 getConversationScope().put("someName", value); MockExternalContext context = new MockExternalContext(); startFlow(context); 

However, it seems that when I call startFlow(context) , the value is cleared.

I also tried:

 MockExternalContext context = new MockExternalContext(); setCurrentState("someDecisionState"); resumeFlow(context) 

But the test fails with an error informing me that I cannot resume the action from the decision state, only from the view state.

Does anyone know how I can embed mock values ​​in conversationScope so that I can check these cases?

+4
source share
1 answer

This is not obvious, but I came up with this:

 public void testFoo() { FlowExecution flowExecution = getFlowExecutionFactory().createFlowExecution(getFlowDefinition()); updateFlowExecution(flowExecution); flowExecution.getConversationScope().put("fooBar", "goo"); flowExecution.start(null, new MockExternalContext()); assertCurrentStateEquals("fooView"); } 

I needed to delve into the base AbstractXmlFlowExecutionTests.startFlow() to see how it created the FlowExecution instance, and copy and paste part of this into the unit test.

Here's the test channel stream.

 <?xml version="1.0" encoding="UTF-8"?> <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"> <action-state id="decideFoo"> <evaluate expression="conversationScope.fooBar" /> <transition on="goo" to="fooView" /> <transition on="gar" to="barView" /> </action-state> <view-state id="fooView" /> <view-state id="barView" /> </flow> 
+5
source

All Articles