Package org.hibernate.validator.constraints

Examples of org.hibernate.validator.constraints.Length


      required = true;
    }

    // determine max length
    int maxlen = -1;
    final Length aLength = m.getAnnotation(Length.class);
    if(aLength != null) {
      maxlen = aLength.max();
    }
    else {
      // try Size anno
      final Size aSize = m.getAnnotation(Size.class);
      if(aSize != null) {
View Full Code Here


      required = true;
    }

    // determine max length
    int maxlen = -1;
    final Length aLength = m.getAnnotation(Length.class);
    if(aLength != null) {
      maxlen = aLength.max();
    }
    else {
      // try Size anno
      final Size aSize = m.getAnnotation(Size.class);
      if(aSize != null) {
View Full Code Here

       
    }
   
    public int getMaxLength(final String propertyName){
       
        final Length maxLength = getPropertyLengthAnnotation(propertyName);
               
        return maxLength == null ? -1 : maxLength.max();
       
    }
View Full Code Here

       
    }
   
    protected Length getPropertyLengthAnnotation(final String propertyName){
       
        Length length = getGetterLengthAnnotation(propertyName);
       
        if (length == null){
           
            length = getFieldLengthAnnotation(propertyName);
           
View Full Code Here

  public void testIsValid() {
    AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
    descriptor.setValue( "min", 1 );
    descriptor.setValue( "max", 3 );
    descriptor.setValue( "message", "{validator.length}" );
    Length l = AnnotationFactory.create( descriptor );
    LengthValidator constraint = new LengthValidator();
    constraint.initialize( l );
    assertTrue( constraint.isValid( null, null ) );
    assertFalse( constraint.isValid( "", null ) );
    assertTrue( constraint.isValid( "f", null ) );
View Full Code Here

  @TestForIssue(jiraKey = "HV-502")
  public void testIsValidCharSequence() {
    AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
    descriptor.setValue( "min", 1 );
    descriptor.setValue( "max", 3 );
    Length l = AnnotationFactory.create( descriptor );
    LengthValidator constraint = new LengthValidator();
    constraint.initialize( l );
    assertTrue( constraint.isValid( new MyCustomStringImpl( "foo" ), null ) );
    assertFalse( constraint.isValid( new MyCustomStringImpl( "foobar" ), null ) );
  }
View Full Code Here

  public void testNegativeMinValue() {
    AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
    descriptor.setValue( "min", -1 );
    descriptor.setValue( "max", 1 );
    descriptor.setValue( "message", "{validator.length}" );
    Length p = AnnotationFactory.create( descriptor );

    LengthValidator constraint = new LengthValidator();
    constraint.initialize( p );
  }
View Full Code Here

  public void testNegativeMaxValue() {
    AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
    descriptor.setValue( "min", 1 );
    descriptor.setValue( "max", -1 );
    descriptor.setValue( "message", "{validator.length}" );
    Length p = AnnotationFactory.create( descriptor );

    LengthValidator constraint = new LengthValidator();
    constraint.initialize( p );
  }
View Full Code Here

  public void testNegativeLength() {
    AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
    descriptor.setValue( "min", 5 );
    descriptor.setValue( "max", 4 );
    descriptor.setValue( "message", "{validator.length}" );
    Length p = AnnotationFactory.create( descriptor );

    LengthValidator constraint = new LengthValidator();
    constraint.initialize( p );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.validator.constraints.Length

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.