Package org.hibernate.validator.cfg

Examples of org.hibernate.validator.cfg.ConstraintMapping


    assertCorrectPropertyPaths( violations, "GreetingService.arg0", "GreetingService.arg1" );
  }

  @Test
  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 );
View Full Code Here


    assertCorrectPropertyPaths( violations, "GreetingService.arg0", "GreetingService.arg0" );
  }

  @Test
  public void testReturnValueConstraint() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class )
        .returnValue()
        .constraint(
            new GenericConstraintDef<ValidGreetingService>( ValidGreetingService.class ).message(
                "invalid"
View Full Code Here

    assertCorrectPropertyPaths( violations, "GreetingService.<return value>" );
  }

  @Test
  public void testMultipleReturnValueConstraints() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class )
        .returnValue()
        .constraint(
            new GenericConstraintDef<ValidGreetingService>( ValidGreetingService.class ).message(
                "invalid 1"
View Full Code Here

    assertCorrectPropertyPaths( violations, "GreetingService.<return value>", "GreetingService.<return value>" );
  }

  @Test
  public void testProgrammaticAndAnnotationReturnValueConstraintsAddUp() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( CharSequence.class )
        .returnValue()
        .constraint(
            new GenericConstraintDef<ValidGreetingService>( ValidGreetingService.class ).message(
                "invalid 2"
View Full Code Here

    assertCorrectPropertyPaths( violations, "GreetingService.<return value>", "GreetingService.<return value>" );
  }

  @Test
  public void shouldDetermineConstraintTargetForReturnValueConstraint() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class, String.class )
        .returnValue()
        .constraint(
            new GenericConstraintDef<GenericAndCrossParameterConstraint>(
                GenericAndCrossParameterConstraint.class
View Full Code Here

    assertCorrectPropertyPaths( violations, "GreetingService.<return value>" );
  }

  @Test
  public void crossParameterConstraint() throws Exception {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( GreetingService.class )
        .constructor( String.class, String.class )
        .crossParameter()
        .constraint(
            new GenericConstraintDef<GenericAndCrossParameterConstraint>(
                GenericAndCrossParameterConstraint.class
View Full Code Here

    Set<ConstraintViolation<EmailContainer>> violations = validator.validate( container );
    assertOrgAddressesAreNotValid( violations );

    // now the same test with programmatic configuration
    final HibernateValidatorConfiguration config = getConfiguration( HibernateValidator.class );
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( EmailContainer.class )
        .property( "email", METHOD )
        .constraint(
            new EmailDef().regexp( noOrgEmailAddressRegexp )
                .message( "ORG addresses are not valid" )
        );
View Full Code Here

  @TestForIssue(jiraKey = "HV-480")
  public void testConstraintsFromXmlAndProgrammaticApiAddUp() {
    final HibernateValidatorConfiguration configuration = ValidatorUtil.getConfiguration( HibernateValidator.class );

    //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" );
View Full Code Here

    config = getConfiguration( HibernateValidator.class );
  }

  @Test
  public void testIgnoreAllAnnotationsOnType() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( Foo.class ).ignoreAllAnnotations();
    config.addMapping( mapping );

    Validator validator = config.buildValidatorFactory().getValidator();
    assertFalse( validator.getConstraintsForClass( Foo.class ).isBeanConstrained() );
  }
View Full Code Here

    assertFalse( validator.getConstraintsForClass( Foo.class ).isBeanConstrained() );
  }

  @Test
  public void testIgnoreClassConstraints() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type( Fu.class ).ignoreAnnotations();
    config.addMapping( mapping );

    Validator validator = config.buildValidatorFactory().getValidator();
    assertFalse( validator.getConstraintsForClass( Fu.class ).isBeanConstrained() );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.validator.cfg.ConstraintMapping

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.