Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockFlowSession


    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", Boolean.TRUE);
    flowSession.setState(endState);

    hibernateListener.sessionEnded(context, flowSession, "success", null);
    assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertSessionNotBound();
    assertFalse(flowSession.getScope().contains("hibernate.session"));
  }
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", Boolean.TRUE);
    flowSession.setState(endState);

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

    assertSessionNotBound();
    assertFalse(flowSession.getScope().contains("hibernate.session"));

  }
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", Boolean.FALSE);
    flowSession.setState(endState);
    hibernateListener.sessionEnded(context, flowSession, "cancel", null);
    assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertSessionNotBound();
    assertFalse(flowSession.getScope().contains("hibernate.session"));
  }
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.sessionEnded(context, flowSession, "cancel", null);
    assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    assertFalse(flowSession.getScope().contains("hibernate.session"));

    assertSessionNotBound();
    assertFalse(flowSession.getScope().contains("hibernate.session"));
  }
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

    assertSessionNotBound();
  }

  public void testLazyInitializedCollection() {
    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 = (TestBean) hibernateTemplate.get(TestBean.class, Long.valueOf(0));
View Full Code Here

    jpaTemplate = new JpaTemplate(entityManagerFactory);
  }

  public void testFlowNotAPersistenceContext() {
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    jpaListener.sessionStarting(context, flowSession, null);
    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.