public boolean isRedirectRequested() { return getFlowExecutionRedirectRequested() || getFlowDefinitionRedirectRequested() || getExternalRedirectRequested(); }
private void assertResponseAllowed() throws IllegalStateException { if (!isResponseAllowed()) { if (getFlowExecutionRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because a redirect has already been requested on this ExternalContext"); } if (getFlowDefinitionRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because a flowRedirect has already been requested on this ExternalContext"); } if (getExternalRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because an externalRedirect has already been requested on this ExternalContext"); } if (responseComplete) { throw new IllegalStateException( "A response is not allowed because one has already been completed on this ExternalContext"); } else { throw new IllegalStateException("A response is not allowed"); } } }
public boolean isRedirectRequested() { return getFlowExecutionRedirectRequested() || getFlowDefinitionRedirectRequested() || getExternalRedirectRequested(); }
private void assertResponseAllowed() throws IllegalStateException { if (!isResponseAllowed()) { if (getFlowExecutionRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because a redirect has already been requested on this ExternalContext"); } if (getFlowDefinitionRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because a flowRedirect has already been requested on this ExternalContext"); } if (getExternalRedirectRequested()) { throw new IllegalStateException( "A response is not allowed because an externalRedirect has already been requested on this ExternalContext"); } if (responseComplete) { throw new IllegalStateException( "A response is not allowed because one has already been completed on this ExternalContext"); } else { throw new IllegalStateException("A response is not allowed"); } } }
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 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 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 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 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 testEmbeddedModeOverridesRedirectInSameState() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); context.getMockExternalContext().setAjaxRequest(true); context.setEmbeddedMode(); context.setAlwaysRedirectOnPause(true); context.setRedirectInSameState(true); state.enter(context); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
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 testViewStateRedirectOverridesEmbeddedMode() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(false); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context.getMockExternalContext().setAjaxRequest(true); context.setEmbeddedMode(); context.setAlwaysRedirectOnPause(true); context.setRedirectInSameState(true); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
public void testEnterViewStateRenderNotAllowed() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); context.getMockExternalContext().setResponseAllowed(false); context.getFlashScope().put("foo", "bar"); state.enter(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertTrue(context.getFlashScope().contains("foo")); }
public void testEnterViewStateRedirectInPopup() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.setRedirect(true); state.setPopup(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.getMockExternalContext().getRedirectInPopup()); assertTrue(context.getFlashScope().contains("foo")); }
public void testRedirectInSameStateOverridesAlwaysRedirectOnPause() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); state.getTransitionSet().add(t); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.setAlwaysRedirectOnPause(false); context.setRedirectInSameState(true); context.getFlowScope().remove("renderCalled"); context.putRequestParameter("_eventId", "submit"); state.resume(context); assertTrue(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
public void testEnterViewStateWithVariables() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.addVariable(new ViewVariable("foo", new VariableValueFactory() { public Object createInitialValue(RequestContext context) { return "bar"; } public void restoreReferences(Object value, RequestContext context) { } })); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertEquals("bar", context.getViewScope().getString("foo")); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); }
public void testResumeViewStateRestoreVariables() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.addVariable(new ViewVariable("foo", new VariableValueFactory() { public Object createInitialValue(RequestContext context) { return new TestBean(); } public void restoreReferences(Object value, RequestContext context) { ((TestBean) value).datum1 = "Restored"; } })); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); state.resume(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertEquals("Restored", ((TestBean) context.getViewScope().get("foo")).datum1); }
public void testResumeViewStateForRefresh() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue("Render not called", context.getFlowScope().contains("renderCalled")); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testResumeViewStateForRefreshResponseCompleteRecorded() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.getTransitionSet().add(new Transition(on("submit"), to("finish"))); new EndState(flow, "finish"); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.getFlowScope().remove("renderCalled"); context.getFlashScope().put("foo", "bar"); context.getExternalContext().recordResponseComplete(); state.resume(context); assertFalse("Render called", context.getFlowScope().contains("renderCalled")); assertFalse(context.getMockExternalContext().getFlowExecutionRedirectRequested()); assertFalse(context.getFlashScope().contains("foo")); }
public void testResumeViewStateForEventStateNotExitedNonAjaxResponseNotAllowed() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); Transition t = new Transition(on("submit"), null); 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.getMockExternalContext().setResponseAllowed(false); context.getFlashScope().put("foo", "bar"); state.resume(context); assertTrue(context.getFlowExecutionContext().isActive()); assertTrue(context.getExternalContext().isResponseComplete()); 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")); }