Spring Framework BindException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework BindException class.

This code example shows how to use the following methods:getFieldErrorCount, getGlobalErrorCount
        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");
 
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);
 
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals(3, errors.getFieldErrorCount());
 
    } 
 
    public void testLoadConfiguration_WithCustomHandlerFailure() throws Exception {
 
        AnnotatedPerson person = new AnnotatedPerson();
        person.setFirstName("Uri");
        person.setLastName("boness");
        person.setAge(-1);
        person.setEmail("uri@b");
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getGlobalError, getGlobalErrorCount, hasGlobalErrors
 
        validator.setErrorCodeConverter(new DefaultErrorCodeConverter());
        validator.setConfigurationLoader(loader);
 
        Person person = new Person("Uri");
        BindException errors = new BindException(person, "person");
 
        validator.validate(person, errors);
 
        assertTrue(errors.hasGlobalErrors());
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals("Person[bad]", errors.getGlobalError().getCode());
    } 
 
    public void testBeanValidator_WithCustomValangFunctions2() throws Exception {
 
        Map functionsByName = new HashMap();
        functionsByName.put("tupper", UpperCaseFunction.class.getName());
 
        ValangConditionExpressionParser conditionExpressionParser = new ValangConditionExpressionParser();
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getFieldErrorCount, getGlobalErrorCount
        person.setAge(-1);
        person.setEmail("uri@b");
        person.setPassword("pa");
        person.setConfirmPassword("pa1");
 
        BindException errors = new BindException(person, "person");
        validator.validate(person, errors);
 
        assertEquals(1, errors.getGlobalErrorCount());
        assertEquals(3, errors.getFieldErrorCount());
 
    } 
 
    public void testLoadConfiguration_WithCustomHandlerFailure() throws Exception {
 
        Person person = new Person();
        person.setFirstName("Uri");
        person.setLastName("boness");
        person.setAge(-1);
        person.setEmail("uri@b");
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:hasFieldErrors
	@Verifies(value = "fail validation if name field length is too long", method = "validateFieldLengths(org.springframework.validation.Errors, Class, String...)") 
	public void validateFieldLength_shouldRejectValueWhenNameIsToLong() { 
		PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
		patientIdentifierType.setName("asdfghjkl asdfghjkl asdfghjkl asdfghjkl asdfghjkl xx");
		 
		BindException errors = new BindException(patientIdentifierType, "patientIdentifierType");
		ValidateUtil.validateFieldLengths(errors, PatientIdentifierType.class, "name");
		assertTrue(errors.hasFieldErrors("name"));
	} 
	 
	/** 
	 * @see {@link ValidateUtil#validateFieldLengths(org.springframework.validation.Errors, Class, String...)} 
	 */ 
	@Test
	@Verifies(value = "pass validation if name field length is equal to maximum length", method = "validateFieldLengths(org.springframework.validation.Errors, Class, String...)") 
	public void validateFieldLength_shouldNotRejectValueWhenNameIsEqualMax() { 
		PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
		patientIdentifierType.setName("asdfghjkl asdfghjkl asdfghjkl asdfghjkl asdfghjkl ");
		 
		BindException errors = new BindException(patientIdentifierType, "patientIdentifierType");
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:hasFieldErrors
        validator.validate(bean, errors);
        assertTrue(errors.hasFieldErrors("name"));
        assertEquals(1, errors.getErrorCount());
        assertEquals("name", ((FieldError) errors.getAllErrors().iterator().next()).getField());
 
        errors = new BindException(bean, "pagedFooBean");
        bean.setName("name");
        validator.validate(bean, errors);
        assertFalse(errors.hasFieldErrors("name"));
    } 
 
    public void testValidate() { 
        FooBean bean = new FooBean();
 
        MockControl ctl = MockControl.createControl(ValidatorFactory.class);
        ValidatorFactory factory = (ValidatorFactory) ctl.getMock();
 
        // expect call to get validator with args "fooBean", bean and null 
        factory.getValidator("fooBean", bean, null);
        ctl.setReturnValue(getCommonsValidator());
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getGlobalError, hasErrors
	 */ 
	@Test
	@Verifies(value = "display an error message when the password and confirm password entries are different", method = "handleSubmission()") 
	public void handleSubmission_shouldDisplayErrorMessageWhenPasswordAndConfirmPasswordAreNotSame() throws Exception {
		ChangePasswordFormController controller = new ChangePasswordFormController();
		BindException errors = new BindException(controller.formBackingObject(), "user");
		 
		String result = controller.handleSubmission(new MockHttpSession(), "password", "differentPassword", "", "", "",
		    Context.getAuthenticatedUser(), errors);
		 
		assertTrue(errors.hasErrors());
		assertEquals("error.password.match", errors.getGlobalError().getCode());
	} 
	 
	/** 
	 * @see {@link ChangePasswordFormController#handleSubmission(HttpSession, String, String, String, String, String, User, BindingResult)} 
	 */ 
	@Test
	@Verifies(value = "not display error message if password and confirm password are the same", method = "handleSubmission()") 
	public void handleSubmission_shouldRedirectToIndexPageWhenPasswordAndConfirmPasswordAreTheSame() throws Exception {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:hasFieldErrors
        assertTrue(errors.hasFieldErrors("name"));
        assertTrue(errors.hasFieldErrors("name"));
        assertEquals(1, errors.getErrorCount());
        assertEquals("name", ((FieldError) errors.getAllErrors().iterator().next()).getField());
 
        errors = new BindException(bean, "pagedFooBean");
        bean.setName("name");
        validator.validate(bean, errors);
        assertFalse(errors.hasFieldErrors("name"));
    } 
 
    public void testValidate() { 
        FooBean bean = new FooBean();
        String formName = "myForm";
 
        MockControl ctl = MockControl.createControl(ValidatorFactory.class);
        ValidatorFactory factory = (ValidatorFactory) ctl.getMock();
 
        // expect call to get validator with args "fooBean", bean and null 
        factory.getValidator(formName, bean, null);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getErrorCount
		EncounterRoleFormController controller = new EncounterRoleFormController(); 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
		HttpSession session = request.getSession(); 
		EncounterRole encounterRole = new EncounterRole(); 
		encounterRole.setDescription("person in charge"); 
		BindException errors = new BindException(encounterRole, "encounterRole"); 
		controller.save(session, encounterRole, errors); 
		Assert.assertNull(encounterRole.getId()); 
		Assert.assertEquals(1, errors.getErrorCount()); 
	} 
	 
	/** 
	 * @verifies edit and save an existing encounter 
	 * @see EncounterRoleFormController#save(javax.servlet.http.HttpSession, org.openmrs.EncounterRole, org.springframework.validation.BindingResult) 
	 */ 
	@Test 
	public void saveEncounterRole_shouldEditAndSaveAnExistingEncounter() throws Exception { 
		executeDataSet(ENC_INITIAL_DATA_XML); 
		EncounterRoleFormController controller = new EncounterRoleFormController(); 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		UserFormController controller = new UserFormController(); 
		WebRequest request = new ServletWebRequest(new MockHttpServletRequest()); 
		User user = controller.formBackingObject(request, null); 
		user.addName(new PersonName("This", "is", "Test")); 
		user.getPerson().setGender("F"); 
		controller.handleSubmission(request, new MockHttpSession(), new ModelMap(), "Save User", "pass123", "pass123", null, 
		    null, null, new String[0], "true", user, new BindException(user, "user")); 
	} 
	 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:hasErrors
	public void validate_shouldPassValidationIfAllRequiredValuesAreSet() throws Exception {
		attributeType.setName("name");
		attributeType.setMinOccurs(1);
		attributeType.setDatatypeClassname(RegexValidatedTextDatatype.class.getName());
		attributeType.setDatatypeConfig("[a-z]+");
		validator.validate(attributeType, errors);
		Assert.assertFalse(errors.hasErrors());
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework BindException Methods: