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 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 testRenderWithBindingModel() throws Exception { MockRequestControlContext context = new MockRequestControlContext(); context.setCurrentState(new ViewState(context.getRootFlow(), "test", new StubViewFactory())); Object bindBean = new BindBean(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); view.setConversionService(new DefaultConversionService()); view.render(); assertEquals(context.getFlowScope().get("bindBean"), model.get("bindBean")); BindingModel bm = (BindingModel) model.get(BindingResult.MODEL_KEY_PREFIX + "bindBean"); assertNotNull(bm); assertEquals(null, bm.getFieldValue("stringProperty")); assertEquals("3", bm.getFieldValue("integerProperty")); assertEquals("2008-01-01", bm.getFieldValue("dateProperty")); }
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 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 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 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 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 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 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")); }
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 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)); }