/** * Creates a new mock flow execution context for the specified root flow definition. */ public MockFlowExecutionContext(Flow flow) { this(new MockFlowSession(flow)); }
public void endActiveFlowSession(String outcome, MutableAttributeMap<Object> output) throws IllegalStateException { MockFlowSession endingSession = getMockFlowExecutionContext().getMockActiveSession(); endingSession.getDefinitionInternal().end(this, outcome, output); getMockFlowExecutionContext().setActiveSession(endingSession.getParent()); if (!getMockFlowExecutionContext().hasEnded()) { handleEvent(new Event(endingSession.getState(), outcome, output)); } }
/** * Creates a new mock flow session that sets a flow with id "mockFlow" as the 'active flow' in state "mockState". */ public MockFlowSession() { setDefinition(new Flow("mockFlow")); State state = new TransitionableState(definition, "mockState") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { // nothing to do } }; setState(state); }
/** * Set the currently active state. */ public void setState(State state) { if (this.state != null && this.state.isViewState()) { destroyViewScope(); } this.state = state; if (this.state != null && this.state.isViewState()) { initViewScope(); } }
private MockFlowSession newFlowSession(boolean persistenceContext, FlowSession parent) { MockFlowSession flowSession = new MockFlowSession(); flowSession.setParent(parent); if (persistenceContext) { flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); } EndState endState = new EndState(flowSession.getDefinitionInternal(), "success"); endState.getAttributes().put("commit", true); flowSession.setState(endState); return flowSession; }
public void start(Flow flow, MutableAttributeMap<?> input) throws IllegalStateException { MockFlowSession session = new MockFlowSession(flow, input); if (getFlowExecutionContext().isActive()) { session.setParent(getFlowExecutionContext().getActiveSession()); } getMockFlowExecutionContext().setActiveSession(session); flow.start(this, input); }
public void setCurrentState(State state) { getMockFlowExecutionContext().getMockActiveSession().setState(state); }
public void testEnterEndStateTerminateFlowSession() { final Flow subflow = new Flow("mySubflow"); EndState state = new EndState(subflow, "end"); MockFlowSession session = new MockFlowSession(subflow); Flow parent = new Flow("parent"); SubflowState subflowState = new SubflowState(parent, "subflow", new AbstractGetValueExpression() { public Object getValue(Object context) throws EvaluationException { return subflow; } }); subflowState.getTransitionSet().add(new Transition(on("end"), to("end"))); new EndState(parent, "end"); MockFlowSession parentSession = new MockFlowSession(parent); parentSession.setState(subflowState); session.setParent(parentSession); MockRequestControlContext context = new MockRequestControlContext(new MockFlowExecutionContext(session)); state.enter(context); assertFalse("Active", context.getFlowExecutionContext().isActive()); }
/** * Creates a new mock flow session that sets a flow with id "mockFlow" as the 'active flow' in state "mockState". * This session marks itself active. */ public MockFlowSession() { setDefinition(new Flow("mockFlow")); State state = new ViewState(definition, "mockState"); setStatus(FlowSessionStatus.ACTIVE); setState(state); }
public void testExceptionThrownWithNothingBound() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); assertSessionNotBound(); hibernateListener.exceptionThrown(context, new FlowExecutionException("foo", "bar", "test")); assertSessionNotBound(); }
/** * Creates a new mock session in a created state for the specified flow definition. */ public MockFlowSession(Flow flow) { setDefinition(flow); }
public void testDispatchWithCurrentStateId() throws Exception { MockFlowSession session = context.getMockFlowExecutionContext().getMockActiveSession(); session.setState(new ViewState(session.getDefinitionInternal(), "increment", new StubViewFactory())); action.execute(context); assertEquals(1, action.counter); }
public void testSameSession() { MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); // Session created and bound to conversation final Session hibSession = (Session) flowSession.getScope().get("persistenceContext"); assertNotNull("Should have been populated", hibSession); hibernateListener.paused(context); assertSessionNotBound(); // Session bound to thread local variable hibernateListener.resuming(context); assertSessionBound(); hibernate.templateExecuteWithNativeSession(session -> assertSame("Should have been original instance", hibSession, session)); hibernateListener.paused(context); assertSessionNotBound(); }
public FlowSession endActiveFlowSession(MutableAttributeMap output) throws IllegalStateException { MockFlowSession endingSession = getMockFlowExecutionContext().getMockActiveSession(); endingSession.getDefinitionInternal().end(this, output); endingSession.setStatus(FlowSessionStatus.ENDED); getMockFlowExecutionContext().setActiveSession(null); return endingSession; }
public ViewSelection start(Flow flow, MutableAttributeMap input) throws IllegalStateException { getMockFlowExecutionContext().setActiveSession(new MockFlowSession(flow, input)); getMockFlowExecutionContext().getMockActiveSession().setStatus(FlowSessionStatus.STARTING); ViewSelection selectedView = flow.start(this, input); return selectedView; }
public boolean getEmbeddedMode() { return getMockFlowExecutionContext().getMockActiveSession().isEmbeddedMode(); }
public void testNoCommitAttributeSetOnEndState() { assertEquals("Table should only have one row", 1, getCount()); MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel"); flowSession.setState(endState); hibernateListener.sessionEnding(context, flowSession, "success", null); hibernateListener.sessionEnded(context, flowSession, "cancel", null); assertEquals("Table should only have three rows", 1, getCount()); assertSessionNotBound(); }
public void start(Flow flow, MutableAttributeMap<?> input) throws IllegalStateException { MockFlowSession session = new MockFlowSession(flow, input); if (getFlowExecutionContext().isActive()) { session.setParent(getFlowExecutionContext().getActiveSession()); } getMockFlowExecutionContext().setActiveSession(session); flow.start(this, input); }
public void setCurrentState(State state) { getMockFlowExecutionContext().getMockActiveSession().setState(state); }