Package javax.validation.metadata

Examples of javax.validation.metadata.MethodDescriptor


        this.methodValidator = methodValidator;
    }

    public boolean accepts(ResourceMethod method) {
        BeanDescriptor bean = methodValidator.getConstraintsForClass(method.getResource().getType());
        MethodDescriptor descriptor = bean.getConstraintsForMethod(method.getMethod().getName(), method.getMethod().getParameterTypes());
        return descriptor != null && descriptor.hasConstrainedParameters();
    }
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

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

      @SpecAssertion(section = "8.1.1.5", id = "a"),
      @SpecAssertion(section = "8.1.1.5", id = "c"),
      @SpecAssertion(section = "8.1.1.5", id = "f")
  })
  public void testXmlMethodConfigurationApplied() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor( CustomerRepository.class, "listCustomers" );
    assertNotNull( descriptor, "the specified method should be configured in xml" );
    assertTrue( descriptor.hasConstrainedReturnValue() );
    assertFalse( descriptor.hasConstrainedParameters() );

    descriptor = TestUtil.getMethodDescriptor( CustomerRepository.class, "findCustomer", String.class );
    assertNotNull( descriptor, "the specified method should be configured in xml" );
    assertTrue( descriptor.hasConstrainedReturnValue() );
    assertTrue( descriptor.hasConstrainedParameters() );

    descriptor = TestUtil.getMethodDescriptor( CustomerRepository.class, "isCustomer", String.class );
    assertNotNull( descriptor, "the specified method should be configured in xml" );
    assertFalse( descriptor.hasConstrainedReturnValue() );
    assertTrue( descriptor.hasConstrainedParameters() );
  }
View Full Code Here

      @SpecAssertion(section = "8.1.1.5", id = "a"),
      @SpecAssertion(section = "8.1.1.5", id = "b"),
      @SpecAssertion(section = "8.1.1.5", id = "c")
  })
  public void testVarargsMethodParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        CustomerRepository.class,
        "addCustomers",
        Customer[].class
    );
    assertNotNull( descriptor, "the specified method should be configured in xml" );
    assertTrue( descriptor.hasConstrainedParameters() );
  }
View Full Code Here

      @SpecAssertion(section = "8.1.1.5", id = "c"),
      @SpecAssertion(section = "8.1.1.5", id = "g"),
      @SpecAssertion(section = "8.1.1.5", id = "k")
  })
  public void testMethodCrossParameterConstraint() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        CustomerRepository.class,
        "notifyCustomer",
        Customer.class,
        String.class
    );
    assertNotNull( descriptor, "the specified method should be configured in xml" );
    CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor();
    assertTrue( crossParameterDescriptor.hasConstraints() );

    Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
    assertTrue( constraintDescriptors.size() == 1 );
View Full Code Here

  @SpecAssertions({
      @SpecAssertion(section = "6.11", id = "a"),
      @SpecAssertion(section = "8.1.1.5", id = "h")
  })
  public void testConstraintOnMethodReturnValueAndParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        CustomerRepository.class,
        "notifyCustomer",
        Customer.class,
        String.class
    );
    assertNotNull( descriptor, "the specified method should be configured in xml" );

    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
    assertTrue( constraintDescriptors.size() == 1 );

    ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(
        constraintDescriptor.getAnnotation().annotationType(),
        NotNull.class,
        "Unexpected constraint type"
    );

    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue( parameterDescriptors.size() == 2 );

    ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 );
    constraintDescriptors = parameterDescriptor.getConstraintDescriptors();
    assertTrue( constraintDescriptors.size() == 1 );
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "8.1.1.5", id = "i")
  public void testCascadingOnReturnValueAndParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        CustomerRepository.class,
        "findByExample",
        Customer.class
    );
    assertNotNull( descriptor, "the specified method should be configured in xml" );

    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertTrue( returnValueDescriptor.isCascaded(), "<valid/> is used to configure cascading" );

    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue( parameterDescriptors.size() == 1 );

    ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 );
    assertTrue( parameterDescriptor.isCascaded(), "<valid/> is used to configure cascading" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "8.1.1.5", id = "j")
  public void testGroupConversionOnReturnValueAndParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        CustomerRepository.class,
        "findByExample",
        Customer.class
    );
    assertNotNull( descriptor, "the specified method should be configured in xml" );

    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    Set<GroupConversionDescriptor> groupConversionDescriptors = returnValueDescriptor.getGroupConversions();
    assertTrue( groupConversionDescriptors.size() == 1 );

    GroupConversionDescriptor groupConversionDescriptor = groupConversionDescriptors.iterator().next();
    assertEquals( groupConversionDescriptor.getFrom(), Default.class, "Wrong from class for group conversion" );

    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue( parameterDescriptors.size() == 1 );

    ParameterDescriptor parameterDescriptor = parameterDescriptors.get( 0 );
    groupConversionDescriptors = parameterDescriptor.getGroupConversions();
    assertTrue( groupConversionDescriptors.size() == 1 );
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "8.1.1.5", id = "l")
  public void testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter() {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(
        IgnoreAnnotations.class,
        "foobar",
        String.class,
        String.class
    );
    CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor();
    assertFalse( crossParameterDescriptor.hasConstraints(), "Cross parameter constraints should be ignored." );

    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertFalse( returnValueDescriptor.hasConstraints(), "Return value constraints should be ignored." );

    ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get( 0 );
    assertFalse( parameterDescriptor.hasConstraints(), "First parameter constraints should be ignored." );

    parameterDescriptor = descriptor.getParameterDescriptors().get( 1 );
    assertTrue( parameterDescriptor.hasConstraints(), "Second parameter constraints should be applied." );
  }
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.