Package org.springframework.webflow.execution

Examples of org.springframework.webflow.execution.TestAction


import org.springframework.webflow.test.MockRequestContext;

public class ActionExecutingViewFactoryTests extends TestCase {

  public void testGetView() throws Exception {
    TestAction action = new TestAction();
    ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action);
    MockRequestContext context = new MockRequestContext();
    View view = factory.getView(context);
    assertFalse(action.isExecuted());
    view.render();
    assertTrue(action.isExecuted());
  }
View Full Code Here


    view.render();
    assertTrue(action.isExecuted());
  }

  public void testProcessUserEvent() throws IOException {
    TestAction action = new TestAction();
    ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action);
    MockRequestContext context = new MockRequestContext();
    View view = factory.getView(context);
    assertFalse(action.isExecuted());
    view.render();
    assertTrue(action.isExecuted());
    context.putRequestParameter("_eventId", "foo");
    view.processUserEvent();
    assertTrue(view.hasFlowEvent());
    assertEquals("foo", view.getFlowEvent().getId());
  }
View Full Code Here

    assertTrue(view.hasFlowEvent());
    assertEquals("foo", view.getFlowEvent().getId());
  }

  public void testProcessUserEventButton() throws IOException {
    TestAction action = new TestAction();
    ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action);
    MockRequestContext context = new MockRequestContext();
    View view = factory.getView(context);
    assertFalse(action.isExecuted());
    view.render();
    assertTrue(action.isExecuted());
    context.putRequestParameter("_eventId_foo", "doesn't matter");
    view.processUserEvent();
    assertTrue(view.hasFlowEvent());
    assertEquals("foo", view.getFlowEvent().getId());
  }
View Full Code Here

    assertTrue(view.hasFlowEvent());
    assertEquals("foo", view.getFlowEvent().getId());
  }

  public void testProcessUserEventNoEvent() throws IOException {
    TestAction action = new TestAction();
    ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action);
    MockRequestContext context = new MockRequestContext();
    View view = factory.getView(context);
    assertFalse(action.isExecuted());
    view.render();
    assertTrue(action.isExecuted());
    view.processUserEvent();
    assertFalse(view.hasFlowEvent());
    assertNull(view.getFlowEvent());
  }
View Full Code Here

    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")));
    EndState end = new EndState(flow, "finish");
    TestAction testAction = new TestAction();
    end.setFinalResponseAction(testAction);
    MockRequestControlContext context = new MockRequestControlContext(flow);
    state.enter(context);
    context = new MockRequestControlContext(context.getFlowExecutionContext());
    context.putRequestParameter("_eventId", "submit");
    state.resume(context);
    assertTrue(context.getExternalContext().isResponseComplete());
    assertFalse(context.getFlowExecutionContext().isActive());
    assertTrue(testAction.isExecuted());
  }
View Full Code Here

  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));
View Full Code Here

  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"));
  }
View Full Code Here

  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));
View Full Code Here

  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));
View Full Code Here

  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));
View Full Code Here

TOP

Related Classes of org.springframework.webflow.execution.TestAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.