Package org.springframework.validation

Examples of org.springframework.validation.Errors


    }

    @Test
    public void testValidationFailsOnEmptyValues() {
        Widget widget = new WidgetImpl();
        Errors errors = new BindException(widget, WIDGET);

        widgetValidator.validate(widget, errors);

        assertEquals(4, errors.getErrorCount());
    }
View Full Code Here


        Widget newWidget = new WidgetImpl();
        newWidget.setTitle(VALID_TITLE);
        newWidget.setType(VALID_TYPE);
        newWidget.setDescription(VALID_DESCRIPTION);
        newWidget.setUrl(existingUrl);
        Errors errors = new BindException(newWidget, WIDGET);

        expect(widgetService.isRegisteredUrl(existingUrl)).andReturn(true);
        replay(widgetService);

        widgetValidator.validate(newWidget, errors);
        verify(widgetService);
        assertEquals(1, errors.getErrorCount());
        assertNotNull("Field error for duplicate url", errors.getFieldError("url"));
    }
View Full Code Here

        widget.setUrl("http:/this.is/invalid?url=true&reject=true");
        widget.setScreenshotUrl("https://///invalid/screenshot");
        widget.setThumbnailUrl("thumbnail");
        widget.setTitleUrl("titleUrl");
        widget.setDescription(VALID_DESCRIPTION);
        Errors errors = new BindException(widget, WIDGET);

        widgetValidator.validate(widget, errors);
        assertEquals(4, errors.getErrorCount());
        assertNotNull("Field error on url", errors.getFieldError("url"));
        assertNotNull("Field error on screenshot url", errors.getFieldError("screenshotUrl"));
        assertNotNull("Field error on thumbnail url", errors.getFieldError("thumbnailUrl"));
        assertNotNull("Field error on title url", errors.getFieldError("titleUrl"));
    }
View Full Code Here

    public void testValidateValidFormData() throws Exception {
        Widget widget = new Widget();
        widget.setTitle(VALID_TITLE);
        widget.setUrl(VALID_URL);
        widget.setType(VALID_TYPE);
        Errors errors = new BindException(widget, WIDGET);

        newWidgetValidator.validate(widget, errors);
        assertFalse("No validation errors", errors.hasErrors());
    }
View Full Code Here

    }

    @Test
    public void testValidationFailsOnEmptyValues() {
        Widget widget = new Widget();
        Errors errors = new BindException(widget, WIDGET);

        newWidgetValidator.validate(widget, errors);

        assertEquals(3, errors.getErrorCount());
    }
View Full Code Here

        widget.setTitle(VALID_TITLE);
        widget.setType(VALID_TYPE);
        widget.setUrl("http:/this.is/invalid?url=true&reject=true");
        widget.setScreenshotUrl("https://///invalid/screenshot");
        widget.setThumbnailUrl("thumbnail");
        Errors errors = new BindException(widget, WIDGET);

        newWidgetValidator.validate(widget, errors);
        assertEquals(3, errors.getErrorCount());
        assertNotNull("Field error on url", errors.getFieldError("url"));
        assertNotNull("Field error on screenshot url", errors.getFieldError("screenshotUrl"));
        assertNotNull("Field error on thumbnail url", errors.getFieldError("thumbnailUrl"));
    }
View Full Code Here

   */
  public Errors getErrors(String name, boolean htmlEscape) {
    if (this.errorsMap == null) {
      this.errorsMap = new HashMap();
    }
    Errors errors = (Errors) this.errorsMap.get(name);
    boolean put = false;
    if (errors == null) {
      errors = (Errors) getModelObject(BindingResult.MODEL_KEY_PREFIX + name);
      // Check old BindException prefix for backwards compatibility.
      if (errors == null) {
View Full Code Here

    // use a FormAction to do the binding
    FormAction formAction = new FormAction();
    formAction.setFormObjectClass(TestBean.class);
    formAction.setFormObjectName("formObject");
    formAction.execute(context);
    Errors formActionErrors = new FormObjectAccessor(context).getCurrentFormErrors(formAction.getFormErrorsScope());
    assertNotNull(formActionErrors);
    assertTrue(formActionErrors.hasErrors());

    assertEquals(1, formActionErrors.getErrorCount());
    assertEquals(0, formActionErrors.getGlobalErrorCount());
    assertEquals(1, formActionErrors.getFieldErrorCount("prop"));
  }
View Full Code Here

    MockRequestContext context = new MockRequestContext();

    context.setAttribute("method", "setupForm");
    formAction.execute(context);
    Errors errors = new FormObjectAccessor(context).getFormErrors("formObject", ScopeType.FLASH);
    assertNotNull(errors);
    assertEquals(new Long(-1), errors.getFieldValue("prop"));

    // this fails because of SWF-193
    assertEquals("initialValue", errors.getFieldValue("otherProp"));

    context.putRequestParameter("prop", "1");
    context.putRequestParameter("otherProp", "value");
    context.setAttribute("method", "bind");
    formAction.execute(context);

    TestBean formObject = (TestBean) new FormObjectAccessor(context).getFormObject("formObject", ScopeType.FLOW);
    errors = new FormObjectAccessor(context).getFormErrors("formObject", ScopeType.FLASH);
    assertNotNull(formObject);
    assertEquals(new Long(1), formObject.getProp());
    assertEquals(new Long(1), errors.getFieldValue("prop"));
    assertEquals("value", formObject.otherProp);
    assertEquals("value", errors.getFieldValue("otherProp"));
  }
View Full Code Here

  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
View Full Code Here

TOP

Related Classes of org.springframework.validation.Errors

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.