/** * Create a transition criteria chain chaining given list of actions. * @param actions the actions (and their execution properties) to chain together */ public static TransitionCriteria criteriaChainFor(Action... actions) { if (actions == null || actions.length == 0) { return WildcardTransitionCriteria.INSTANCE; } TransitionCriteriaChain chain = new TransitionCriteriaChain(); for (Action action : actions) { chain.add(new ActionTransitionCriteria(action)); } return chain; } }
/** * Creates a <code>TransitionCriteria</code> that will execute the specified action when the Transition is * executed but before the transition's target state is entered. * <p> * This criteria will only allow the Transition to complete execution if the Action completes successfully. * @param action the action to execute after a transition is matched but before it transitions to its target state * @return the transition execution criteria */ protected TransitionCriteria ifReturnedSuccess(Action action) { return new ActionTransitionCriteria(action); }
/** * Create a transition criteria chain chaining given list of actions. * @param actions the actions (and their execution properties) to chain together */ public static TransitionCriteria criteriaChainFor(Action... actions) { if (actions == null || actions.length == 0) { return WildcardTransitionCriteria.INSTANCE; } TransitionCriteriaChain chain = new TransitionCriteriaChain(); for (Action action : actions) { chain.add(new ActionTransitionCriteria(action)); } return chain; } }
/** * Create a transition criteria chain chaining given list of actions. * @param actions the actions (and their execution properties) to chain together */ public static TransitionCriteria criteriaChainFor(Action[] actions) { if (actions == null || actions.length == 0) { return WildcardTransitionCriteria.INSTANCE; } TransitionCriteriaChain chain = new TransitionCriteriaChain(); for (int i = 0; i < actions.length; i++) { chain.add(new ActionTransitionCriteria(actions[i])); } return chain; } }
/** * Create a transition criteria chain chaining given list of actions. * @param actions the actions (and their execution properties) to chain together */ public static TransitionCriteria criteriaChainFor(AnnotatedAction[] actions) { if (actions == null || actions.length == 0) { return WildcardTransitionCriteria.INSTANCE; } TransitionCriteriaChain chain = new TransitionCriteriaChain(); for (int i = 0; i < actions.length; i++) { chain.add(new ActionTransitionCriteria(actions[i])); } return chain; } }
protected void setUp() throws Exception { action = new MockAction(); criteria = new ActionTransitionCriteria(action); }
public void testResumeViewStateForEventStateNotExitedNonAjaxRedirectEnabled() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); TestAction action = new TestAction(); t.setExecutionCriteria(new ActionTransitionCriteria(action)); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); context.setAlwaysRedirectOnPause(true); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.setAlwaysRedirectOnPause(true); context.putRequestParameter("_eventId", "submit"); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals(1, action.getExecutionCount()); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertEquals(StubViewFactory.USER_EVENT_STATE, context.getFlashScope().get(View.USER_EVENT_STATE_ATTRIBUTE)); assertTrue(context.getFlashScope().contains("foo")); }
public void testResumeViewStateForEventStateNotExitedAjax() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); TestAction action = new TestAction(); t.setExecutionCriteria(new ActionTransitionCriteria(action)); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); context.getMockExternalContext().setAjaxRequest(true); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.putRequestParameter("_eventId", "submit"); context.getMockExternalContext().setAjaxRequest(true); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals(1, action.getExecutionCount()); assertTrue(context.getExternalContext().isResponseComplete()); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE)); }
public void testResumeViewStateForEventStateNotExitedNonAjax() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); TestAction action = new TestAction(); t.setExecutionCriteria(new ActionTransitionCriteria(action)); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.getFlowScope().remove("renderCalled"); context.putRequestParameter("_eventId", "submit"); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals(1, action.getExecutionCount()); assertTrue(context.getExternalContext().isResponseComplete()); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE)); }
public void testResumeViewStateForEventStateNoExitActionRecordedExecutionRedirect() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); TestAction action = new TestAction() { protected Event doExecute(RequestContext context) throws Exception { super.doExecute(context); context.getExternalContext().requestFlowExecutionRedirect(); return success(); } }; t.setExecutionCriteria(new ActionTransitionCriteria(action)); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); context.getFlowScope().remove("renderCalled"); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.putRequestParameter("_eventId", "submit"); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals(1, action.getExecutionCount()); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); assertEquals(StubViewFactory.USER_EVENT_STATE, context.getFlashScope().get(View.USER_EVENT_STATE_ATTRIBUTE)); }
public void testResumeViewStateForEventStateNoExitActionRecordedResponseComplete() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); TestAction action = new TestAction() { protected Event doExecute(RequestContext context) throws Exception { super.doExecute(context); context.getExternalContext().recordResponseComplete(); return success(); } }; t.setExecutionCriteria(new ActionTransitionCriteria(action)); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); context.getFlowScope().remove("renderCalled"); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.putRequestParameter("_eventId", "submit"); context.getFlashScope().put("Foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertEquals(1, action.getExecutionCount()); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); assertFalse(context.getFlashScope().contains(View.USER_EVENT_STATE_ATTRIBUTE)); }