Package javax.validation

Examples of javax.validation.ConstraintViolationException


        try {
            gamesManager.addSportMan("ILoseTwo", "TOO-LONG");
            fail("country should be between 2 and 4 characters");
        } catch (EJBException wrappingException) {
            assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
            ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
            assertEquals(1, exception.getConstraintViolations().size());
        }
    }
View Full Code Here


        try {
            poleVaultingManager.points(119);
            fail("the jump is too short");
        } catch (EJBException wrappingException) {
            assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
            ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
            assertEquals(1, exception.getConstraintViolations().size());
        }
    }
View Full Code Here

    Set<ConstraintViolation<Person>> violations = validator.validate(person,
        Default.class, ServerGroup.class);
    if (!violations.isEmpty()) {
      Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(
          violations);
      throw new ConstraintViolationException(temp);
    }

    String serverInfo = getServletContext().getServerInfo();
    String userAgent = getThreadLocalRequest().getHeader("User-Agent");
View Full Code Here

        Set<ConstraintViolation<T>> violations = AccessController.doPrivileged(
                J2DoPrivHelper.validateAction(_validator, arg0, getValidationGroup(event)));

        if (violations != null && violations.size() > 0) {
            return new ValidationException(
                new ConstraintViolationException(
                    // A validation constraint failure occurred for class "{0}".
                    _loc.get("validate-failed",
                        arg0.getClass().getName()).getMessage(),
                    (Set)violations),
                true);
View Full Code Here

        Set<ConstraintViolation<T>> violations =
            _validator.validateProperty(arg0, property,
                getValidationGroup(event));
        if (violations != null && violations.size() > 0) {
            return new ValidationException(
                new ConstraintViolationException(
                    // A validation constraint failure occurred for
                    // property "{1}" in class "{0}".
                    _loc.get("valdiate-property-failed",
                        arg0.getClass().getName(),property).getMessage(),
                    (Set)violations),
View Full Code Here

        Set<ConstraintViolation<T>> violations =
            _validator.validateValue(arg0, arg1, arg2,
                getValidationGroup(event));
        if (violations != null && violations.size() > 0) {
            return new ValidationException(
                new ConstraintViolationException(
                    // A validation constraint failure occurred for
                    // value "{2}" of property "{1}" in class "{0}".
                    _loc.get("validate-value-failed", arg0.getClass().getName(),
                        arg1, arg2.toString()).getMessage(),                   
                    (Set)violations),
View Full Code Here

  private void validateParameters(final Object obj, final Method method, final Object[] args, final Class<?>[] groups) {
    final Set<ConstraintViolation<Object>> violations = methodValidator.validateParameters(obj, method, args, groups);
    if (!violations.isEmpty()) {
      final String message = "Invalid arguments calling '" + method + "' with " + Arrays.deepToString(args);
      throw new ConstraintViolationException(message, violations);
    }
  }
View Full Code Here

  private void validateReturnValue(final Object obj, final Method method, final Object value, final Class<?>[] groups) {
    final Set<ConstraintViolation<Object>> violations = methodValidator.validateReturnValue(obj, method, value, groups);
    if (!violations.isEmpty()) {
      final String message = "Invalid value returned by '" + method + "' was " + value;
      throw new ConstraintViolationException(message, violations);
    }
  }
View Full Code Here

          }
          return asResponse(invalid(cause));
        }

        if (e instanceof ConstraintViolationException) {
          ConstraintViolationException cause = (ConstraintViolationException) e;
          Set<ConstraintViolation<?>> violations = cause.getConstraintViolations();
          if (violations == null || violations.size() == 0) {
            return asResponse(error(e));
          }
          return asResponse(invalid(cause));
        }
View Full Code Here

  public static void validateWithException(Validator validator,
      Object object, Class<?>... groups)
      throws ConstraintViolationException {
    Set constraintViolations = validator.validate(object, groups);
    if (!constraintViolations.isEmpty()) {
      throw new ConstraintViolationException(constraintViolations);
    }
  }
View Full Code Here

TOP

Related Classes of javax.validation.ConstraintViolationException

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.