Examples of ExecutableValidator


Examples of javax.validation.executable.ExecutableValidator

  public void testParameterNameProviderSetUsingContext() throws Exception {
    Object object = new User();
    Method method = User.class.getMethod( "setNames", String.class, String.class );
    Object[] parameters = new Object[] { null, null };

    ExecutableValidator executableValidator = TestUtil.getValidatorFactoryUnderTest()
        .usingContext()
        .parameterNameProvider( new CustomParameterNameProvider() )
        .getValidator()
        .forExecutables();
    Set<ConstraintViolation<Object>> constraintViolations = executableValidator.validateParameters(
        object,
        method,
        parameters
    );
    assertCorrectNumberOfViolations( constraintViolations, 2 );
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

        }
    }
   
    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

Examples of javax.validation.executable.ExecutableValidator

            throw new ConstraintViolationException(violations);
        }               
    }
   
    public< T > void validateReturnValue(final T instance, final Method method, final Object returnValue) {
        final ExecutableValidator methodValidator = getExecutableValidator();
        final Set<ConstraintViolation< T > > violations = methodValidator.validateReturnValue(instance,
            method, returnValue);
       
        if (!violations.isEmpty()) {
            throw new ResponseConstraintViolationException(violations);
        }               
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

   * @throws Exception Any exception caused by the intercepted method invocation. A {@link ConstraintViolationException}
   * in case at least one constraint violation occurred either during parameter or return value validation.
   */
  @AroundInvoke
  public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(
        ctx.getTarget(),
        ctx.getMethod(),
        ctx.getParameters()
    );

    if ( !violations.isEmpty() ) {
      throw new ConstraintViolationException(
          getMessage( ctx.getMethod(), ctx.getParameters(), violations ),
          violations
      );
    }

    Object result = ctx.proceed();

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

View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

   * @throws Exception Any exception caused by the intercepted constructor invocation. A {@link ConstraintViolationException}
   * in case at least one constraint violation occurred either during parameter or return value validation.
   */
  @AroundConstruct
  public void validateConstructorInvocation(InvocationContext ctx) throws Exception {
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> violations = executableValidator.validateConstructorParameters(
        ctx.getConstructor(),
        ctx.getParameters()
    );

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

Examples of javax.validation.executable.ExecutableValidator

  @Test
  public void constructorViolationsWhenNullParameters() throws NoSuchMethodException, SecurityException {
        final MyParameter parameter = new MyParameter();

    ExecutableValidator methodValidator = validator.forExecutables();
    Constructor<MyBean2> constructor = MyBean2.class
        .getConstructor(parameter.getClass());

    Set<ConstraintViolation<MyBean2>> constraints = methodValidator
        .validateConstructorParameters(constructor, new Object[] {parameter});

    ConstraintViolation<MyBean2> violation = constraints.iterator().next();
    assertThat(constraints.size(), equalTo(1));
    assertThat(violation.getMessageTemplate(), equalTo("{javax.validation.constraints.NotNull.message}"));
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

  @Test
  public void constructorViolationsWhenNotNullParameters() throws NoSuchMethodException, SecurityException {
    final MyParameter parameter = new MyParameter();
        parameter.setValue("foo");

        ExecutableValidator methodValidator = validator.forExecutables();
    Constructor<MyBean2> constructor = MyBean2.class
        .getConstructor(parameter.getClass());

    Set<ConstraintViolation<MyBean2>> constraints = methodValidator
        .validateConstructorParameters(constructor, new Object[] {parameter});

    assertThat(constraints.isEmpty(), equalTo(true));
  }
View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

   * @throws Exception Any exception caused by the intercepted method invocation. A {@link ConstraintViolationException}
   * in case at least one constraint violation occurred either during parameter or return value validation.
   */
  @AroundInvoke
  public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(
        ctx.getTarget(),
        ctx.getMethod(),
        ctx.getParameters()
    );

View Full Code Here

Examples of javax.validation.executable.ExecutableValidator

   * in case at least one constraint violation occurred either during parameter or return value validation.
   */
  @AroundConstruct
  @SuppressWarnings("unchecked")
  public void validateConstructorInvocation(InvocationContext ctx) throws Exception {
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> violations = executableValidator.validateConstructorParameters(
        ctx.getConstructor(),
        ctx.getParameters()
    );

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

Examples of javax.validation.executable.ExecutableValidator

   * @throws Exception Any exception caused by the intercepted method invocation. A {@link ConstraintViolationException}
   * in case at least one constraint violation occurred either during parameter or return value validation.
   */
  @AroundInvoke
  public Object validateMethodInvocation(InvocationContext ctx) throws Exception {
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(
        ctx.getTarget(),
        ctx.getMethod(),
        ctx.getParameters()
    );

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.