Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockRequestContext


  private boolean renderCalled;

  private Map model;

  public void testRender() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.getRequestScope().put("foo", "bar");
    context.getFlowScope().put("bar", "baz");
    context.getFlowScope().put("bindBean", new BindBean());
    context.getConversationScope().put("baz", "boop");
    context.getFlashScope().put("boop", "bing");
    context.getMockExternalContext().setCurrentUser("Keith");
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new ServletMvcView(mvcView, context);
    view.render();
    assertTrue(renderCalled);
    assertEquals("bar", model.get("foo"));
View Full Code Here


    assertEquals(cal.getTime(), bindBean.getDateProperty());
    assertEquals(null, bindBean.getBeanProperty().getName());
  }

  public void testResumeEventModelBindingFieldMarker() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("_booleanProperty", "whatever");
    BindBean bindBean = new BindBean();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    HashSet allowedBindFields = new HashSet();
    allowedBindFields.add("booleanProperty");
View Full Code Here

    view.processUserEvent();
    assertEquals(false, bindBean.getBooleanProperty());
  }

  public void testResumeEventModelBindingFieldMarkerFieldPresent() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("booleanProperty", "true");
    context.putRequestParameter("_booleanProperty", "whatever");
    BindBean bindBean = new BindBean();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    view.processUserEvent();
    assertEquals(true, bindBean.getBooleanProperty());
View Full Code Here

    view.processUserEvent();
    assertEquals(true, bindBean.getBooleanProperty());
  }

  public void testResumeEventModelBindAndValidate() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("stringProperty", "foo");
    context.putRequestParameter("integerProperty", "5");
    context.putRequestParameter("dateProperty", "2007-01-01");
    BindBean bindBean = new ValidatingBindBean();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    view.processUserEvent();
    assertTrue(view.hasFlowEvent());
View Full Code Here

    assertEquals("submit", view.getFlowEvent().getId());
    assertTrue(bindBean.validationMethodInvoked);
  }

  public void testResumeEventModelBindAndValidateDefaultValidatorFallback() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("stringProperty", "foo");
    context.putRequestParameter("integerProperty", "5");
    context.putRequestParameter("dateProperty", "2007-01-01");
    BindBean bindBean = new ValidatingBindBeanFallback();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    view.processUserEvent();
    assertTrue(view.hasFlowEvent());
View Full Code Here

    assertEquals("submit", view.getFlowEvent().getId());
    assertTrue(bindBean.validationMethodInvoked);
  }

  public void testResumeEventModelValidateOnBindingErrors() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("stringProperty", "foo");
    context.putRequestParameter("integerProperty", "bogus");
    context.putRequestParameter("dateProperty", "2007-01-01");
    BindBean bindBean = new ValidatingBindBean();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    view.processUserEvent();
    assertFalse(view.hasFlowEvent());
View Full Code Here

    assertFalse(view.hasFlowEvent());
    assertTrue(bindBean.validationMethodInvoked);
  }

  public void testResumeEventModelNoValidateOnBindingErrors() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.putRequestParameter("_eventId", "submit");
    context.putRequestParameter("stringProperty", "foo");
    context.putRequestParameter("integerProperty", "bogus");
    context.putRequestParameter("dateProperty", "2007-01-01");
    BindBean bindBean = new ValidatingBindBean();
    StaticExpression modelObject = new StaticExpression(bindBean);
    modelObject.setExpressionString("bindBean");
    context.getMockFlowExecutionContext().putAttribute("validateOnBindingErrors", Boolean.FALSE);
    context.getCurrentState().getAttributes().put("model", modelObject);
    context.getFlowScope().put("bindBean", bindBean);
    context.getMockExternalContext().setNativeContext(new MockServletContext());
    context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest());
    context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse());
    context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1"));
    org.springframework.web.servlet.View mvcView = new MockView();
    AbstractMvcView view = new MockMvcView(mvcView, context);
    view.setExpressionParser(DefaultExpressionParserFactory.getExpressionParser());
    view.processUserEvent();
    assertFalse(view.hasFlowEvent());
View Full Code Here

public class SetActionTests extends TestCase {
  public void testSetAction() throws Exception {
    StaticExpression name = new StaticExpression("");
    SetAction action = new SetAction(name, new StaticExpression("bar"), null, null);
    MockRequestContext context = new MockRequestContext();
    Event result = action.execute(context);
    assertEquals("success", result.getId());
    assertEquals("bar", name.getValue(null));
  }
View Full Code Here

  }

  public void testSetActionWithTypeConversion() throws Exception {
    StaticExpression name = new StaticExpression("");
    SetAction action = new SetAction(name, new StaticExpression("3"), Integer.class, new DefaultConversionService());
    MockRequestContext context = new MockRequestContext();
    Event result = action.execute(context);
    assertEquals("success", result.getId());
    assertEquals(new Integer(3), name.getValue(null));
  }
View Full Code Here

    jpaListener = new JpaFlowExecutionListener(entityManagerFactory, tm);
    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.MockRequestContext

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.