/** * Factory method that creates a new view state, a state where a user is allowed to participate in the flow. This * method is an atomic operation that returns a fully initialized state. It encapsulates the selection of the view * 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 viewFactory the state view factory strategy * @param redirect whether to send a flow execution redirect before rendering * @param popup whether to display the view in a popup window * @param renderActions any 'render actions' to execute on entry and refresh; may be null * @param transitions any transitions (paths) out of this state; may be null * @param exceptionHandlers any exception handlers; may be null * @param exitActions any state exit actions; 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 view state instance */ public State createViewState(String id, Flow flow, ViewVariable[] variables, Action[] entryActions, ViewFactory viewFactory, Boolean redirect, boolean popup, Action[] renderActions, Transition[] transitions, FlowExecutionExceptionHandler[] exceptionHandlers, Action[] exitActions, AttributeMap<?> attributes) { ViewState viewState = new ViewState(flow, id, viewFactory); viewState.addVariables(variables); viewState.setRedirect(redirect); viewState.setPopup(popup); viewState.getRenderActionList().addAll(renderActions); configureCommonProperties(viewState, entryActions, transitions, exceptionHandlers, exitActions, attributes); return viewState; }
/** * 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); }
protected void initView(MockRequestContext requestContext) { ((MockFlowSession) requestContext.getFlowExecutionContext().getActiveSession()).setState(new ViewState( requestContext.getRootFlow(), "view", context -> { throw new UnsupportedOperationException("Auto-generated method stub"); })); }
protected void initView(MockRequestContext requestContext) { ((MockFlowSession) requestContext.getFlowExecutionContext().getActiveSession()).setState(new ViewState( requestContext.getRootFlow(), "view", new ViewFactory() { public View getView(RequestContext context) { throw new UnsupportedOperationException("Not implemented"); } })); }
public void testStateEnteringNoSecurity() { SecurityFlowExecutionListener listener = new SecurityFlowExecutionListener(); RequestContext context = new MockRequestContext(); Flow flow = new Flow("flow"); ViewState state = new ViewState(flow, "view", new StubViewFactory()); listener.stateEntering(context, state); }
protected void setUp() throws Exception { flow = new Flow("myFlow"); ViewState s1 = new ViewState(flow, "state", new StubViewFactory()); s1.getTransitionSet().add(new Transition(new DefaultTargetStateResolver("state2"))); new ViewState(flow, "state2", new StubViewFactory()); conversationManager = new StubConversationManager(); FlowDefinitionLocator locator = flowId -> flow; SerializedFlowExecutionSnapshotFactory snapshotFactory = new SerializedFlowExecutionSnapshotFactory( executionFactory, locator); repository = new DefaultFlowExecutionRepository(conversationManager, snapshotFactory); executionFactory.setExecutionKeyFactory(repository); }
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 testFallbackModelValidationMethodInvoked() { Model model = new Model(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state2", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertFalse(model.state1Invoked); assertTrue(model.fallbackInvoked); }
public void testFallbackModelErrorsValidationMethodInvoked() { ErrorsModel model = new ErrorsModel(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state2", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertFalse(model.state1Invoked); assertTrue(model.fallbackInvoked); }
public void testStateAndFallbackErrorsModelValidationMethodInvoked() { ErrorsModel model = new ErrorsModel(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertTrue(model.state1Invoked); assertTrue(model.fallbackInvoked); }
public void testStateEnteringWithSecurity() { SecurityFlowExecutionListener listener = new SecurityFlowExecutionListener(); RequestContext context = new MockRequestContext(); Flow flow = new Flow("flow"); ViewState state = new ViewState(flow, "view", new StubViewFactory()); SecurityRule rule = getSecurityRuleAllAuthorized(); state.getAttributes().put(SecurityRule.SECURITY_ATTRIBUTE_NAME, rule); configureSecurityContext(); listener.stateEntering(context, state); }
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(); }
public void testResolveViewScope() { MockRequestControlContext context = new MockRequestControlContext(); ViewState state = new ViewState(context.getRootFlow(), "view", new StubViewFactory()); context.setCurrentState(state); context.getViewScope().put("foo", "bar"); Expression exp = parser.parseExpression("foo", new FluentParserContext().evaluate(RequestContext.class)); assertEquals("bar", exp.getValue(context)); }
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 testEnterViewStateWithAlwaysRedirectOnPause() { 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"); context.setAlwaysRedirectOnPause(true); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testEnterViewStateWithLocalRedirect() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(true); MockRequestControlContext context = new MockRequestControlContext(flow); 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 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 testEnterViewStateResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().recordResponseComplete(); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(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")); }