public void start(Flow flow, MutableAttributeMap<?> input) throws FlowExecutionException { flowExecution.start(flow, input, this); }
listeners.fireRequestSubmitted(requestContext); try { start(flow, input, requestContext); } catch (FlowExecutionException e) { handleException(e, requestContext);
public void start(Flow flow, MutableAttributeMap<?> input) throws FlowExecutionException { flowExecution.start(flow, input, this); }
public void start(Flow flow, MutableAttributeMap input) throws FlowExecutionException { flowExecution.start(flow, input, this); }
public void testStartCannotCallTwice() { Flow flow = new Flow("flow"); new EndState(flow, "end"); FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); execution.start(null, context); try { execution.start(null, context); fail("Should've failed"); } catch (IllegalStateException e) { } }
public void testResumeAfterEnding() { Flow flow = new Flow("flow"); new EndState(flow, "end"); FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); execution.start(null, context); try { execution.resume(context); fail("Should've failed"); } catch (IllegalStateException e) { } }
public void testStartFlowExecutionExceptionThrownByState() { Flow flow = new Flow("flow"); final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw e; } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); try { execution.start(null, context); fail("Should have failed"); } catch (FlowExecutionException ex) { assertSame(e, ex); } }
public void testStartWithNullInputMap() { Flow flow = new Flow("flow"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { // no op } }; MockFlowExecutionListener mockListener = new MockFlowExecutionListener() { public void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap<?> input) { super.sessionStarting(context, session, input); assertNotNull(input); } }; FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); MockExternalContext context = new MockExternalContext(); execution.start(null, context); assertTrue(execution.isActive()); assertEquals(1, mockListener.getPausedCount()); }
public void testStartAndPause() { Flow flow = new Flow("flow"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { // no op } }; MockFlowExecutionListener mockListener = new MockFlowExecutionListener(); FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); MockExternalContext context = new MockExternalContext(); execution.start(null, context); assertTrue(execution.isActive()); assertEquals(1, mockListener.getPausedCount()); }
public void testExceptionHandledByNestedExceptionHandler() { Flow flow = new Flow("flow"); ExceptionThrowingExceptionHandler exceptionHandler = new ExceptionThrowingExceptionHandler(true); flow.getExceptionHandlerSet().add(exceptionHandler); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw new FlowExecutionException("flow", "state", "Oops"); } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertEquals(2, exceptionHandler.getHandleCount()); }
public void testStartExceptionThrownByStateHandledByFlowExceptionHandler() { Flow flow = new Flow("flow"); StubFlowExecutionExceptionHandler exceptionHandler = new StubFlowExecutionExceptionHandler(); flow.getExceptionHandlerSet().add(exceptionHandler); final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw e; } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertTrue(exceptionHandler.getHandled()); }
public void testResumeNotAViewState() { Flow flow = new Flow("flow"); new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { // no-op } }; MockFlowExecutionListener mockListener = new MockFlowExecutionListener(); FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); MockExternalContext context = new MockExternalContext(); execution.start(null, context); context = new MockExternalContext(); try { execution.resume(context); assertEquals(1, mockListener.getResumingCount()); fail("Should have failed"); } catch (FlowExecutionException e) { } }
public void testStartExceptionThrownByState() { Flow flow = new Flow("flow"); State state = new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw new IllegalStateException("Oops"); } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); try { execution.start(null, context); fail("Should have failed"); } catch (FlowExecutionException e) { assertEquals(flow.getId(), e.getFlowId()); assertEquals(state.getId(), e.getStateId()); } }
public void testRequestContextManagedOnStartAndResume() { Flow flow = new Flow("flow"); new ViewState(flow, "view", new StubViewFactory()) { public void resume(RequestControlContext context) { assertSame(context, RequestContextHolder.getRequestContext()); } }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setKeyFactory(new MockFlowExecutionKeyFactory()); MockExternalContext context = new MockExternalContext(); execution.start(null, context); assertNull("RequestContext was not released", RequestContextHolder.getRequestContext()); context = new MockExternalContext(); execution.resume(context); assertNull("RequestContext was not released", RequestContextHolder.getRequestContext()); }
public void testResume() { Flow flow = new Flow("flow"); new ViewState(flow, "view", new StubViewFactory()); MockFlowExecutionListener mockListener = new MockFlowExecutionListener(); FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); execution.setKeyFactory(new MockFlowExecutionKeyFactory()); MockExternalContext context = new MockExternalContext(); execution.start(null, context); context = new MockExternalContext(); execution.resume(context); assertEquals(1, mockListener.getResumingCount()); assertEquals(2, mockListener.getPausedCount()); }
public void testStartExceptionThrownByStateHandledByStateExceptionHandler() { Flow flow = new Flow("flow"); flow.getExceptionHandlerSet().add(new StubFlowExecutionExceptionHandler()); final FlowExecutionException e = new FlowExecutionException("flow", "state", "Oops"); State s = new State(flow, "state") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { throw e; } }; StubFlowExecutionExceptionHandler exceptionHandler = new StubFlowExecutionExceptionHandler(); s.getExceptionHandlerSet().add(exceptionHandler); FlowExecutionImpl execution = new FlowExecutionImpl(flow); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertTrue(exceptionHandler.getHandled()); }
public void testStartAndEndSavedMessages() { Flow flow = new Flow("flow"); new EndState(flow, "end"); MockFlowExecutionListener mockListener = new MockFlowExecutionListener() { public void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap<?> input) { super.sessionStarting(context, session, input); context.getMessageContext().addMessage(new MessageBuilder().source("foo").defaultText("bar").build()); } }; FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); MockExternalContext context = new MockExternalContext(); assertFalse(execution.hasStarted()); execution.start(null, context); assertTrue(execution.hasStarted()); assertFalse(execution.isActive()); assertTrue(execution.hasEnded()); assertNotNull(execution.getFlashScope().get("messagesMemento")); }
public void testResumeFlowExecutionException() { Flow flow = new Flow("flow"); ViewState state = new ViewState(flow, "view", new StubViewFactory()) { public void resume(RequestControlContext context) { throw new FlowExecutionException("flow", "view", "oops"); } }; MockFlowExecutionListener mockListener = new MockFlowExecutionListener(); FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); execution.setKeyFactory(new MockFlowExecutionKeyFactory()); MockExternalContext context = new MockExternalContext(); execution.start(null, context); context = new MockExternalContext(); try { execution.resume(context); } catch (FlowExecutionException e) { assertEquals(flow.getId(), e.getFlowId()); assertEquals(state.getId(), e.getStateId()); assertEquals(1, mockListener.getResumingCount()); assertEquals(2, mockListener.getPausedCount()); } }
public void testResumeException() { Flow flow = new Flow("flow"); ViewState state = new ViewState(flow, "view", new StubViewFactory()) { public void resume(RequestControlContext context) { throw new IllegalStateException("Oops"); } }; MockFlowExecutionListener mockListener = new MockFlowExecutionListener(); FlowExecutionListener[] listeners = new FlowExecutionListener[] { mockListener }; FlowExecutionImpl execution = new FlowExecutionImpl(flow); execution.setListeners(listeners); execution.setKeyFactory(new MockFlowExecutionKeyFactory()); MockExternalContext context = new MockExternalContext(); execution.start(null, context); context = new MockExternalContext(); try { execution.resume(context); } catch (FlowExecutionException e) { assertEquals(flow.getId(), e.getFlowId()); assertEquals(state.getId(), e.getStateId()); assertEquals(1, mockListener.getResumingCount()); assertEquals(2, mockListener.getPausedCount()); } }
public void testCreateSnapshot() { FlowExecutionImpl flowExecution = (FlowExecutionImpl) executionFactory.createFlowExecution(flow); flowExecution.start(null, new MockExternalContext()); flowExecution.getActiveSession().getScope().put("foo", "bar"); FlowExecutionSnapshot snapshot = factory.createSnapshot(flowExecution); FlowExecutionImpl flowExecution2 = (FlowExecutionImpl) factory.restoreExecution(snapshot, "myFlow", null, flowExecution.getConversationScope(), null); assertNotSame(flowExecution, flowExecution2); assertEquals(flowExecution.getDefinition().getId(), flowExecution2.getDefinition().getId()); assertEquals(flowExecution.getActiveSession().getScope().get("foo"), flowExecution2.getActiveSession() .getScope().get("foo")); assertEquals(flowExecution.getActiveSession().getState().getId(), flowExecution2.getActiveSession().getState() .getId()); assertNull(flowExecution2.getKey()); assertSame(flowExecution.getConversationScope(), flowExecution2.getConversationScope()); } }