List of usage examples for org.springframework.validation FieldError isBindingFailure
public boolean isBindingFailure()
From source file:org.tonguetied.web.BundleValidatorTest.java
/** * Test method for {@link org.tonguetied.web.BundleValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *//* w w w .ja v a2 s .c om*/ @Test public final void testValidateInvalidObject() { BundleValidator validator = new BundleValidator(); validator.setKeywordService(keywordService); Errors errors = new BindException(this.bundle, "bundle"); validator.validate(this.bundle, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_NAME.equals(fieldName)) { assertEquals(this.bundle.getName(), error.getRejectedValue()); } else if (FIELD_RESOURCE_NAME.equals(fieldName)) { assertEquals(this.bundle.getResourceName(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.AccountFormValidatorTest.java
/** * Test method for// w ww . ja va 2 s . c om * {@link org.tonguetied.web.AccountFormValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. */ @Test public final void testValidateInvalidObject() { AccountFormValidator validator = new AccountFormValidator(); Errors errors = new BindException(this.user, "user"); validator.validate(this.user, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_FIRSTNAME.equals(fieldName)) { assertEquals(this.user.getFirstName(), error.getRejectedValue()); } if (FIELD_LASTNAME.equals(fieldName)) { assertEquals(this.user.getLastName(), error.getRejectedValue()); } if (FIELD_EMAIL.equals(fieldName)) { assertEquals(this.user.getEmail(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.KeywordValidatorTest.java
/** * Test method for {@link org.tonguetied.web.KeywordValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. */// w ww . j a v a2 s . c o m @Test public final void testValidate() { KeywordValidator validator = new KeywordValidator(); validator.setKeywordService(keywordService); Errors errors = new BindException(this.keyword, "keyword"); validator.validate(this.keyword, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_KEYWORD.equals(fieldName)) { assertEquals(this.keyword.getKeyword(), error.getRejectedValue()); } else if (FIELD_TRANSLATIONS.equals(fieldName)) { assertEquals(this.keyword.getTranslations(), error.getRejectedValue()); assertEquals(1, errors.getErrorCount()); } else { fail("cannot match error field"); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.ImportValidatorTest.java
/** * Test method for//from www .j ava2 s . com * {@link org.tonguetied.web.ImportValidator#validate(Object, Errors)}. */ @Test public final void testValidateInvalidObject() { ImportValidator validator = new ImportValidator(); Errors errors = new BindException(this.importBean, "importBean"); validator.validate(this.importBean, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_FORMAT_TYPE.equals(fieldName)) { assertEquals(this.importBean.getParameters().getFormatType(), error.getRejectedValue()); } if (FIELD_TRANSLATION_STATE.equals(fieldName)) { assertEquals(this.importBean.getParameters().getTranslationState(), error.getRejectedValue()); } if (FIELD_FILE_NAME.equals(fieldName)) { assertEquals(this.importBean.getFileUploadBean().getFile().getName(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.ExportParametersValidatorTest.java
/** * Test method for {@link org.tonguetied.web.ExportParametersValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *//*from www . j a va2s. co m*/ @Test public void testValidate() { ExportParametersValidator validator = new ExportParametersValidator(); Errors errors = new BindException(this.parameters, "parameters"); validator.validate(parameters, errors); assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_BUNDLES.equals(fieldName)) { assertEquals(this.parameters.getBundles(), error.getRejectedValue()); } else if (FIELD_COUNTRIES.equals(fieldName)) { assertEquals(this.parameters.getCountries(), error.getRejectedValue()); } else if (FIELD_LANGUAGES.equals(fieldName)) { assertEquals(this.parameters.getLanguages(), error.getRejectedValue()); } else if (FIELD_FORMAT_TYPE.equals(fieldName)) { assertEquals(this.parameters.getFormatType(), error.getRejectedValue()); } else if (FIELD_TRANSLATION_STATE.equals(fieldName)) { assertEquals(this.parameters.getTranslationState(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); }
From source file:org.tonguetied.web.UserValidatorTest.java
/** * Test method for {@link org.tonguetied.web.UserValidator#validate(java.lang.Object, org.springframework.validation.Errors)}. *//*w ww . j a va2s . c om*/ @Test public final void testValidateInvalidObject() { UserValidator validator = new UserValidator(); validator.setUserService(userService); Errors errors = new BindException(this.userForm, "userForm"); validator.validate(this.userForm, errors); if (fieldName == null) { assertTrue(errors.getAllErrors().isEmpty()); } else { assertFalse(errors.getAllErrors().isEmpty()); FieldError error = errors.getFieldError(fieldName); if (FIELD_USER_USERNAME.equals(fieldName)) { assertEquals(this.userForm.getUser().getUsername(), error.getRejectedValue()); } if (FIELD_USER_FIRSTNAME.equals(fieldName)) { assertEquals(this.userForm.getUser().getFirstName(), error.getRejectedValue()); } if (FIELD_USER_LASTNAME.equals(fieldName)) { assertEquals(this.userForm.getUser().getLastName(), error.getRejectedValue()); } if (FIELD_USER_EMAIL.equals(fieldName)) { assertEquals(this.userForm.getUser().getEmail(), error.getRejectedValue()); } if (FIELD_USER_PASSWORD.equals(fieldName)) { assertEquals(this.userForm.getUser().getPassword(), error.getRejectedValue()); } if (FIELD_USER_REPEATED_PASSWORD.equals(fieldName)) { assertEquals(this.userForm.getUser().getRepeatedPassword(), error.getRejectedValue()); } assertFalse(error.isBindingFailure()); } }