/** * Factory method that creates a new end state, a state where an executing flow session terminates. This method is * an atomic operation that returns a fully initialized state. It encapsulates the selection of the end state * implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param finalResponseAction the state response renderer; may be null * @param outputMapper the state output mapper; may be null * @param exceptionHandlers any exception handlers; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized subflow state instance */ public State createEndState(String id, Flow flow, Action[] entryActions, Action finalResponseAction, Mapper outputMapper, FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap<?> attributes) { EndState endState = new EndState(flow, id); if (finalResponseAction != null) { endState.setFinalResponseAction(finalResponseAction); } if (outputMapper != null) { endState.setOutputMapper(outputMapper); } configureCommonProperties(endState, entryActions, exceptionHandlers, attributes); return endState; }
protected void setUp() throws Exception { flow = new Flow("myFlow"); state = new EndState(flow, "end"); context = new MockRequestContext(flow); }
public void setUp() { flow = new Flow("myFlow"); state = new ActionState(flow, "actionState"); new EndState(flow, "finish"); context = new MockRequestControlContext(flow); }
public void testAddStateAlreadyInOtherFlow() { Flow otherFlow = new Flow("myOtherFlow"); State state = new EndState(otherFlow, "myState1"); Flow flow = new Flow("myFlow"); try { flow.add(state); fail("Added state part of another flow"); } catch (IllegalArgumentException e) { // expected } }
public void buildStates() throws FlowBuilderException { State state = new EndState(getFlow(), "end"); state.getEntryActionList().add(new AbstractAction() { protected Event doExecute(RequestContext context) throws Exception { throw new NullPointerException("failing"); } }); new TransitionableState(getFlow(), "showError") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { } }; }
public void testAddSameStateTwice() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "myState1"); try { flow.add(state); fail("Should have failed"); } catch (IllegalArgumentException e) { } assertEquals("State count wrong:", 1, flow.getStateCount()); }
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 testEnterEndStateWithFinalResponseRenderer() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); StubFinalResponseAction action = new StubFinalResponseAction(); state.setFinalResponseAction(action); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertTrue(action.executeCalled); }
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) { Flow mockDetailFlow = new Flow("detail-flow"); mockDetailFlow.setInputMapper((source, target) -> { assertEquals("id of value 1 not provided as input by calling search flow", 1L, ((AttributeMap<?>) source).get("id")); return null; }); // test responding to finish result new EndState(mockDetailFlow, "finish"); builderContext.registerSubflow(mockDetailFlow); builderContext.registerBean("phonebook", new TestPhoneBook()); }
public void testEnterEndStateWithFinalResponseRendererResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); StubFinalResponseAction action = new StubFinalResponseAction(); state.setFinalResponseAction(action); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().recordResponseComplete(); state.enter(context); assertFalse(action.executeCalled); }
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 testAddStates() { Flow flow = new Flow("myFlow"); new EndState(flow, "myState1"); new EndState(flow, "myState2"); assertEquals("Wrong start state:", "myState1", flow.getStartState().getId()); assertEquals("State count wrong:", 2, flow.getStateCount()); assertTrue(flow.containsState("myState1")); assertTrue(flow.containsState("myState2")); State state = flow.getStateInstance("myState1"); assertEquals("Wrong flow:", flow.getId(), state.getFlow().getId()); assertEquals("Wrong state:", "myState1", flow.getState("myState1").getId()); assertEquals("Wrong state:", "myState2", flow.getState("myState2").getId()); }
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 testIfDecision() { Flow flow = new Flow("flow"); DecisionState state = new DecisionState(flow, "decisionState"); state.getTransitionSet().add(new Transition(new MockTransitionCriteria("foo"), to("target"))); new EndState(flow, "target"); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentEvent(new Event(this, "foo")); state.enter(context); assertFalse(context.getFlowExecutionContext().isActive()); }
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()); }