Package javax.validation

Examples of javax.validation.Validator.validateValue()


  @SpecAssertion(section = "4.1.1", id = "i")
  public void testValidateValuePassingNullAsGroup() {
    Validator validator = TestUtil.getValidatorUnderTest();

    try {
      validator.validateValue( Customer.class, "firstName", "foobar", null );
      fail();
    }
    catch ( IllegalArgumentException e ) {
      // success
    }
View Full Code Here


  @SpecAssertion(section = "4.1.1", id = "i")
  public void testValidateValueWithEmptyPropertyPath() {
    Validator validator = TestUtil.getValidatorUnderTest();

    try {
      validator.validateValue( Customer.class, "", null );
      fail();
    }
    catch ( IllegalArgumentException e ) {
      // success
    }
View Full Code Here

  @Test
  @SpecAssertion(section = "4.1.1", id = "i")
  public void testValidateValueWithNullObject() {
    Validator validator = TestUtil.getValidatorUnderTest();
    try {
      validator.validateValue( null, "firstName", "foobar" );
      fail();
    }
    catch ( IllegalArgumentException e ) {
      // success
    }
View Full Code Here

  @Test
  @SpecAssertion(section = "4.1.1", id = "i")
  public void testValidateValueWithNullPropertyName() {
    Validator validator = TestUtil.getValidatorUnderTest();
    try {
      validator.validateValue( Customer.class, null, "foobar" );
      fail();
    }
    catch ( IllegalArgumentException e ) {
      // success
    }
View Full Code Here

    Customer customer = new Customer();
    Order order = new Order();
    customer.addOrder( order );

    Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
        Customer.class, "orders", order
    );
    assertCorrectNumberOfViolations( constraintViolations, 0 );
  }
}
View Full Code Here

    Property property = getProperty();

    // validate the value using the bean validator

    Set<?> violations = validator.validateValue(property.getOwner(), property.getName(),
      validatable.getValue(), getGroups());

    // iterate over violations and report them

    for (ConstraintViolation<?> violation : (Set<ConstraintViolation<?>>)violations)
View Full Code Here

          // Se houver um validador anexado à propriedade alterada, executa o validador sobre
          // o novo valor.
          Validator validator = getDefaultValidator();
          if (validator != null) {
            Set<?> violations = validator.validateValue(managedType.getType(), propertyName, newValue);
            if (violations.size() > 0) {
              StringBuffer errorBuffer = new StringBuffer();
              for (Object objectViolation : violations) {
                ConstraintViolation<?> violation = (ConstraintViolation<?>) objectViolation;
                errorBuffer.append(violation.getMessage()).append('\r').append('\n');
View Full Code Here

    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "Car type has to be between 2 and 20 characters."
    );

    constraintViolations = validator.validateValue( Car.class, "type", "A" );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "Car type has to be between 2 and 20 characters."
    );
  }
View Full Code Here

        BoundariesConstraintValidator.isValidCalls > nbrOfValidCalls,
        "Ensure is valid has been called."
    );
    nbrOfValidCalls = BoundariesConstraintValidator.isValidCalls;

    validator.validateValue( Shoe.class, "size", 41 );
    assertTrue(
        BoundariesConstraintValidator.isValidCalls > nbrOfValidCalls,
        "Ensure is valid has been called."
    );
  }
View Full Code Here

  @Test
  @SpecAssertion(section = "4.1.1", id = "h")
  public void testValidateValueSuccess() {
    Validator validator = TestUtil.getValidatorUnderTest();

    Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue(
        Address.class, "city", "Paris"
    );
    assertCorrectNumberOfViolations( constraintViolations, 0 );
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.