Examples of MethodValidator


Examples of br.com.caelum.vraptor.validator.beanvalidation.MethodValidator

    assertThat(validator.getErrors(), hasSize(2));
    assertThat(validator.getErrors(), containsInAnyOrder(expected));
  }

  private MethodValidator getMethodValidator() {
    return new MethodValidator(new MockInstanceImpl<Locale>(new Locale("pt", "br")), interpolator, validatorFactory.getValidator());
  }
View Full Code Here

Examples of org.apache.bval.jsr303.extensions.MethodValidator

     */
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Validate validate = invocation.getMethod().getAnnotation(Validate.class);

        Validator validator = this.validatorProvider.get();
        MethodValidator methodValidator = validator.unwrap(MethodValidator.class);

        Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
        Class<?> clazz = invocation.getMethod().getDeclaringClass();
        Method method = invocation.getMethod();
        Object[] arguments = invocation.getArguments();
        Class<?>[] groups = validate.groups();

        constraintViolations.addAll(methodValidator.validateParameters(clazz,
                method,
                arguments,
                groups));

        if (!constraintViolations.isEmpty()) {
            throw getException(new ConstraintViolationException("Validation error when calling method '"
                        + method
                        + "' with arguments "
                        + Arrays.deepToString(arguments), constraintViolations),
                    validate.rethrowExceptionsAs());
        }

        Object returnedValue = invocation.proceed();

        if (validate.validateReturnedValue()) {
            constraintViolations.addAll(methodValidator.validateReturnedValue(clazz, method, returnedValue, groups));
            if (!constraintViolations.isEmpty()) {
                throw getException(new ConstraintViolationException("Method '"
                        + method
                        + "' returned a not valid value "
                        + returnedValue, constraintViolations), validate.rethrowExceptionsAs());
View Full Code Here

Examples of org.apache.bval.jsr303.extensions.MethodValidator

        throws Throwable
    {
        Validate validate = invocation.getMethod().getAnnotation( Validate.class );

        Validator validator = validatorFactory.getValidator();
        MethodValidator methodValidator = validator.unwrap( MethodValidator.class );

        Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
        Class<?> clazz = invocation.getMethod().getDeclaringClass();
        Method method = invocation.getMethod();
        Object[] arguments = invocation.getArguments();
        Class<?>[] groups = validate.groups();

        constraintViolations.addAll( methodValidator.validateParameters( clazz, method, arguments, groups ) );

        if ( !constraintViolations.isEmpty() )
        {
            throw getException( new ConstraintViolationException( format( "Validation error when calling method '%s' with arguments %s",
                                                                          method,
                                                                          deepToString( arguments ) ),
                                                                  constraintViolations ),
                                validate.rethrowExceptionsAs(),
                                validate.exceptionMessage(),
                                arguments );
        }

        Object returnedValue = invocation.proceed();

        if ( validate.validateReturnedValue() )
        {
            constraintViolations.addAll( methodValidator.validateReturnedValue( clazz, method, returnedValue, groups ) );

            if ( !constraintViolations.isEmpty() )
            {
                throw getException( new ConstraintViolationException( format( "Method '%s' returned a not valid value %s",
                                                                              method,
View Full Code Here

Examples of org.apache.bval.jsr303.extensions.MethodValidator

    /**
     * {@inheritDoc}
     */
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Validate validate = invocation.getMethod().getAnnotation(Validate.class);
        MethodValidator methodValidator = this.validator.unwrap(MethodValidator.class);

        Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
        Class<?> clazz = invocation.getMethod().getDeclaringClass();
        Method method = invocation.getMethod();
        Object[] arguments = invocation.getArguments();
        Class<?>[] groups = validate.groups();

        constraintViolations.addAll(methodValidator.validateParameters(clazz,
                method,
                arguments,
                groups));

        if (!constraintViolations.isEmpty()) {
            throw new ConstraintViolationException("Validation error when calling method '"
                    + method
                    + "' with arguments "
                    + Arrays.deepToString(arguments), constraintViolations);
        }

        Object returnedValue = invocation.proceed();

        if (validate.validateReturnedValue()) {
            constraintViolations.addAll(methodValidator.validateReturnedValue(clazz, method, returnedValue, groups));
            if (!constraintViolations.isEmpty()) {
                throw new ConstraintViolationException("Method '"
                        + method
                        + "' returned a not valid value "
                        + returnedValue, constraintViolations);
View Full Code Here

Examples of org.apache.bval.jsr303.extensions.MethodValidator

     */
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Validate validate = invocation.getMethod().getAnnotation(Validate.class);

        Validator validator = this.validatorFactory.getValidator();
        MethodValidator methodValidator = validator.unwrap(MethodValidator.class);

        Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
        Class<?> clazz = invocation.getMethod().getDeclaringClass();
        Method method = invocation.getMethod();
        Object[] arguments = invocation.getArguments();
        Class<?>[] groups = validate.groups();

        constraintViolations.addAll(methodValidator.validateParameters(clazz,
                method,
                arguments,
                groups));

        if (!constraintViolations.isEmpty()) {
            throw getException(new ConstraintViolationException(
                    String.format("Validation error when calling method '%s' with arguments %s",
                            method,
                            Arrays.deepToString(arguments)),
                    constraintViolations),
                    validate.rethrowExceptionsAs(),
                    validate.exceptionMessage(),
                    arguments);
        }

        Object returnedValue = invocation.proceed();

        if (validate.validateReturnedValue()) {
            constraintViolations.addAll(methodValidator.validateReturnedValue(clazz, method, returnedValue, groups));

            if (!constraintViolations.isEmpty()) {
                throw getException(new ConstraintViolationException(
                        String.format("Method '%s' returned a not valid value %s",
                                method,
View Full Code Here

Examples of org.hibernate.validator.MethodValidator

  //Match any public methods in a class annotated with @AutoValidating
  @Around("execution(public * *(..)) && @within(de.gmorling.methodvalidation.spring.AutoValidating)")
  public Object validateMethodInvocation(ProceedingJoinPoint pjp) throws Throwable {
    Object result;
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    MethodValidator methodValidator = validator.unwrap( MethodValidator.class );

    Set<MethodConstraintViolation<Object>> parametersViolations = methodValidator.validateParameters(
        pjp.getTarget(), signature.getMethod(), pjp.getArgs()
    );
    if ( !parametersViolations.isEmpty() ) {
      throw new MethodConstraintViolationException( parametersViolations );
    }

    result =  pjp.proceed(); //Execute the method

    Set<MethodConstraintViolation<Object>> returnValueViolations = methodValidator.validateReturnValue(
        pjp.getTarget(), signature.getMethod(), result
    );
    if ( !returnValueViolations.isEmpty() ) {
      throw new MethodConstraintViolationException( returnValueViolations );
    }
View Full Code Here

Examples of org.hibernate.validator.MethodValidator

  private ValidatorFactory validatorFactory;

  @Override
  public Object invoke(MethodInvocation invocation) throws Throwable {

    MethodValidator validator = validatorFactory.getValidator().unwrap(
      MethodValidator.class);

    Set<MethodConstraintViolation<Object>> violations = validator
      .validateParameters(
        invocation.getThis(), invocation.getMethod(),
        invocation.getArguments());

    if (!violations.isEmpty()) {
      throw new MethodConstraintViolationException(violations);
    }

    Object result = invocation.proceed();

    violations = validator.validateReturnValue(
            invocation.getThis(),
            invocation.getMethod(),
            result);

    if (!violations.isEmpty()) {
View Full Code Here

Examples of org.hibernate.validator.MethodValidator

  private ValidatorFactory validatorFactory;

  @AroundInvoke
  public Object validateMethodInvocation(InvocationContext ctx) throws Exception {

    MethodValidator validator = validatorFactory.getValidator().unwrap(
      MethodValidator.class);

    Set<MethodConstraintViolation<Object>> violations = validator
      .validateParameters(
        ctx.getTarget(), ctx.getMethod(), ctx.getParameters());

    if (!violations.isEmpty()) {
      throw new MethodConstraintViolationException(violations);
    }

    Object result = ctx.proceed();

    violations = validator.validateReturnValue(ctx.getTarget(), ctx.getMethod(), result);

    if (!violations.isEmpty()) {
      throw new MethodConstraintViolationException(violations);
    }
View Full Code Here

Examples of org.hibernate.validator.method.MethodValidator

            }
         }
      }
      Validator validator = validatorFactory.getValidator();
      MethodValidator methodValidator = validator.unwrap(MethodValidator.class);
      return  new GeneralValidatorImpl(validator, methodValidator);
   }
View Full Code Here

Examples of org.junit.internal.runners.MethodValidator

    @Test public void a() {
    }
  }
 
  @Test public void overloaded() {
    MethodValidator validator= new MethodValidator(Confused.class);
    List<Throwable> errors= validator.validateAllMethods();
    assertEquals(1, errors.size());
  }
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.