1 16 package org.springframework.webflow.test; 17 18 import org.springframework.webflow.core.collection.MutableAttributeMap; 19 import org.springframework.webflow.engine.Flow; 20 import org.springframework.webflow.engine.RequestControlContext; 21 import org.springframework.webflow.engine.State; 22 import org.springframework.webflow.engine.Transition; 23 import org.springframework.webflow.engine.TransitionableState; 24 import org.springframework.webflow.execution.Event; 25 import org.springframework.webflow.execution.FlowSession; 26 import org.springframework.webflow.execution.FlowSessionStatus; 27 import org.springframework.webflow.execution.ViewSelection; 28 29 39 public class MockRequestControlContext extends MockRequestContext implements RequestControlContext { 40 41 45 public MockRequestControlContext(Flow rootFlow) { 46 super(rootFlow); 47 } 48 49 51 public void setCurrentState(State state) { 52 State previousState = (State)getCurrentState(); 53 getMockFlowExecutionContext().getMockActiveSession().setState(state); 54 if (previousState == null) { 55 getMockFlowExecutionContext().getMockActiveSession().setStatus(FlowSessionStatus.ACTIVE); 56 } 57 } 58 59 public ViewSelection start(Flow flow, MutableAttributeMap input) throws IllegalStateException { 60 getMockFlowExecutionContext().setActiveSession(new MockFlowSession(flow, input)); 61 getMockFlowExecutionContext().getMockActiveSession().setStatus(FlowSessionStatus.STARTING); 62 ViewSelection selectedView = flow.start(this, input); 63 return selectedView; 64 } 65 66 public ViewSelection signalEvent(Event event) { 67 setLastEvent(event); 68 ViewSelection selectedView = ((Flow)getActiveFlow()).onEvent(this); 69 return selectedView; 70 } 71 72 public FlowSession endActiveFlowSession(MutableAttributeMap output) throws IllegalStateException { 73 MockFlowSession endingSession = getMockFlowExecutionContext().getMockActiveSession(); 74 endingSession.getDefinitionInternal().end(this, output); 75 endingSession.setStatus(FlowSessionStatus.ENDED); 76 getMockFlowExecutionContext().setActiveSession(null); 77 return endingSession; 78 } 79 80 public ViewSelection execute(Transition transition) { 81 return transition.execute((TransitionableState)getCurrentState(), this); 82 } 83 } | Popular Tags |