Examples of validateParameters()


Examples of javax.validation.executable.ExecutableValidator.validateParameters()

        .parameterNameProvider( new CustomParameterNameProvider() )
        .buildValidatorFactory()
        .getValidator()
        .forExecutables();

    Set<ConstraintViolation<User>> constraintViolations = executableValidator.validateParameters(
        new User(),
        User.class.getMethod( "setAddresses", Map.class ),
        new Object[] { }
    );
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CreditCard04 creditCard = new CreditCard04("12341234", "10/10", 1234, "VISA");
    CardValidator04 cardValidator = new CardValidator04();

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CardValidator04.class.getMethod("validate", CreditCard04.class);
    Set<ConstraintViolation<CardValidator04>> violations = methodValidator.validateParameters(cardValidator, method, new Object[]{creditCard});
    assertEquals(0, violations.size());

    violations = methodValidator.validateReturnValue(cardValidator, method, Boolean.TRUE);
    assertEquals(0, violations.size());
  }
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CardValidator04 cardValidator = new CardValidator04();

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CardValidator04.class.getMethod("validate", CreditCard04.class);
    Set<ConstraintViolation<CardValidator04>> violations = methodValidator.validateParameters(cardValidator, method, new Object[]{null});
    displayContraintViolations(violations);
    assertEquals(1, violations.size());
  }

  @Test
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CreditCard04 creditCard = new CreditCard04(null, null, null, null);
    CardValidator04 cardValidator = new CardValidator04();

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CardValidator04.class.getMethod("validate", CreditCard04.class);
    Set<ConstraintViolation<CardValidator04>> violations = methodValidator.validateParameters(cardValidator, method, new Object[]{creditCard});
    displayContraintViolations(violations);
    assertEquals(3, violations.size());
  }

  private void displayContraintViolations(Set<ConstraintViolation<CardValidator04>> constraintViolations) {
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CD21 cd = new CD21("Kind of Blue", 12.5f);

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CD21.class.getMethod("calculatePrice", Float.class);
    Set<ConstraintViolation<CD21>> violations = methodValidator.validateParameters(cd, method, new Object[]{new Float(2.2)});
    assertEquals(0, violations.size());
  }

  @Test //@Ignore("Make sure your local is EN, if not use the following JVM parameters : -Duser.language=en -Duser.country=EN")
  public void shouldRaiseMethodParameterConstraintViolationCauseRateIsLow() throws NoSuchMethodException {
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CD21 cd = new CD21("Kind of Blue", 12.5f);

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CD21.class.getMethod("calculatePrice", Float.class);
    Set<ConstraintViolation<CD21>> violations = methodValidator.validateParameters(cd, method, new Object[]{new Float(1.2)});
    displayContraintViolations(violations);
    assertEquals(1, violations.size());
    assertEquals("must be greater than or equal to 1.4", violations.iterator().next().getMessage());
    assertEquals(new Float(1.2), violations.iterator().next().getInvalidValue());
    assertEquals("{javax.validation.constraints.DecimalMin.message}", violations.iterator().next().getMessageTemplate());
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    CD10 cd = new CD10("title", 12.80f, "Beatles master piece", "Apple", 1, 53.32f, "Pop");

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = CD10.class.getMethod("calculatePrice", Float.class);
    Set<ConstraintViolation<CD10>> violations = methodValidator.validateParameters(cd, method, new Object[]{new Float(4.5)});
  }

  private void displayContraintViolations(Set<ConstraintViolation<CD10>> constraintViolations) {
    for (ConstraintViolation constraintViolation : constraintViolations) {
      System.out.println("### " + constraintViolation.getRootBeanClass().getSimpleName() +
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    Item10 item = new Item10("H2G2", 12.5f, "Best IT Scifi Book");

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = Item10.class.getMethod("calculatePrice", Float.class);
    Set<ConstraintViolation<Item10>> violations = methodValidator.validateParameters(item, method, new Object[]{new Float(4.5)});
    assertEquals(0, violations.size());
  }

  @Test
  public void shouldRaiseConstraintViolationOnCalculatePriceCauseRateIsTooLow() throws NoSuchMethodException {
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    Item10 item = new Item10("H2G2", 12.5f, "Best IT Scifi Book");

    ExecutableValidator methodValidator = validator.forExecutables();
    Method method = Item10.class.getMethod("calculatePrice", Float.class);
    Set<ConstraintViolation<Item10>> violations = methodValidator.validateParameters(item, method, new Object[]{new Float(0.5)});
    displayContraintViolations(violations);
    assertEquals(1, violations.size());
  }

  private void displayContraintViolations(Set<ConstraintViolation<Item10>> constraintViolations) {
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator.validateParameters()

    }
   
    public< T > void validateParameters(final T instance, final Method method, final Object[] arguments) {
       
        final ExecutableValidator methodValidator = getExecutableValidator();
        final Set< ConstraintViolation< T > > violations = methodValidator.validateParameters(instance,
            method, arguments);
       
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }               
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.