Package javax.validation

Examples of javax.validation.Configuration


   /**
    * Constructor
    */
   public BeanValidation()
   {
      Configuration configuration = Validation.byDefaultProvider().configure();
      Configuration<?> conf = configuration.traversableResolver(new JCATraversableResolver());

      validatorFactory = conf.buildValidatorFactory();
      validator = validatorFactory.getValidator();
   }


public class CustomMessageInterpolatorTest extends AbstractTest {

  @Test
  @SpecAssertion(section = "4.3.2", id = "b")
  public void testCustomMessageInterpolatorViaConfiguration() {
    Configuration config = Validation.byDefaultProvider().configure();
    config = config.messageInterpolator( new DummyMessageInterpolator() );
    Validator validator = config.buildValidatorFactory().getValidator();

    assertCustomMessageInterpolatorUsed( validator );
  }

public class CustomMessageInterpolatorTest extends AbstractTest {

  @Test
  @SpecAssertion(section = "4.3.2", id = "b")
  public void testCustomMessageInterpolatorViaConfiguration() {
    Configuration config = Validation.byDefaultProvider().configure();
    config = config.messageInterpolator( new DummyMessageInterpolator() );
    Validator validator = config.buildValidatorFactory().getValidator();

    assertCustomMessageInterpolatorUsed( validator );
  }

  }


  @SuppressWarnings("unchecked")
  public void afterPropertiesSet() {
    Configuration configuration = (this.providerClass != null ?
        Validation.byProvider(this.providerClass).configure() :
        Validation.byDefaultProvider().configure());

    MessageInterpolator targetInterpolator = this.messageInterpolator;
    if (targetInterpolator == null) {
      targetInterpolator = configuration.getDefaultMessageInterpolator();
    }
    configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));

    if (this.traversableResolver != null) {
      configuration.traversableResolver(this.traversableResolver);
    }

    ConstraintValidatorFactory targetConstraintValidatorFactory = this.constraintValidatorFactory;
    if (targetConstraintValidatorFactory == null && this.applicationContext != null) {
      targetConstraintValidatorFactory =
          new SpringConstraintValidatorFactory(this.applicationContext.getAutowireCapableBeanFactory());
    }
    if (targetConstraintValidatorFactory != null) {
      configuration.constraintValidatorFactory(targetConstraintValidatorFactory);
    }

    if (this.mappingLocations != null) {
      for (Resource location : this.mappingLocations) {
        try {
          configuration.addMapping(location.getInputStream());
        }
        catch (IOException ex) {
          throw new IllegalStateException("Cannot read mapping resource: " + location);
        }
      }
    }

    for (Map.Entry<String, String> entry : this.validationPropertyMap.entrySet()) {
      configuration.addProperty(entry.getKey(), entry.getValue());
    }

    this.validatorFactory = configuration.buildValidatorFactory();
    setTargetValidator(this.validatorFactory.getValidator());
  }

public class CustomMessageInterpolatorTest extends AbstractTest {

  @Test
  @SpecAssertion(section = "4.3.2", id = "b")
  public void testCustomMessageInterpolatorViaConfiguration() {
    Configuration config = Validation.byDefaultProvider().configure();
    config = config.messageInterpolator( new DummyMessageInterpolator() );
    Validator validator = config.buildValidatorFactory().getValidator();

    assertCustomMessageInterpolatorUsed( validator );
  }

  }

  @Test
  @TestForIssue(jiraKey = "HV-920")
  public void url_validator_using_regexp_only_can_be_configured_via_xml() {
    Configuration config = ValidatorUtil.getConfiguration();

    InputStream mappingStream = URLValidatorTest.class.getResourceAsStream( "mapping.xml" );
    config.addMapping( mappingStream );

    DelegatingConstraintValidatorFactory constraintValidatorFactory = new DelegatingConstraintValidatorFactory(
        config.getDefaultConstraintValidatorFactory()
    );
    config.constraintValidatorFactory( constraintValidatorFactory );

    assertDefaultURLConstraintValidatorOverridden( config, constraintValidatorFactory );
  }

TOP

Related Classes of javax.validation.Configuration

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.