コード例 #1
0
  private <T> Set<AnnotatedCallable<? super T>> determineConstrainedCallables(
      AnnotatedType<T> type) {
    Set<AnnotatedCallable<? super T>> callables = newHashSet();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(type.getJavaClass());

    determineConstrainedConstructors(type, beanDescriptor, callables);
    determineConstrainedMethods(type, beanDescriptor, callables);

    return callables;
  }
コード例 #2
0
 @Test
 @SpecAssertions({@SpecAssertion(section = "7.1.1.3", id = "f")})
 public void testWrongPropertyNameThrowsException() {
   try {
     Validator validator = TestUtil.getValidatorUnderTest();
     validator.getConstraintsForClass(User.class);
   } catch (ValidationException e) {
     // success
   }
 }
コード例 #3
0
  @Test
  @SpecAssertion(section = "8.2", id = "a")
  public void testValidBeanValidation11Mapping() {
    Validator validator =
        TestUtil.getConfigurationUnderTest()
            .addMapping(Version11InMappingXmlTest.class.getResourceAsStream(MAPPING_FILE))
            .buildValidatorFactory()
            .getValidator();

    assertFalse(validator.getConstraintsForClass(TestEntity.class).isBeanConstrained());
  }
  @Test
  @TestForIssue(jiraKey = "HV-333")
  public void
      testContextWithRightDescriptorAndValueAndRootBeanClassIsPassedToMessageInterpolator() {

    // use a easy mock message interpolator for verifying that the right MessageInterpolatorContext
    // will be passed
    MessageInterpolator mock = createMock(MessageInterpolator.class);
    Configuration<?> config = ValidatorUtil.getConfiguration().messageInterpolator(mock);

    Validator validator = config.buildValidatorFactory().getValidator();

    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(TestBean.class);
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty("test");
    Set<ConstraintDescriptor<?>> constraintDescriptors =
        propertyDescriptor.getConstraintDescriptors();
    assertTrue(constraintDescriptors.size() == 1);

    // prepare the mock interpolator to expect the right interpolate call
    String validatedValue = "value";
    expect(
            mock.interpolate(
                MESSAGE,
                new MessageInterpolatorContext(
                    constraintDescriptors.iterator().next(),
                    validatedValue,
                    TestBean.class,
                    Collections.<String, Object>emptyMap())))
        .andReturn("invalid");
    replay(mock);

    Set<ConstraintViolation<TestBean>> violations =
        validator.validate(new TestBean(validatedValue));
    assertNumberOfViolations(violations, 1);

    // verify that the right context was passed
    verify(mock);
  }
コード例 #5
0
 @Override
 public BeanDescriptor getConstraintsForClass(final Class<?> clazz) {
   return delegate.getConstraintsForClass(clazz);
 }
コード例 #6
0
 @Override
 public BeanDescriptor getConstraintsForClass(Class<?> clazz) {
   return validator.getConstraintsForClass(clazz);
 }