Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockFlowSession


  }

  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");
    jpaListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean = new TestBean(1, "Keith Donald");
    EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    em.persist(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);
    jpaListener.sessionEnding(context, flowSession, "cancel", null);
    jpaListener.sessionEnded(context, flowSession, "success", 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");
    jpaListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

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

    jpaListener.sessionEnding(context, flowSession, "cancel", null);
    jpaListener.sessionEnded(context, flowSession, "success", 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");
    jpaListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

    TestBean bean = new TestBean(1, "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();
    jpaListener.exceptionThrown(context, new FlowExecutionException("foo", "bar", "test"));
    assertSessionNotBound();
  }
View Full Code Here

    }
  }

  public void testDispatchWithCurrentStateId() throws Exception {
    MockFlowSession session = context.getMockFlowExecutionContext().getMockActiveSession();
    session.setState(new ViewState(session.getDefinitionInternal(), "increment", new StubViewFactory()));
    action.execute(context);
    assertEquals(1, action.counter);
  }
View Full Code Here

    populateDataBase(dataSource);
    setUpResources(dataSource);
  }

  public void testSessionStarting_NoPc_ParentPc() {
    MockFlowSession parentSession = newFlowSession(true, null);
    MockFlowSession childSession = newFlowSession(false, parentSession);

    getListener().sessionStarting(new MockRequestContext(), parentSession, null);
    assertSessionBound();
    assertSessionInScope(parentSession);
View Full Code Here

    assertSessionNotBound();
    assertSessionNotInScope(childSession);
  }

  public void testSessionStarting_Pc_ParentPc() {
    MockFlowSession parentSession = newFlowSession(true, null);
    MockFlowSession childSession = newFlowSession(true, parentSession);

    getListener().sessionStarting(new MockRequestContext(), parentSession, null);
    assertSessionBound();
    assertSessionInScope(parentSession);

    getListener().sessionStarting(new MockRequestContext(), childSession, null);
    assertSessionBound();
    assertSessionInScope(childSession);
    assertSame("Parent PersistenceContext should be re-used", parentSession.getScope().get("persistenceContext"),
        childSession.getScope().get("persistenceContext"));
  }
View Full Code Here

    assertSame("Parent PersistenceContext should be re-used", parentSession.getScope().get("persistenceContext"),
        childSession.getScope().get("persistenceContext"));
  }

  public void testSessionEnd_Pc_NoParentPc() {
    MockFlowSession parentSession = newFlowSession(false, null);
    MockFlowSession childSession = newFlowSession(true, parentSession);

    getListener().sessionStarting(requestContext, parentSession, null);
    getListener().sessionStarting(requestContext, childSession, null);

    assertCommitState(true, false);
View Full Code Here

    assertSessionNotBound();
    assertCommitState(false, true);
  }

  public void testSessionEnd_Pc_ParentPc() {
    MockFlowSession parentSession = newFlowSession(true, null);
    MockFlowSession childSession = newFlowSession(true, parentSession);

    getListener().sessionStarting(requestContext, parentSession, null);
    getListener().sessionStarting(requestContext, childSession, null);

    assertCommitState(true, false);
View Full Code Here

    getListener().sessionEnded(requestContext, childSession, "success", null);
    assertSessionBound();
  }

  private MockFlowSession newFlowSession(boolean persistenceContext, FlowSession parent) {
    MockFlowSession flowSession = new MockFlowSession();
    flowSession.setParent(parent);
    if (persistenceContext) {
      flowSession.getDefinition().getAttributes().put("persistenceContext", "true");
    }
    EndState endState = new EndState(flowSession.getDefinitionInternal(), "success");
    endState.getAttributes().put("commit", true);
    flowSession.setState(endState);
    return flowSession;
  }
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.