Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockFlowSession


  }

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

    TestBean bean = new TestBean(1, "Keith Donald");
    jpaTemplate.persist(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);

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

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

    jpaListener.resuming(context);
    TestBean bean2 = new TestBean(2, "Keith Donald");
    jpaTemplate.persist(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);

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

    TestBean bean = new TestBean(1, "Keith Donald");
    jpaTemplate.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", Boolean.FALSE);
    flowSession.setState(endState);
    jpaListener.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");
    jpaListener.sessionStarting(context, flowSession, null);
    context.setActiveSession(flowSession);
    assertSessionBound();

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

    jpaListener.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");
    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 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

    jpaListener = new JpaFlowExecutionListener(entityManagerFactory, tm);
  }

  public void testFlowNotAPersistenceContext() {
    MockRequestContext context = new MockRequestContext();
    MockFlowSession flowSession = new MockFlowSession();
    jpaListener.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");
    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(), "success");
    endState.getAttributes().put("commit", true);
    flowSession.setState(endState);

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

    TestBean bean1 = new TestBean(1, "Keith Donald");
    EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    em.persist(bean1);
    assertEquals("Table should still only have one row", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
    jpaListener.paused(context);
    assertSessionNotBound();

    jpaListener.resuming(context);
    TestBean bean2 = new TestBean(2, "Keith Donald");
    em = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
    em.persist(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);

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

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.