Java 类org.springframework.validation.DirectFieldBindingResult 实例源码

项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate_invalidDate() {
    customerForm.setCustomerBirthYear(1997);
    customerForm.setCustomerBirthMonth(2);
    customerForm.setCustomerBirthDay(29);

    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(true));

    FieldError error = result.getFieldError("customerBirthYear");
    assertThat(error, is(notNullValue()));
    assertThat(error.getCode(), is("IncorrectDate.customerBirth"));
    assertThat(error.getDefaultMessage(), is("Incorrect date was entered."));
}
项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate() {
    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(false));
}
项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate_validLeapYear() {
    customerForm.setCustomerBirthYear(1996);
    customerForm.setCustomerBirthMonth(2);
    customerForm.setCustomerBirthDay(29);

    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(false));
}
项目:spanners    文件:SignupControllerTest.java   
@Test
public void testAccountCreation() {

    SignupForm form = populateForm(NAME, PASSWORD);
    Errors noErrors = new DirectFieldBindingResult(form, "form");

    controller.signup(form, noErrors);

    // Verify that the account was created for user
    verify(userDetailsManager).createUser(argThat(hasProperty("username", equalTo(NAME))));
}
项目:spanners    文件:SignupControllerTest.java   
/**
 * Verify that hashed password is saved to userDetailsManager
 */
@Test
public void testPasswordHash() {

    given(passwordEncoder.encode(PASSWORD)).willReturn(HASHED_PASSWORD);

    SignupForm form = populateForm(NAME, PASSWORD);
    Errors noErrors = new DirectFieldBindingResult(form, "form");

    controller.signup(form, noErrors);

    // Verify that the hashed password was passed to the userDetailsManager
    verify(userDetailsManager).createUser(argThat(hasProperty("password", equalTo(HASHED_PASSWORD))));
}
项目:spanners    文件:SignupControllerTest.java   
@Test
public void testValidationFailIsLogged() {
    SignupForm invalidForm = populateForm(null, null);
    Errors errors = new DirectFieldBindingResult(invalidForm, "form");
    errors.rejectValue("name", "Invalid name");
    errors.rejectValue("password", "Invalid password");

    controller.signup(invalidForm, errors);

    assertThat(sysOut.asString(), containsString("Oh no!"));
}
项目:spanners    文件:SignupControllerTest.java   
@Test
public void testSuccessIsLogged() {
    SignupForm form = populateForm(NAME, PASSWORD);
    Errors noErrors = new DirectFieldBindingResult(form, "form");

    controller.signup(form, noErrors);

    assertThat(sysOut.asString(), containsString("Success!"));
}
项目:kansalaisaloite    文件:EmailsTest.java   
private static DirectFieldBindingResult emailValidationErrors(FollowInitiativeDto followInitiativeDto) {
    return new DirectFieldBindingResult(followInitiativeDto, "email");
}
项目:kansalaisaloite    文件:FollowServiceTest.java   
private static DirectFieldBindingResult emailValidationErrors(FollowInitiativeDto followInitiativeDto) {
    return new DirectFieldBindingResult(followInitiativeDto, "email");
}
项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate_invalidPasswordConfirm() {
    customerForm.setCustomerPassConfirm("invalidPassword");

    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(true));

    assertCustomerPassError(result.getFieldError("customerPass"));
}
项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate_nullPassword() {
    customerForm.setCustomerPass(null);

    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(true));

    assertCustomerPassError(result.getFieldError("customerPass"));
}
项目:springboot-tourreservation    文件:CustomerFormValidatorTest.java   
@Test
public void testValidate_nullPasswordConfirm() {
    customerForm.setCustomerPassConfirm(null);

    BindingResult result = new DirectFieldBindingResult(customerForm, "customerForm");

    customerFormValidator.validate(customerForm, result);

    assertThat(result.hasErrors(), is(true));

    assertCustomerPassError(result.getFieldError("customerPass"));
}
项目:spanners    文件:SignupControllerTest.java   
@Test
public void testSuccessForward() {

    SignupForm form = populateForm(NAME, PASSWORD);
    Errors noErrors = new DirectFieldBindingResult(form, "form");

    String response = controller.signup(form, noErrors);

    assertEquals(SignupController.VIEW_SUCCESS, response);
}