Package org.springframework.webflow.test

Examples of org.springframework.webflow.test.MockRequestContext


  protected void setUp() throws Exception {
    action = createFormAction("test");
  }

  public void testSetupForm() throws Exception {
    MockRequestContext context = new MockRequestContext();

    // setupForm() should initialize the form object and the Errors
    // instance, but no bind & validate should happen since bindOnSetupForm
    // is not set

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertFalse(getErrors(context).hasErrors());
    assertNull(getFormObject(context).getProp());
  }
View Full Code Here


    map.put("prop", "");
    return map;
  }

  public void testSetupFormWithExistingFormObject() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    Errors errors = getErrors(context);
    errors.reject("dummy");
    TestBean formObject = getFormObject(context);
    formObject.setProp("bla");

    // setupForm() should leave the existing form object and Errors instance
    // untouched, at least when no bind & validate is done (bindOnSetupForm
    // == false)

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertSame(errors, getErrors(context));
    assertSame(formObject, getFormObject(context));
    assertTrue(getErrors(context).hasErrors());
    assertEquals("bla", getFormObject(context).getProp());
  }
View Full Code Here

    assertTrue(getErrors(context).hasErrors());
    assertEquals("bla", getFormObject(context).getProp());
  }

  public void testBindAndValidate() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());

    // bindAndValidate() should setup a new form object and errors instance
    // and do a bind & validate

    context.setAttribute("validatorMethod", "validateTestBean");
    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.bindAndValidate(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertFalse(getErrors(context).hasErrors());
    assertEquals("value", getFormObject(context).getProp());
  }
View Full Code Here

    assertFalse(getErrors(context).hasErrors());
    assertEquals("value", getFormObject(context).getProp());
  }

  public void testBindAndValidateFailure() throws Exception {
    MockRequestContext context = new MockRequestContext();

    // bindAndValidate() should setup a new form object and errors instance
    // and do a bind & validate, which fails because the provided value is
    // empty

    assertEquals(action.getEventFactorySupport().getErrorEventId(), action.bindAndValidate(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertTrue(getErrors(context).hasErrors());
    assertNull(getFormObject(context).getProp());
  }
View Full Code Here

    assertTrue(getErrors(context).hasErrors());
    assertNull(getFormObject(context).getProp());
  }

  public void testBindAndValidateWithExistingFormObject() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    Errors errors = getErrors(context);
    errors.reject("dummy");
    TestBean formObject = getFormObject(context);
    formObject.setProp("bla");

    // bindAndValidate() should leave the existing form object untouched
    // but should setup a new Errors instance during bind & validate

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.bindAndValidate(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertNotSame(errors, getErrors(context));
    assertSame(formObject, getFormObject(context));
    assertFalse(getErrors(context).hasErrors());
    assertEquals("value", getFormObject(context).getProp());
  }
View Full Code Here

    assertEquals("value", getFormObject(context).getProp());
  }

  // this is what happens in a 'form state'
  public void testBindAndValidateFailureThenSetupForm() throws Exception {
    MockRequestContext context = new MockRequestContext(blankParameters());

    // setup existing form object & errors
    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());
    TestBean formObject = getFormObject(context);
    formObject.setProp("bla");

    assertEquals(action.getEventFactorySupport().getErrorEventId(), action.bindAndValidate(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertSame(formObject, getFormObject(context));
    assertTrue(getErrors(context).hasErrors());
    assertEquals("", getFormObject(context).getProp());

    Errors errors = getErrors(context);

    // the setupForm() should leave the form object and error info setup by
    // the
    // bind & validate untouched

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    assertEquals(2, context.getRequestScope().size());
    assertEquals(2, context.getFlowScope().size());
    assertSame(errors, getErrors(context));
    assertSame(formObject, getFormObject(context));
    assertTrue(getErrors(context).hasErrors());
    assertEquals("", getFormObject(context).getProp());
  }
View Full Code Here

    assertTrue(getErrors(context).hasErrors());
    assertEquals("", getFormObject(context).getProp());
  }

  public void testMultipleFormObjectsInOneFlow() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());

    FormAction otherAction = createFormAction("otherTest");

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());
    assertEquals(action.getEventFactorySupport().getSuccessEventId(), otherAction.setupForm(context).getId());

    assertEquals(3, context.getRequestScope().size());
    assertEquals(3, context.getFlowScope().size());
    assertNotSame(getErrors(context), getErrors(context, "otherTest"));
    assertNotSame(getFormObject(context), getFormObject(context, "otherTest"));
    assertFalse(getErrors(context).hasErrors());
    assertFalse(getErrors(context, "otherTest").hasErrors());
    assertNull(getFormObject(context).getProp());
    assertNull(getFormObject(context, "otherTest").getProp());

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.bindAndValidate(context).getId());

    assertEquals(3, context.getRequestScope().size());
    assertEquals(3, context.getFlowScope().size());
    assertNotSame(getErrors(context), getErrors(context, "otherTest"));
    assertNotSame(getFormObject(context), getFormObject(context, "otherTest"));
    assertFalse(getErrors(context).hasErrors());
    assertFalse(getErrors(context, "otherTest").hasErrors());
    assertEquals("value", getFormObject(context).getProp());
    assertNull(getFormObject(context, "otherTest").getProp());

    context.setExternalContext(new MockExternalContext(blankParameters()));

    assertEquals(action.getEventFactorySupport().getErrorEventId(), otherAction.bindAndValidate(context).getId());

    assertEquals(3, context.getRequestScope().size());
    assertEquals(3, context.getFlowScope().size());
    assertNotSame(getErrors(context), getErrors(context, "otherTest"));
    assertNotSame(getFormObject(context), getFormObject(context, "otherTest"));
    assertFalse(getErrors(context).hasErrors());
    assertTrue(getErrors(context, "otherTest").hasErrors());
    assertEquals("value", getFormObject(context).getProp());
View Full Code Here

    assertEquals("value", getFormObject(context).getProp());
    assertEquals("", getFormObject(context, "otherTest").getProp());
  }

  public void testGetFormObject() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());
    FormAction action = createFormAction("test");
    TestBean formObject = (TestBean) action.getFormObject(context);
    assertNotNull(formObject);
    formObject = new TestBean();
    TestBean testBean = formObject;
View Full Code Here

    formObject = (TestBean) action.getFormObject(context);
    assertSame(formObject, testBean);
  }

  public void testGetFormErrors() throws Exception {
    MockRequestContext context = new MockRequestContext(parameters());
    FormAction action = createFormAction("test");
    action.setupForm(context);
    Errors errors = action.getFormErrors(context);
    assertNotNull(errors);
    assertTrue(!errors.hasErrors());
View Full Code Here

    errors = action.getFormErrors(context);
    assertSame(errors, testErrors);
  }

  public void testFormObjectAccessUsingAlias() throws Exception {
    MockRequestContext context = new MockRequestContext(blankParameters());

    FormAction otherAction = createFormAction("otherTest");

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), action.setupForm(context).getId());

    assertSame(getFormObject(context), new FormObjectAccessor(context).getCurrentFormObject());
    assertSame(getErrors(context), new FormObjectAccessor(context).getCurrentFormErrors());

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), otherAction.setupForm(context).getId());

    assertSame(getFormObject(context, "otherTest"), new FormObjectAccessor(context).getCurrentFormObject());
    assertSame(getErrors(context, "otherTest"), new FormObjectAccessor(context).getCurrentFormErrors());

    assertEquals(action.getEventFactorySupport().getErrorEventId(), action.bindAndValidate(context).getId());

    assertSame(getFormObject(context), new FormObjectAccessor(context).getCurrentFormObject());
    assertSame(getErrors(context), new FormObjectAccessor(context).getCurrentFormErrors());

    context.setExternalContext(new MockExternalContext(parameters()));

    assertEquals(action.getEventFactorySupport().getSuccessEventId(), otherAction.bindAndValidate(context).getId());

    assertSame(getFormObject(context, "otherTest"), new FormObjectAccessor(context).getCurrentFormObject());
    assertSame(getErrors(context, "otherTest"), new FormObjectAccessor(context).getCurrentFormErrors());
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.