/** * Factory method that creates a new transition, a path from one step in a flow to another. This method is an atomic * operation that returns a fully initialized transition. It encapsulates the selection of the transition * implementation as well as the transition assembly. * @param targetStateResolver the resolver of the target state of the transition (required) * @param matchingCriteria the criteria that matches the transition; may be null * @param executionCriteria the criteria that governs execution of the transition after match; may be null * @param attributes attributes to assign to the transition, which may also be used to affect transition * construction; may be null * @return the fully initialized transition instance */ public Transition createTransition(TargetStateResolver targetStateResolver, TransitionCriteria matchingCriteria, TransitionCriteria executionCriteria, AttributeMap<?> attributes) { Transition transition = new Transition(targetStateResolver); if (matchingCriteria != null) { transition.setMatchingCriteria(matchingCriteria); } if (executionCriteria != null) { transition.setExecutionCriteria(executionCriteria); } transition.getAttributes().putAll(attributes); return transition; }
/** * Factory method that creates a new transition, a path from one step in a flow to another. This method is an atomic * operation that returns a fully initialized transition. It encapsulates the selection of the transition * implementation as well as the transition assembly. * @param targetStateResolver the resolver of the target state of the transition (required) * @param matchingCriteria the criteria that matches the transition; may be null * @param executionCriteria the criteria that governs execution of the transition after match; may be null * @param attributes attributes to assign to the transition, which may also be used to affect transition * construction; may be null * @return the fully initialized transition instance */ public Transition createTransition(TargetStateResolver targetStateResolver, TransitionCriteria matchingCriteria, TransitionCriteria executionCriteria, AttributeMap<?> attributes) { Transition transition = new Transition(targetStateResolver); if (matchingCriteria != null) { transition.setMatchingCriteria(matchingCriteria); } if (executionCriteria != null) { transition.setExecutionCriteria(executionCriteria); } transition.getAttributes().putAll(attributes); return transition; }
/** * Factory method that creates a new transition, a path from one step in a flow to another. This method is an atomic * operation that returns a fully initialized transition. It encapsulates the selection of the transition * implementation as well as the transition assembly. * @param targetStateResolver the resolver of the target state of the transition (required) * @param matchingCriteria the criteria that matches the transition; may be null * @param executionCriteria the criteria that governs execution of the transition after match; may be null * @param attributes attributes to assign to the transition, which may also be used to affect transition * construction; may be null * @return the fully initialized transition instance */ public Transition createTransition(TargetStateResolver targetStateResolver, TransitionCriteria matchingCriteria, TransitionCriteria executionCriteria, AttributeMap attributes) { Transition transition = new Transition(targetStateResolver); if (matchingCriteria != null) { transition.setMatchingCriteria(matchingCriteria); } if (executionCriteria != null) { transition.setExecutionCriteria(executionCriteria); } transition.getAttributes().putAll(attributes); return transition; }
/** * Factory method that creates a new transition, a path from one step in a flow to another. This method is an atomic * operation that returns a fully initialized transition. It encapsulates the selection of the transition * implementation as well as the transition assembly. * @param targetStateResolver the resolver of the target state of the transition (required) * @param matchingCriteria the criteria that matches the transition; may be null * @param executionCriteria the criteria that governs execution of the transition after match; may be null * @param attributes attributes to assign to the transition, which may also be used to affect transition * construction; may be null * @return the fully initialized transition instance * @throws FlowArtifactLookupException an exception occured creating the transition */ public Transition createTransition(TargetStateResolver targetStateResolver, TransitionCriteria matchingCriteria, TransitionCriteria executionCriteria, AttributeMap attributes) throws FlowArtifactLookupException { Transition transition = new Transition(targetStateResolver); if (matchingCriteria != null) { transition.setMatchingCriteria(matchingCriteria); } if (executionCriteria != null) { transition.setExecutionCriteria(executionCriteria); } transition.getAttributeMap().putAll(attributes); return transition; }
public void testTransitionExecutionRefused() { Flow flow = new Flow("flow"); final TransitionableState source = new TransitionableState(flow, "state 1") { public void exit(RequestControlContext context) { exitCalled = true; } protected void doEnter(RequestControlContext context) throws FlowExecutionException { } }; final TransitionableState target = new TransitionableState(flow, "state 2") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { } }; TargetStateResolver targetResolver = (transition, sourceState, context) -> { assertSame(source, sourceState); return target; }; MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(source); Transition t = new Transition(targetResolver); t.setExecutionCriteria(context1 -> false); boolean stateExited = t.execute(source, context); assertFalse(stateExited); assertFalse(exitCalled); assertSame(source, context.getCurrentState()); }
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 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 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 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)); }