Package javax.validation.metadata

Examples of javax.validation.metadata.MethodDescriptor


  @Test
  public void testXMLCrossParameterConstraints() {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Garage.class );

    MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod( "buildCar", java.util.List.class );
    CrossParameterDescriptor crossParameterDescriptor = methodDescriptor.getCrossParameterDescriptor();
    Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
    assertCorrectConstraintTypes( constraintDescriptors, ELAssert.class);

    methodDescriptor = beanDescriptor.getConstraintsForMethod( "paintCar", int.class );
    ReturnValueDescriptor returnValueDescriptor = methodDescriptor.getReturnValueDescriptor();
    constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
    assertCorrectConstraintTypes( constraintDescriptors, ELAssert.class);
  }
View Full Code Here


  @Test
  public void testMethodAndConstructorDescriptor() {
    BeanDescriptor carDescriptor = validator.getConstraintsForClass( Car.class );

    //driveAway(int) has a constrained parameter and an unconstrained return value
    MethodDescriptor driveAwayDescriptor = carDescriptor.getConstraintsForMethod(
        "driveAway",
        int.class
    );
    assertEquals( "driveAway", driveAwayDescriptor.getName() );
    assertTrue( driveAwayDescriptor.hasConstrainedParameters() );
    assertFalse( driveAwayDescriptor.hasConstrainedReturnValue() );

    //always returns an empty set; constraints are retrievable by navigating to
    //one of the sub-descriptors, e.g. for the return value
    assertTrue( driveAwayDescriptor.getConstraintDescriptors().isEmpty() );

    ParameterDescriptor speedDescriptor = driveAwayDescriptor.getParameterDescriptors()
        .get( 0 );

    //The "speed" parameter is located at index 0, has one constraint and is not cascaded
    //nor does it define group conversions
    assertEquals( "arg0", speedDescriptor.getName() );
    assertEquals( 0, speedDescriptor.getIndex() );
    assertEquals( 1, speedDescriptor.getConstraintDescriptors().size() );
    assertFalse( speedDescriptor.isCascaded() );
    assert speedDescriptor.getGroupConversions().isEmpty();

    //getDriver() has no constrained parameters but its return value is marked for cascaded
    //validation and declares one group conversion
    MethodDescriptor getDriverDescriptor = carDescriptor.getConstraintsForMethod(
        "getDriver"
    );
    assertFalse( getDriverDescriptor.hasConstrainedParameters() );
    assertTrue( getDriverDescriptor.hasConstrainedReturnValue() );

    ReturnValueDescriptor returnValueDescriptor = getDriverDescriptor.getReturnValueDescriptor();
    assertTrue( returnValueDescriptor.getConstraintDescriptors().isEmpty() );
    assertTrue( returnValueDescriptor.isCascaded() );
    assertEquals( 1, returnValueDescriptor.getGroupConversions().size() );

    //load(List<Person>, List<PieceOfLuggage>) has one cross-parameter constraint
    MethodDescriptor loadDescriptor = carDescriptor.getConstraintsForMethod(
        "load",
        List.class,
        List.class
    );
    assertTrue( loadDescriptor.hasConstrainedParameters() );
    assertFalse( loadDescriptor.hasConstrainedReturnValue() );
    assertEquals(
        1,
        loadDescriptor.getCrossParameterDescriptor().getConstraintDescriptors().size()
    );

    //Car(String, String, Person, String) has one constrained parameter
    ConstructorDescriptor constructorDescriptor = carDescriptor.getConstraintsForConstructor(
        String.class,
View Full Code Here

   * @param parameterIndex The parameter index.
   *
   * @return an instance of {@code ParameterDescriptor}.
   */
  public static ParameterDescriptor getParameterDescriptor(Class<?> clazz, String methodName, Class<?>[] parameterTypes, int parameterIndex) {
    final MethodDescriptor methodDescriptor = getMethodDescriptor(
        clazz,
        methodName,
        parameterTypes
    );
    assertNotNull(
        methodDescriptor,
        "No method with the given signature is declared in " + clazz + " or its super class"
    );
    return methodDescriptor.getParameterDescriptors().get( parameterIndex );
  }
View Full Code Here

        final Class<?> targetClass = Proxies.classFor(context.getTarget().getClass());
        if (!isMethodValidated(targetClass, method)) {
            return context.proceed();
        }

        final MethodDescriptor constraintsForMethod = validator.getConstraintsForClass(targetClass).getConstraintsForMethod(method.getName(), method.getParameterTypes());
        if (constraintsForMethod == null) {
            return context.proceed();
        }

        initExecutableValidator();
View Full Code Here

      logger.debug("method {} has no parameters, skipping", controllerMethod);
      return false;
    }

    BeanDescriptor bean = bvalidator.getConstraintsForClass(controllerMethod.getController().getType());
    MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getName(), method.getParameterTypes());
    return descriptor != null && descriptor.hasConstrainedParameters();
  }
View Full Code Here

TOP

Related Classes of javax.validation.metadata.MethodDescriptor

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.