/** * 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); }
/** * Create a new flow with the given id and attributes. * @param id the flow id * @param attributes the attributes * @return the flow */ public static Flow create(String id, AttributeMap<?> attributes) { Flow flow = new Flow(id); flow.getAttributes().putAll(attributes); return flow; }
public void setUp() { flow = new Flow("flow"); state = new State(flow, "myState") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { entered = true; } }; }
/** * 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); }
public void testGetStateNoStartState() { Flow flow = new Flow("myFlow"); try { flow.getStartState(); fail("Retrieved start state when no such state"); } catch (IllegalStateException e) { // expected } }
protected void setUp() throws Exception { flow = new Flow("myFlow"); state = new EndState(flow, "end"); context = new MockRequestContext(flow); }
public void testStartWithoutStartState() { MockRequestControlContext context = new MockRequestControlContext(flow); try { Flow empty = new Flow("empty"); empty.start(context, null); fail("should have failed"); } catch (IllegalStateException e) { } }
public void testStaticListener() { final FlowExecutionListener listener1 = new FlowExecutionListener() {}; loader = new StaticFlowExecutionListenerLoader(listener1); assertEquals(listener1, loader.getListeners(new Flow("foo"))[0]); }
protected void setUp() { flow = new Flow("myFlow"); state = new TransitionableState(flow, "state1") { protected void doEnter(RequestControlContext context) { throw new FlowExecutionException(getFlow().getId(), getId(), "Oops!", new TestException()); } }; state.getTransitionSet().add(new Transition(toState("end"))); }
private MockRequestContext getRequestContext() { Flow flow = new Flow("id"); MockRequestContext ctx = new MockRequestContext(flow); RequestContextHolder.setRequestContext(ctx); ctx.getFlowScope().put("foo", "bar"); ctx.setCurrentEvent(new Event(this, "sample")); return ctx; } }
public void testEnterEndStateTerminateFlowExecution() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertFalse("Active", context.getFlowExecutionContext().isActive()); }
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 testGetFlowExecutorBasicConfig() throws Exception { factoryBean.setFlowDefinitionLocator(id -> { Flow flow = new Flow(id); ViewState view = new ViewState(flow, "view", new StubViewFactory()); view.getTransitionSet().add(new Transition(new DefaultTargetStateResolver("end"))); new EndState(flow, "end"); return flow; }); factoryBean.afterPropertiesSet(); factoryBean.getObject(); }
private Flow createSimpleFlow() { flow = new Flow("myFlow"); ViewState state1 = new ViewState(flow, "myState1", new StubViewFactory()); state1.getTransitionSet().add(new Transition(on("submit"), to("myState2"))); new EndState(flow, "myState2"); flow.getGlobalTransitionSet().add(new Transition(on("globalEvent"), to("myState2"))); return flow; }
public void testEnterViewStateWithNoLocalRedirect() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(false); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertTrue("Render called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testEnterViewStateRedirectResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().requestFlowExecutionRedirect(); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testEnterViewStateRenderResponse() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getFlashScope().put("foo", "bar"); state.enter(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testElseDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("invalid"))); state.getTransitionSet().add(new Transition(to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "bogus")); state.enter(context); assertFalse(context.getFlowExecutionContext().isActive()); }