Package org.hibernate.validator.cfg.defs

Examples of org.hibernate.validator.cfg.defs.SizeDef


  public void testMultipleParameterConstraintsAtSameParameter() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class )
        .parameter( 0 )
        .constraint( new SizeDef().min( 1 ).max( 10 ) )
        .constraint( new SizeDef().min( 2 ).max( 10 ) );
    config.addMapping( mapping );

    Constructor<GreetingService> constructor = GreetingService.class.getConstructor( String.class );
    Object[] parameterValues = new Object[] { "" };
View Full Code Here


  public void testMultipleParameterConstraintsAtDifferentParameters() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class, String.class )
        .parameter( 0 )
        .constraint( new SizeDef().min( 1 ).max( 10 ) )
        .parameter( 1 )
        .constraint( new SizeDef().min( 1 ).max( 10 ) );
    config.addMapping( mapping );

    Constructor<GreetingService> constructor = GreetingService.class.getConstructor( String.class, String.class );
    Object[] parameterValues = new Object[] { "", "" };
View Full Code Here

  public void testProgrammaticAndAnnotationParameterConstraintsAddUp() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( CharSequence.class )
        .parameter( 0 )
        .constraint( new SizeDef().min( 2 ).max( 10 ) );
    config.addMapping( mapping );

    Constructor<GreetingService> constructor = GreetingService.class.getConstructor( CharSequence.class );
    Object[] parameterValues = new Object[] { "" };
View Full Code Here

    //given
    final ConstraintMapping programmaticMapping = configuration.createConstraintMapping();
    programmaticMapping.type( Customer.class )
        .property( "firstName", ElementType.FIELD )
        .constraint( new SizeDef().min( 2 ).max( 10 ) );

    final InputStream xmlMapping = XmlMappingTest.class.getResourceAsStream( "hv-480-mapping.xml" );

    configuration.addMapping( programmaticMapping );
    configuration.addMapping( xmlMapping );
View Full Code Here

  @Test
  public void testThatSpecificParameterCanBeSetAfterInvokingMethodFromBaseType() {
    mapping.type( Marathon.class )
        .property( "name", METHOD )
        .constraint(
            new SizeDef().message( "too short" ).min( 3 )
        );
    config.addMapping( mapping );
    Validator validator = config.buildValidatorFactory().getValidator();

    Marathon marathon = new Marathon();
View Full Code Here

    mapping.type( Marathon.class )
        .constraint(
            new GenericConstraintDef<MarathonConstraint>( MarathonConstraint.class ).param( "minRunner", 1 )
        )
        .property( "name", METHOD )
        .constraint( new SizeDef().message( "name too short" ).min( 3 ) );
    config.addMapping( mapping );
    Validator validator = config.buildValidatorFactory().getValidator();

    Marathon marathon = new Marathon();
    marathon.setName( "NY" );
View Full Code Here

  @Test
  public void testMultipleConstraintOfTheSameType() {
    mapping.type( Marathon.class )
        .property( "name", METHOD )
        .constraint( new SizeDef().min( 5 ) )
        .constraint( new SizeDef().min( 10 ) );
    config.addMapping( mapping );
    Validator validator = config.buildValidatorFactory().getValidator();

    Marathon marathon = new Marathon();
    marathon.setName( "Foo" );
View Full Code Here

  @Test
  public void testProgrammaticAndAnnotationFieldConstraintsAddUp() {
    mapping.type( User.class )
        .property( "firstName", ElementType.FIELD )
        .constraint( new SizeDef().min( 2 ).max( 10 ) );
    config.addMapping( mapping );
    Validator validator = config.buildValidatorFactory().getValidator();
    Set<ConstraintViolation<User>> violations = validator.validateProperty( new User( "", "" ), "firstName" );

    assertCorrectConstraintViolationMessages(
View Full Code Here

  @Test
  public void testProgrammaticAndAnnotationPropertyConstraintsAddUp() {
    mapping.type( User.class )
        .property( "lastName", ElementType.METHOD )
        .constraint( new SizeDef().min( 4 ).max( 10 ) );
    config.addMapping( mapping );
    Validator validator = config.buildValidatorFactory().getValidator();
    Set<ConstraintViolation<User>> violations = validator.validateProperty( new User( "", "" ), "lastName" );

    assertCorrectConstraintViolationMessages(
View Full Code Here

  public void testMultipleParameterConstraintsAtDifferentParameters() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .method( "greet", String.class, String.class )
        .parameter( 0 )
        .constraint( new SizeDef().min( 1 ).max( 10 ) )
        .parameter( 1 )
        .constraint( new SizeDef().min( 1 ).max( 10 ) );
    config.addMapping( mapping );

    try {
      GreetingService service = getValidatingProxy(
          wrappedObject,
View Full Code Here

TOP

Related Classes of org.hibernate.validator.cfg.defs.SizeDef

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.