Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockFlowSession


    this.root = new MockMyfacesResponseStateManager();
    this.flow = new FlowResponseStateManager(this.root);
    this.manager = new MyFacesFlowResponseStateManager(this.flow);
    this.requestContext = new MockRequestContext();
    MockFlowExecutionContext executionContext = requestContext.getMockFlowExecutionContext();
    MockFlowSession session = executionContext.getMockActiveSession();
    ViewFactory viewFactory = EasyMock.createNiceMock(ViewFactory.class);
    session.setState(new ViewState(session.getDefinitionInternal(), "view", viewFactory));
    executionContext.setKey(new MockFlowExecutionKey("x"));
    RequestContextHolder.setRequestContext(requestContext);
  }
View Full Code Here


  }

  public void testEnterEndStateTerminateFlowSession() {
    final Flow subflow = new Flow("mySubflow");
    EndState state = new EndState(subflow, "end");
    MockFlowSession session = new MockFlowSession(subflow);

    Flow parent = new Flow("parent");
    SubflowState subflowState = new SubflowState(parent, "subflow", new AbstractGetValueExpression() {
      public Object getValue(Object context) throws EvaluationException {
        return subflow;
      }
    });
    subflowState.getTransitionSet().add(new Transition(on("end"), to("end")));
    new EndState(parent, "end");

    MockFlowSession parentSession = new MockFlowSession(parent);
    parentSession.setState(subflowState);

    session.setParent(parentSession);
    MockRequestControlContext context = new MockRequestControlContext(new MockFlowExecutionContext(session));
    state.enter(context);
View Full Code Here

    hibernateListener = new HibernateFlowExecutionListener(sessionFactory, tm);
  }

  public void testSameSession() {
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    // Session created and bound to conversation
    final Session hibSession = (Session) flowSession.getScope().get("persistenceContext");
    assertNotNull("Should have been populated", hibSession);
    hibernateListener.paused(context);
    assertSessionNotBound();

    // Session bound to thread local variable
View Full Code Here

    assertSessionNotBound();
  }

  public void testFlowNotAPersistenceContext() {
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    hibernateListener.sessionStarting(context, flowSession, null);
    assertSessionNotBound();
  }
View Full Code Here

  }

  public void testFlowCommitsInSingleRequest() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean = new TestBean("Keith Donald");
    hibernateTemplate.save(bean);
    assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));

    EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
    endState.getAttributes().put("commit", true);
    flowSession.setState(endState);

    hibernateListener.sessionEnding(context, flowSession, "success", null);
    hibernateListener.sessionEnded(context, flowSession, "success", null);
    assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertSessionNotBound();
View Full Code Here

  }

  public void testFlowCommitsAfterMultipleRequests() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean1 = new TestBean("Keith Donald");
    hibernateTemplate.save(bean1);
    assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    hibernateListener.paused(context);
    assertSessionNotBound();

    hibernateListener.resuming(context);
    TestBean bean2 = new TestBean("Keith Donald");
    hibernateTemplate.save(bean2);
    assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertSessionBound();

    EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
    endState.getAttributes().put("commit", true);
    flowSession.setState(endState);

    hibernateListener.sessionEnding(context, flowSession, "success", null);
    hibernateListener.sessionEnded(context, flowSession, "success", null);
    assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));

View Full Code Here

  }

  public void testCancelEndState() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean = new TestBean("Keith Donald");
    hibernateTemplate.save(bean);
    assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));

    EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
    endState.getAttributes().put("commit", false);
    flowSession.setState(endState);
    hibernateListener.sessionEnding(context, flowSession, "success", null);
    hibernateListener.sessionEnded(context, flowSession, "cancel", null);
    assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertSessionNotBound();
  }
View Full Code Here

  }

  public void testNoCommitAttributeSetOnEndState() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
    flowSession.setState(endState);

    hibernateListener.sessionEnding(context, flowSession, "success", null);
    hibernateListener.sessionEnded(context, flowSession, "cancel", null);
    assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));

View Full Code Here

  }

  public void testExceptionThrown() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    hibernateListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean1 = new TestBean("Keith Donald");
View Full Code Here

  }

  public void testExceptionThrownWithNothingBound() {
    assertEquals("Table should only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    assertSessionNotBound();
    hibernateListener.exceptionThrown(context, new FlowExecutionException("foo", "bar", "test"));
    assertSessionNotBound();
  }
View Full Code Here

TOP

Related Classes of org.springframework.webflow.test.MockFlowSession

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.