Package javax.validation

Examples of javax.validation.ValidatorFactory.usingContext()


            }
        });
        try {
            Thread.currentThread().setContextClassLoader(Validation.class.getClassLoader());
            ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
            ValidatorContext validatorContext = validatorFactory.usingContext();
            validatorContext.messageInterpolator(new MessageInterpolatorImpl());
            beanValidator = validatorContext.getValidator();
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }
View Full Code Here


            }
        });
        try {
            Thread.currentThread().setContextClassLoader(null);
            ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
            ValidatorContext validatorContext = validatorFactory.usingContext();
            validatorContext.messageInterpolator(new MessageInterpolatorImpl());
            beanValidator = validatorContext.getValidator();
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }
View Full Code Here

                for (Entry<String, ValidatorFactory> validatorFactory : validatorFactories.entrySet()) {
                    String id = validatorFactory.getKey();
                    ValidatorFactory factory = validatorFactory.getValue();
                    try {
                        containerSystemContext.bind(VALIDATOR_FACTORY_NAMING_CONTEXT + id, factory);
                        containerSystemContext.bind(VALIDATOR_NAMING_CONTEXT + id, factory.usingContext().getValidator());
                    } catch (NameAlreadyBoundException e) {
                        throw new OpenEJBException("ValidatorFactory already exists for module " + id, e);
                    } catch (Exception e) {
                        throw new OpenEJBException(e);
                    }
View Full Code Here

  @Test
  @SpecAssertion(section = "4.3.2", id = "b")
  public void testCustomMessageInterpolatorViaConfiguration() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.usingContext()
        .messageInterpolator( new DummyMessageInterpolator() )
        .getValidator();

    assertCustomMessageInterpolatorUsed( validator );
  }
View Full Code Here

      @SpecAssertion(section = "4.3.2", id = "b")
  })
  public void testCustomMessageInterpolatorViaValidatorContext() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    DummyMessageInterpolator dummyMessageInterpolator = new DummyMessageInterpolator();
    Validator validator = factory.usingContext().messageInterpolator( dummyMessageInterpolator ).getValidator();
    assertCustomMessageInterpolatorUsed( validator );
    assertFalse(
        factory.getMessageInterpolator().equals( dummyMessageInterpolator ),
        "getMessageInterpolator() should return the default message interpolator."
    );
View Full Code Here

  @Test
  @SpecAssertion(section = "3.5.2", id = "b")
  public void testCustomTraversableResolverViaValidatorContext() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    DummyTraversableResolver DummyTraversableResolver = new DummyTraversableResolver();
    Validator validator = factory.usingContext().traversableResolver( DummyTraversableResolver ).getValidator();

    assertCustomTrversableResolverUsed( validator );
  }

  private void assertCustomTrversableResolverUsed(Validator validator) {
View Full Code Here

  @Test
  @TestForIssue(jiraKey = "HV-659")
  public void testParameterNameProviderConfiguredViaContext() throws Exception {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory
        .usingContext()
        .parameterNameProvider( new DummyParameterNameProvider() )
        .getValidator();
    ExecutableValidator executableValidator = validator.forExecutables();
    Method addOrderMethod = Customer.class.getMethod( "addOrder", Order.class );
View Full Code Here

    }
    catch ( IllegalStateException e ) {
      fail( "Traversable Called several times for a given object" );
    }

    v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
    try {
      v.validateProperty( suit, "size", Default.class, Cloth.class );
    }
    catch ( IllegalStateException e ) {
      fail( "Traversable Called several times for a given object" );
View Full Code Here

    }
    catch ( IllegalStateException e ) {
      fail( "Traversable Called several times for a given object" );
    }

    v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
    try {
      v.validateValue( Suit.class, "size", 2, Default.class, Cloth.class );
    }
    catch ( IllegalStateException e ) {
      fail( "Traversable Called several times for a given object" );
View Full Code Here

    Set<ConstraintViolation<Person>> violations = validator.validate( john );
    assertNumberOfViolations( violations, 0 );
    constraintValidatorFactory1.assertSize( 3 );

    // getting a new validator with a new constraint factory
    validator = factory.usingContext().constraintValidatorFactory( constraintValidatorFactory2 ).getValidator();
    constraintValidatorFactory2.assertSize( 0 );
    violations = validator.validate( john );
    assertNumberOfViolations( violations, 0 );
    constraintValidatorFactory2.assertSize( 3 );
    constraintValidatorFactory1.assertConstraintValidatorInstancesAreNotShared( constraintValidatorFactory2 );
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.